-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
461417c
commit 0d01b71
Showing
2 changed files
with
100 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import requests | ||
import json | ||
import time | ||
import os | ||
import asyncio | ||
import aiohttp | ||
|
||
start = time.time() | ||
session = requests.session() | ||
http_timeout = 2 | ||
|
||
async def fx_for(symbol_to): | ||
async with aiohttp.ClientSession() as async_session: | ||
response = await async_session.get( | ||
"https://www.alphavantage.co/query", | ||
timeout=http_timeout, | ||
params={ | ||
'function': 'CURRENCY_EXCHANGE_RATE', | ||
'from_currency': 'USD', | ||
'to_currency': symbol_to, | ||
'apikey': '' | ||
} | ||
) | ||
api_result = await response.json() | ||
return api_result | ||
|
||
symbol_list = ["KRW", | ||
"EUR", | ||
"CNY", | ||
"JPY", | ||
"XDR", | ||
"MNT"] | ||
|
||
loop = asyncio.get_event_loop() | ||
futures = [fx_for(symbol_lists) for symbol_lists in symbol_list] | ||
api_result = loop.run_until_complete(asyncio.gather(*futures)) | ||
|
||
result_real_fx = { | ||
"USDUSD": 1.0, | ||
"USDKRW": 1.0, | ||
"USDEUR": 1.0, | ||
"USDCNY": 1.0, | ||
"USDJPY": 1.0, | ||
"USDSDR": 1.0, | ||
"USDMNT": 1.0 | ||
} | ||
|
||
list_number = 0 | ||
for symbol in symbol_list: | ||
if symbol == "XDR": | ||
symbol = "SDR" | ||
result_real_fx["USD"+symbol] = float( | ||
api_result[list_number]["Realtime Currency Exchange Rate"]["5. Exchange Rate"]) | ||
list_number = list_number +1 | ||
print("time :", time.time() - start) | ||
print(result_real_fx) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
0d01b71
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that this breaks Ubuntu 16.04 LTS compatibility: aio-libs/aiohttp#3588