Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Jinja2==3.1.2
python-multipart==0.0.5
fastapi==0.89.1
uvicorn==0.20.0
aiofiles==22.1.0
aiohttp==3.8.5
requests==2.31.0
aiofiles==24.1.0
aiohttp==3.12.15
fastapi==0.116.1
Jinja2==3.1.6
python-multipart==0.0.20
requests==2.32.5
uvicorn==0.35.0
25 changes: 15 additions & 10 deletions src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ def get_block_height():
def coindesk_btc_fiat(symbol):
# batch the requests together via asyncio or multiprocessing
setlocale(LC_NUMERIC, '')
url = f'https://api.coindesk.com/v1/bpi/currentprice/{symbol}.json'
url = f'https://data-api.coindesk.com/index/cc/v1/latest/tick?market=cadli&instruments={symbol}'
response = requests.get(url)
ticker = response.json()
time = ticker["time"]['updated']
rate = ticker['bpi'][symbol]['rate']
object = response.json()

parsed_rate = atof(rate.replace(',', ''))
data = object['Data'][symbol]
time = data["VALUE_LAST_UPDATE_TS"]
rate = data['VALUE']

return time, parsed_rate
return time, rate


title = "sats converter"
Expand Down Expand Up @@ -66,15 +66,18 @@ def coindesk_btc_fiat(symbol):
app.mount("/static", StaticFiles(directory="static"), name='static')
templates = Jinja2Templates(directory='templates/')

fiatlist = ['USD', 'EUR', 'JPY', 'CAD', 'AUD', 'GBP', 'PLN']
fiatlist = ['USD', 'EUR', 'JPY', 'CAD', 'AUD', 'GBP', 'PLN',
'CHF', 'HKD', 'CNY', 'SGD', 'TWD', 'THB', 'KRW',
'BRL', 'RUB', 'TRY']

# initial get for index page
@app.get("/")
async def initial_page(request: Request):

satsamt = 100000000
currency = 'USD'
time, rate = coindesk_btc_fiat(currency)
symbol = 'BTC-'+currency
time, rate = coindesk_btc_fiat(symbol)
btcusd = "%.2f" % (rate)
moscowtime = int(100000000/float(btcusd))
height = get_block_height()
Expand Down Expand Up @@ -104,7 +107,8 @@ async def submit_form(request: Request, selected: str = Form(...)): # trunk-
if selected is None:
return RedirectResponse('/', status_code=status.HTTP_302_FOUND)

time, rate = coindesk_btc_fiat(selected)
symbol = 'BTC-'+selected
time, rate = coindesk_btc_fiat(symbol)
btcfiat = "%.2f" % rate
moscowtime = int(100000000/float(btcfiat))
height = get_block_height()
Expand Down Expand Up @@ -153,7 +157,8 @@ async def get_rate(pair: str):
if currency is None:
return RedirectResponse('/', status_code=status.HTTP_302_FOUND)

_, rate = coindesk_btc_fiat(currency.upper())
symbol = (currency1+'-'+currency2).upper()
_, rate = coindesk_btc_fiat(symbol)

if not inverse and not sat:
btcfiat = "%.2f" % rate
Expand Down
11 changes: 6 additions & 5 deletions src/test_coindesk.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
asian_list = ['HKD', 'CNY', 'SGD', 'AUD', 'TWD', 'THB', 'KRW', 'JPY']
g7currencies = ['HKD', 'CNY', 'SGD', 'GBP', 'EUR', 'AUD', 'JPY']

for symbol in asian_list:
time, rate = coindesk_btc_fiat(symbol)
arate = "%.2f" % rate
print(arate)
print(f'BTC/{symbol}: {"%.2f" % rate}')
for coin in asian_list:
symbol = f'BTC-{coin}'
time, rate = coindesk_btc_fiat(symbol)
arate = "%.2f" % rate
print(arate)
print(f'BTC-{coin}: {"%.2f" % rate}')


'''
Expand Down