Consider the following mini-program:
import ccxt.async as ccxt
import asyncio
bitfinex = ccxt.bitfinex()
poloniex = ccxt.poloniex()
for exchange in (bitfinex, poloniex):
exchange.verbose = True
async def get_book(exchange, symbol):
result = await exchange.fetch_order_book(symbol)
return result
async def get_data_directly(exchange):
result = await get_book(exchange, 'ETH/BTC')
print(result)
loop = asyncio.get_event_loop()
Running get_data_directly with either bitfinex or poloniex should print the order book. But that's not what happens.
Running it with poloniex works fine:
>>> loop.run_until_complete(get_data_directly(poloniex))
Request: GET https://poloniex.com/public?command=returnOrderBook¤cyPair=BTC_ETH {'User-Agent': 'python-requests/2.18.4', 'Accept-Encoding': 'gzip, deflate'} None
Response: GET https://poloniex.com/public?command=returnOrderBook¤cyPair=BTC_ETH 200 <CIMultiDictProxy('Date': 'Wed, 28 Feb 2018 08:22:35 GMT', 'Content-Type': 'application/json', 'Transfer-Encoding': 'chunked', 'Connection': 'keep-alive', 'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Methods': 'GET', 'Content-Encoding': 'gzip', 'Expect-CT': 'max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"', 'Server': 'cloudflare', 'CF-RAY': '3f41fa0e9a001798-SIN')>
{"asks":[["0.08136930",4],["0.08136997",3.08290226],["0.08138340",0.12599382],["0.08140007",0.37714999],["0.08140597",129.17701955],["0.08140598",75.835],["0.08140600",11.4139],["0.08141055",73.81301107],["0.08143130",0.00228914],["0.08145754",0.0030698],["0.08146258",3.739],["0.08149999",0.00124198]
_(poloniex orderbook truncated for display purposes)_
However running it with bitfinex results in an empty order book:
>>> loop.run_until_complete(get_data_directly(bitfinex))
Request: GET https://api.bitfinex.com/v1/book/ETHBTC?limit_bids=None&limit_asks=None {'User-Agent': 'python-requests/2.18.4', 'Accept-Encoding': 'gzip, deflate'} None
Response: GET https://api.bitfinex.com/v1/book/ETHBTC?limit_bids=None&limit_asks=None 200 <CIMultiDictProxy('Date': 'Wed, 28 Feb 2018 08:22:25 GMT', 'Content-Type': 'application/json; charset=utf-8', 'Content-Length': '21', 'Connection': 'keep-alive', 'X-Frame-Options': 'SAMEORIGIN', 'X-XSS-Protection': '1; mode=block', 'X-Content-Type-Options': 'nosniff', 'ETag': 'W/"0036d08cbce146de126d93d51f91c968"', 'Cache-Control': 'max-age=0, private, must-revalidate', 'X-Request-Id': 'f2faa7a6-3a3d-43b9-9a53-fc8a322e1cff', 'X-Runtime': '0.002434', 'Strict-Transport-Security': 'max-age=31536000', 'X-Frame-Options': 'SAMEORIGIN', 'Expect-CT': 'max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"', 'Server': 'cloudflare', 'CF-RAY': '3f41f9d81c066f96-SIN')> {"bids":[],"asks":[]}
{'bids': [], 'asks': [], 'timestamp': 1519806145693, 'datetime': '2018-02-28T08:22:26.693Z'}
Wow that was fast.
@UnitNote thanks for your thorough report! Try ccxt 1.10.1254, it聽should work now. Let us know if you still have difficulties with it. Thx again!
No problem. Confirmed working with the latest version.