Binance 1 Hour Missing data

610 Views Asked by At

I am doing algo trading in Binance and using ccxt in Python. i realized today that my below code didn't work properly around 1 hour. The code "print('time', data)" produced "time 2022-05-01 19:35:00" and then same code produced "time 2022-05-01 20:45:00" next. Around 1 hour is missing. I am using Amazon server i dont know if the problem resulted from this or not. Maybe i was banned form Binance for an hour but if this was the case wouldnt i receive any error? Could you please advise me if i broke the rate limiter? Could you please share what could be the reasons? Thank you.

import ccxt
import pandas as pd
import numpy as np
import datetime
import warnings

warnings.filterwarnings("ignore", category=np.VisibleDeprecationWarning)
pd.set_option('display.max_rows', None)

exchange = ccxt.binance({
    "apiKey": 'xxx',
    "secret": 'yyy',
    'options': {
        'adjustForTimeDifference': True
    },
    'enableRateLimit': True
})

exchange_f = ccxt.binance({
    "apiKey": 'xxx',
    "secret": 'yyy',
    'options': {
        'defaultType': 'future',
        'adjustForTimeDifference': True
    },
    'enableRateLimit': True
})

coin = "ETH"+"/USDT"
exchange.load_markets()
exchange_f.load_markets()
data= pd.DataFrame([[0]], columns=['timestamp'])
# some codes here

while 1:
    try:
        bars = exchange.fetch_ohlcv(coin, timeframe='5m', limit=10)   
        bars_f = exchange_f.fetch_ohlcv(coin, timeframe='5m', limit=2)  
        df = pd.DataFrame(bars[:], columns=['timestamp', 'open', 'high', 'low', 'close', 'volume'])
        df_f = pd.DataFrame(bars_f[:], columns=['timestamp', 'open', 'high', 'low', 'close', 'volume'])
    except ccxt.BaseError as Error:
        print("[ERROR] ", Error)
        continue

if df['timestamp'].iloc[-2] not in data.values and (df['timestamp'].dt.minute.iloc[-2] % 10 == 5):
 data= pd.DataFrame([[df['timestamp'].iloc[-2]]], columns=['timestamp'])
print('time', data)
1

There are 1 best solutions below

4
On

Your assumption may be right, I used to have this problem with Freqtrade.

Binance bans you if you try to make too many requests, they remove this ban automatically just wait some time.

Here you can see all your limitations for Binance API.