LUCIT-Systems-and-Development / unicorn-binance-websocket-api

A Python SDK by LUCIT to use the Binance Websocket API`s (com+testnet, com-margin+testnet, com-isolated_margin+testnet, com-futures+testnet, com-coin_futures, us, tr, dex/chain+testnet) in a simple, fast, flexible, robust and fully-featured way.
https://unicorn-binance-websocket-api.docs.lucit.tech/
Other
688 stars 164 forks source link

[question] swap markets, and past 200 klines #41

Closed nagualcode closed 4 years ago

nagualcode commented 4 years ago

Hello! I am hacking the examples.. While learning about Python. I am looking to get klines from the btcusd Swap market. This is what I came up: binance_websocket_api_manager.create_stream(["kline_4h"], markets)

With this I can get 1 json object with the most recent kline at first, and then the streaming goes on with new knlines... But how could I get the past 200 klines at once?

Also, is this the swap market? BinanceWebSocketApiManager(exchange="binance.com-futures")

Thank you!

oliver-zehentleitner commented 4 years ago

hi nagualcode!

be aware that you get klines_4h in the beginning of the 4 hours frame with 0 volume, during the 4 hours on changes (trades) and when the 4 hours end (the final candlestick). Just save the last kline with an event_time later than the kline_close_time. Look here for an example: https://github.com/oliver-zehentleitner/unicorn-binance-websocket-api/blob/43e5625ebe9c006c3e3224b53597e60a5df76545/example_kline_1m.py#L76

With ws its not possible to get "old" data. If you want that, you have to use REST API with python-binance or ccxt. Here is an example!

What exactly is swap market? On binance you see a spot, margin and futures account. to use spot you have to use binance.com.

Best regards, Oliver