-
Notifications
You must be signed in to change notification settings - Fork 0
/
pricefeed.py
54 lines (49 loc) · 1.58 KB
/
pricefeed.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import requests
def get_last_price_from_bitso(ticker):
try:
url = f"https://api.bitso.com/v3/ticker/?book={ticker}"
response = requests.get(url)
if response.status_code == 200:
return float(response.json()["payload"]["last"])
else:
raise Exception
except:
if ticker == "usd_mxn":
return 1/0.05882352941
return None
def get_last_price_from_binance(symbol):
try:
url = f"https://api.binance.com/api/v3/ticker/price?symbol={symbol}"
response = requests.get(url)
if response.status_code == 200:
return float(response.json()["price"])
else:
raise Exception
except:
return None # No default value provided for Binance. Return None or adjust as necessary.
def get_last_price_from_bitstamp(currency_pair):
try:
url = f"https://www.bitstamp.net/api/v2/ticker/{currency_pair}/"
response = requests.get(url)
if response.status_code == 200:
return float(response.json()["last"])
else:
raise Exception
except:
if currency_pair == "xrpusd":
return 0.5
elif currency_pair == "eurusd":
return 1.07
return None
def get_exchange_rates():
rates = {
"MXN": 1/get_last_price_from_bitso("usd_mxn"),
"XRP": get_last_price_from_bitstamp("xrpusd"),
"EUR": get_last_price_from_bitstamp("eurusd"),
"USD" : 1,
"TST" : 8.5
}
return rates
if __name__ == "__main__":
rates = get_exchange_rates()
print(rates)