try get exchange rate by api
This commit is contained in:
parent
52e07cb5b1
commit
c842848571
1 changed files with 10 additions and 4 deletions
|
@ -13,11 +13,17 @@ THIRD_PARTY_MULTIPLIER = Decimal('1.5')
|
|||
PROFIT_MULTIPLIER = Decimal('1.1') # At the time we are really just trying to break even
|
||||
PRICE_PER_1K_TOKEN = BASE_COST_GPT_3_5 * THIRD_PARTY_MULTIPLIER * PROFIT_MULTIPLIER
|
||||
|
||||
exchange_rate_api_key = Config('exchange_rate_api_key')
|
||||
exchange_rate_api_url = f'https://v6.exchangerate-api.com/v6/{exchange_rate_api_key}/pair/USD/CNY/1.0'
|
||||
exchange_rate_data = await get_url(exchange_rate_api_url, 200, fmt='json')
|
||||
if data['result'] == "success":
|
||||
USD_TO_CNY = Decimal(exchange_rate_data['conversion_result'])
|
||||
else:
|
||||
USD_TO_CNY = Decimal('7.3') # Assuming 1 USD = 7.3 CNY
|
||||
|
||||
|
||||
async def count_petal(tokens):
|
||||
USD_TO_CNY = Decimal('7.3')
|
||||
CNY_TO_PETAL = 100 # Assuming 1 USD = 7.3 CNY, 100 petal = 1 CNY
|
||||
|
||||
CNY_TO_PETAL = 100 # 100 petal = 1 CNY
|
||||
price = tokens / ONE_K * PRICE_PER_1K_TOKEN
|
||||
petal = price * USD_TO_CNY * CNY_TO_PETAL
|
||||
return petal
|
||||
|
@ -79,4 +85,4 @@ def lost_petal(msg: Bot.MessageSession, amount):
|
|||
p = [p]
|
||||
update_stored_list(msg.target.client_name, 'lostpetal', p)
|
||||
msg.data.modify_petal(-amount)
|
||||
return msg.locale.t('petal.message.lost.success', amount=amount)
|
||||
return msg.locale.t('petal.message.lost.success', amount=amount)
|
||||
|
|
Reference in a new issue