简体   繁体   中英

How do I get Binance API prices in Python at a precise time?

The following is how I get historical data, however the date format does not allow me to specify the minute or second of the data; only the day, which is not precise enough.

start_date_str=start_date.strftime("%d %b, %Y")
data1=client.get_historical_klines(pair, Client.KLINE_INTERVAL_1MINUTE, start_date_str)

I'm looking to get price data for a particular hour, minute and second using the python binance api provided by Sam McHardy (link below).

https://github.com/binance-exchange/python-binance

If anyone knows whether this is possible, or if there are any alternatives, I would really appreciate it.

KLINE_INTERVAL_1MINUTE is the smallest time resolution for get_historical_klines provided by Binance. If you need smaller time intervals you can use get_aggregate_trades which allows startTime and endTime in milliseconds.

This request return the list of trades, so one has to calculate average price abd total volume for desired time period.

current syntax is :

(symbol)@kline_(interval)

for example

BTCUSDT@kline_1m (one minute)

for autobahn complete json :

def onOpen(self):
    subscribe_message = {
    "method": "SUBSCRIBE",
    "params":
    [        
     "btcusdt@miniTicker",
     "btcusdt@depth"
     ],
     "id": 1
     }
  
    self.sendMessage(json.dumps(subscribe_message).encode('utf8'))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM