Removing getPrices endpoint
This commit is contained in:
parent
c53484e8a4
commit
b8f7d1bb87
@ -1135,81 +1135,6 @@ async def getPriceData():
|
||||
''' Stuff required for getPrices endpoint '''
|
||||
|
||||
|
||||
def updatePrices():
|
||||
prices = {}
|
||||
|
||||
# USD -> INR
|
||||
response = requests.get(f"https://api.exchangerate-api.com/v4/latest/usd")
|
||||
try:
|
||||
price = response.json()
|
||||
prices['USDINR'] = price['rates']['INR']
|
||||
except ValueError:
|
||||
response = requests.get(
|
||||
f"https://api.exchangeratesapi.io/latest?base=USD&symbols=INR")
|
||||
try:
|
||||
price = response.json()
|
||||
prices['USDINR'] = price['rates']['INR']
|
||||
except ValueError:
|
||||
response = requests.get(
|
||||
f"https://api.ratesapi.io/api/latest?base=USD&symbols=INR")
|
||||
try:
|
||||
price = response.json()
|
||||
prices['USDINR'] = price['rates']['INR']
|
||||
except ValueError:
|
||||
# todo : add logger to the application
|
||||
print('USD to Fiat APIs arent responding')
|
||||
|
||||
# Blockchain stuff : BTC,FLO -> USD,INR
|
||||
response = requests.get(
|
||||
f"https://api.coingecko.com/api/v3/simple/price?ids=bitcoin,flo&vs_currencies=usd,inr")
|
||||
try:
|
||||
price = response.json()
|
||||
prices['BTCUSD'] = price['bitcoin']['usd']
|
||||
prices['BTCINR'] = price['bitcoin']['inr']
|
||||
prices['FLOUSD'] = price['flo']['usd']
|
||||
prices['FLOINR'] = price['flo']['inr']
|
||||
except ValueError:
|
||||
response1 = requests.get(
|
||||
f"https://api.coinlore.net/api/ticker/?id=90")
|
||||
response2 = requests.get(
|
||||
f"https://api.coinlore.net/api/ticker/?id=67")
|
||||
try:
|
||||
price1 = response1.json()
|
||||
price2 = response2.json()
|
||||
prices['BTCUSD'] = price1[0]['price_usd']
|
||||
prices['BTCINR'] = price1[0]['price_usd'] * prices['USDINR']
|
||||
prices['FLOUSD'] = price2[0]['price_usd']
|
||||
prices['FLOINR'] = price2[0]['price_usd'] * prices['USDINR']
|
||||
except ValueError:
|
||||
response1 = requests.get(
|
||||
f"https://api.coinpaprika.com/v1/tickers/btc-bitcoin")
|
||||
response2 = requests.get(
|
||||
f"https://api.coinpaprika.com/v1/tickers/flo-flo")
|
||||
try:
|
||||
price1 = response1.json()
|
||||
price2 = response2.json()
|
||||
prices['BTCUSD'] = price1['quotes']['usd']['price']
|
||||
prices['BTCINR'] = price1['quotes']['usd']['price'] * \
|
||||
prices['USDINR']
|
||||
prices['FLOUSD'] = price2['quotes']['usd']['price']
|
||||
prices['FLOINR'] = price2['quotes']['usd']['price'] * \
|
||||
prices['USDINR']
|
||||
except ValueError:
|
||||
# todo : add logger to the application
|
||||
print('Blockchain to Fiat APIs arent responding')
|
||||
|
||||
# 3. update latest price data
|
||||
print('Prices updated at time: %s' % datetime.now())
|
||||
print(prices)
|
||||
|
||||
conn = sqlite3.connect('system.db')
|
||||
c = conn.cursor()
|
||||
for pair in list(prices.items()):
|
||||
pair = list(pair)
|
||||
c.execute(
|
||||
f"UPDATE ratepairs SET price={pair[1]} WHERE ratepair='{pair[0]}'")
|
||||
conn.commit()
|
||||
|
||||
|
||||
# if system.db isn't present, initialize it
|
||||
if not os.path.isfile(f"system.db"):
|
||||
|
||||
Loading…
Reference in New Issue
Block a user