Binance Python Spot API returns wrong data for certain timestamps

Viewed 26

I came across a weird problem with Binance API. There are 438 ETH and 434 BTC timestamps for which the API returns the wrong data. For ETH, some of them are:

  • 2017-09-06 16:01:00
  • 2017-12-04 06:01:00
  • 2017-12-18 10:01:00
  • 2017-12-18 12:30:00

When I request the data for one of these defunct timestamps, the Binance response returns a different timestamp, while for all others, the response timestamp is the same as the request timestamp.

I put together the simplest reproducible example to illustrate the difference in Binance's response for normal and defunct timestamps.

Code:

import json
from binance.spot import Spot
from datetime import timezone
from datetime import datetime
import numpy as np

f = open('../data.json')

cred = json.load(f)
key = cred['key']
secret = cred['secret']

client = Spot(key=key, secret=secret)

def to_milliseconds(time):
    return int(np.datetime64(time, 'ms').astype('int64'))


def to_timestamp(time):
    return np.datetime64(datetime.fromtimestamp(int(time) / 1000, tz=timezone.utc), 'm')

normal_timestamp = "2018-05-02T10:00"
defunct_timestamp = "2017-09-06T16:01"

for id, timestamp in enumerate([normal_timestamp, defunct_timestamp]):

    start_time = np.datetime64(timestamp, 'm')

    start_time_ms = to_milliseconds(start_time)

    ticker = client.klines(symbol='ETHUSDT', interval='1m', limit=1, startTime=start_time_ms)

    return_time_ms = ticker[0][0]

    print('Case {id}. Request time: {request_time} (in ms: {request_time_in_ms}). Response time: {response_time} (in ms: {response_time_in_ms})'.format(
        id=id,
        request_time=start_time,
        request_time_in_ms=start_time_ms,
        response_time=to_timestamp(return_time_ms),
        response_time_in_ms=return_time_ms
    ))

Output:

Case 0. Request time: 2018-05-02T10:00 (in ms: 1525255200000). Response time: 2018-05-02T10:00 (in ms: 1525255200000)
Case 1. Request time: 2017-09-06T16:01 (in ms: 1504713660000). Response time: 2017-09-06T23:00 (in ms: 1504738800000)

Did someone encounter that too? What would be the reason for that?

0 Answers
Related