Complete guide to using Price Fetcher via CLI and Python API.
Get Bitcoin price.
$ python -m src bitcoin
============================================================
Bitcoin Price
============================================================
Bitcoin $ 67,890.50 USD (+2.45%)
Source: coingecko
Time: 2026-06-10T15:32:44.123456Get Gold price per troy ounce.
$ python -m src gold
============================================================
Gold Price
============================================================
Gold (per oz) $ 2,087.75 USD (+0.35%)
Source: london_metal_exchange
Time: 2026-06-10T15:32:44.123456Get USD exchange rate for specific currency.
$ python -m src rate EUR
============================================================
Exchange Rate: USD -> EUR
============================================================
1 USD = 0.9200 EUR
Source: open_exchange_rates
Time: 2026-06-10T15:32:44.123456Supported currencies:
EUR GBP JPY AUD CAD CHF CNY INR MXN ARS BRL CLP
Get Bitcoin, Gold, and exchange rates in one command.
# Default (EUR, MXN, ARS)
$ python -m src all
# Custom currencies
$ python -m src all EUR,GBP,JPY
# Single currency
$ python -m src all MXNExport all prices as JSON (perfect for integration).
# Print to console
$ python -m src json
# Save to file
$ python -m src json > prices.json
# Custom currencies
$ python -m src json EUR,GBP,JPYOutput format:
{
"bitcoin": {...},
"gold": {...},
"exchange_rates": {...},
"timestamp": "2026-06-10T15:32:44.123456"
}Show all available commands and usage.
from src.price_fetcher import PriceFetcher
fetcher = PriceFetcher()btc = fetcher.fetch_bitcoin()
print(f"Bitcoin: ${btc.price:,.2f}")
print(f"Change: {btc.change_24h:+.2f}%")
print(f"Updated: {btc.timestamp}")Returns: BitcoinPrice object with:
price: float- Current price in USDcurrency: str- Currency code ("USD")change_24h: float- 24-hour change percentagetimestamp: datetime- Last update timesymbol: str- "BTC"name: str- "Bitcoin"source: str- Data source identifier
gold = fetcher.fetch_gold()
print(f"Gold: ${gold.price:,.2f}/oz")
print(f"Change: {gold.change_24h:+.2f}%")Returns: GoldPrice object with:
price: float- Price per troy ounce in USDcurrency: str- "USD"unit: str- "troy ounce"change_24h: float- 24-hour change percentagetimestamp: datetime- Last update timesymbol: str- "XAU"name: str- "Gold"source: str- Data source
# Single currency
rate = fetcher.fetch_exchange_rate("EUR")
print(f"1 USD = {rate.rate} EUR")
# Multiple currencies
rates = fetcher.fetch_multiple_rates(["EUR", "GBP", "JPY"])
for currency, rate in rates.items():
print(f"1 USD = {rate.rate} {currency}")Returns: ExchangeRate object (for single) or dict (for multiple)
# Get everything
response = fetcher.fetch_all(
fetch_bitcoin=True,
fetch_gold=True,
fetch_rates=["EUR", "MXN", "ARS"]
)
# Access data
print(f"Bitcoin: ${response.bitcoin.price}")
print(f"Gold: ${response.gold.price}")
# Iterate rates
for currency, rate in response.exchange_rates.items():
print(f"{currency}: {rate.rate}")
# Convert to dict
data_dict = response.to_dict()import json
from src.price_fetcher import PriceFetcher
fetcher = PriceFetcher()
response = fetcher.fetch_all()
with open("prices.json", "w") as f:
json.dump(response.to_dict(), f, indent=2)currency = "EUR"
if fetcher.validate_currency(currency):
rate = fetcher.fetch_exchange_rate(currency)
else:
print(f"{currency} not supported")currencies = fetcher.get_supported_currencies()
print("Supported:", ", ".join(currencies))
# Output: Supported: ARS, AUD, BRL, CAD, CHF, CNY, EUR, GBP, INR, JPY, MXNfrom flask import Flask, jsonify
from src.price_fetcher import PriceFetcher
app = Flask(__name__)
fetcher = PriceFetcher()
@app.route('/api/prices')
def get_prices():
response = fetcher.fetch_all(fetch_rates=["EUR", "GBP", "JPY"])
return jsonify(response.to_dict())
@app.route('/api/bitcoin')
def get_bitcoin():
btc = fetcher.fetch_bitcoin()
return jsonify({
"symbol": btc.symbol,
"price": btc.price,
"currency": btc.currency
})
if __name__ == '__main__':
app.run(debug=True)from src.price_fetcher import PriceFetcher, InvalidCurrencyError
fetcher = PriceFetcher()
try:
rate = fetcher.fetch_exchange_rate("INVALID")
except InvalidCurrencyError as e:
print(f"Error: {e}")
print("Valid currencies:", fetcher.get_supported_currencies())Data models validate automatically:
from src.models import BitcoinPrice
from datetime import datetime
# This raises ValueError (price out of range)
try:
btc = BitcoinPrice(
price=500.0, # Should be 1,000-200,000
timestamp=datetime.now(),
change_24h=0.0,
source="test"
)
except ValueError as e:
print(f"Validation error: {e}")Use the CLI for quick checks:
python -m src allOr Python API for programmatic access:
fetcher.fetch_all()Yes! Edit BITCOIN_DATA, GOLD_DATA, or EXCHANGE_RATES constants in src/price_fetcher.py to integrate with real APIs.
As a library:
from src.price_fetcher import PriceFetcher
fetcher = PriceFetcher()
# Use as shown aboveAs a CLI tool:
python -m src json > prices.jsonPython 3.10 and higher. Check your version:
python --version- For mock data: Edit constants in
src/price_fetcher.py - For real APIs: Modify
fetch_*methods to call external APIs - For new currencies: Add to
EXCHANGE_RATESdict andExchangeRate.VALID_CURRENCIES
No, they're realistic mock data for demonstration. This is an educational project, not a real financial service.
As-is, no (mock data). But you can use it as a template to integrate real price sources.