Implemented parallel async API calls and implemented support for bittrex and poloniex
This commit is contained in:
@@ -1,3 +0,0 @@
|
|||||||
def get_answer():
|
|
||||||
"""Get an answer."""
|
|
||||||
return True
|
|
||||||
37
bot/market_data_crawler.py
Normal file
37
bot/market_data_crawler.py
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
import tornado.escape, tornado.httpclient
|
||||||
|
|
||||||
|
def update_market_data_for_basecoin(basecoin):
|
||||||
|
global market_data
|
||||||
|
market_data = {}
|
||||||
|
market_requests = []
|
||||||
|
|
||||||
|
"""Bittrex"""
|
||||||
|
|
||||||
|
def handle_response_bittrex(response):
|
||||||
|
if response.error:
|
||||||
|
print("Error: %s" % response.error)
|
||||||
|
else:
|
||||||
|
response_data = tornado.escape.json_decode(response.body)
|
||||||
|
|
||||||
|
for market in response_data["result"]:
|
||||||
|
base, target = market["MarketName"].split("-")
|
||||||
|
if base == basecoin:
|
||||||
|
market_data.update({
|
||||||
|
target: {
|
||||||
|
"Bittrex": market["Last"]
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
bittrex = {
|
||||||
|
"url": "https://bittrex.com/api/v1.1/public/getmarketsummaries",
|
||||||
|
"response_handler": handle_response_bittrex
|
||||||
|
}
|
||||||
|
|
||||||
|
market_requests.append(bittrex)
|
||||||
|
|
||||||
|
http_client = tornado.httpclient.AsyncHTTPClient()
|
||||||
|
for request in market_requests:
|
||||||
|
print("Doing request to {0}".format(request["url"]))
|
||||||
|
http_client.fetch(request["url"], request["response_handler"])
|
||||||
|
|
||||||
Reference in New Issue
Block a user