BingX-API / BingX-swap-api-doc

bingx api doc
33 stars 23 forks source link

Fetching Bingx historical data #22

Open cipoeth opened 9 months ago

cipoeth commented 9 months ago

Hello everybody,

I have an issue fetching historical data with the bingx API, I can only fetch one single candle, I try different approach and methods but always the same output, somebody knows how to fix this issue?

Script:

`def fetch_all_timeframes_data(exchange, symbol, timeframes, limit=100, market_type='futures'):
data_dict = {}
    for timeframe in timeframes:
        try:
            data = exchange.fetch_ohlcv(symbol, timeframe, limit=limit, params={'type': market_type})
            data_dict[timeframe] = data
            print(f"Fetched {len(data)} candles for timeframe: {timeframe}")
            for row in data:
                timestamp = datetime.fromtimestamp(row[0] / 1000).strftime('%Y-%m-%d %H:%M:%S')
                print(f"{timestamp}: {row}")
            time.sleep(2)
        except Exception as e:
            print(f"Error fetching data for timeframe {timeframe}: {e}")
    return data_dict`

Log:

Fetched 1 candles for timeframe: 1m 2023-09-30 11:56:00: [1696067760000, 57.1, 57.1, 56.973, 56.973, 283.88] Fetched 1 candles for timeframe: 5m 2023-09-30 11:55:00: [1696067700000, 57.137, 57.184, 56.973, 56.997, 1441.26] Fetched 1 candles for timeframe: 15m 2023-09-30 11:45:00: [1696067100000, 57.219, 57.428, 56.815, 57.009, 29509.82] Fetched 1 candles for timeframe: 30m 2023-09-30 11:30:00: [1696066200000, 57.352, 57.468, 56.719, 57.026, 84049.6]

amirinsight commented 9 months ago

Hi! Are you using the correct endpoint? "GET /openApi/swap/v3/quote/klines" You can also check out my implementation here: https://github.com/amirinsight/py-bingx

from bingx.api import BingxAPI

bingx = BingxAPI(API_KEY, SECRET_KEY, timestamp="local")
candles = bingx.get_kline_data("BTC-USDT", "30m", limit=100)
print(candles)
bingx-support commented 5 months ago

please user BingX official API docs https://bingx-api.github.io/docs/#/en-us/swapV2/market-api.html#Get%20Latest%20Price%20of%20a%20Trading%20Pair