Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fetching Bingx historical data #22

Open
cipoeth opened this issue Sep 30, 2023 · 2 comments
Open

Fetching Bingx historical data #22

cipoeth opened this issue Sep 30, 2023 · 2 comments

Comments

@cipoeth
Copy link

cipoeth commented Sep 30, 2023

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
Copy link

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
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants