ccxt / ccxt

A JavaScript / TypeScript / Python / C# / PHP cryptocurrency trading API with support for more than 100 bitcoin/altcoin exchanges
https://docs.ccxt.com
MIT License
32.5k stars 7.47k forks source link

Binance Futures OHLCV #8084

Closed Physicworld closed 3 years ago

Physicworld commented 3 years ago

MUST READ THIS BEFORE SUBMITTING ISSUES (read the links, then delete this message before submitting):

Make sure your local version of CCXT is up to date. Check by comparing the output of ccxt.version to https://github.com/ccxt/ccxt/blob/master/package.json#L3

exchange = ccxt.binance({
    'enableRateLimit':True,

    'options': {
    'defaultType': 'future',
    }
})

markets = exchange.load_markets()
print(exchange.has['fetchOHLCV'])

print(exchange.fetch_ohlcv(symbol = 'BTC/USDT', timeframe = '1h'))```

Traceback (most recent call last): File "histc.py", line 17, in print(exchange.fetch_ohlcv(symbol = 'BTC/USDT', timeframe = '1h')) File "/home/domingocajina/anaconda3/envs/NeuroBot/lib/python3.7/site-packages/ccxt/binance.py", line 1168, in fetch_ohlcv market = self.market(symbol) File "/home/domingocajina/anaconda3/envs/NeuroBot/lib/python3.7/site-packages/ccxt/base/exchange.py", line 1791, in market raise BadSymbol('{} does not have market symbol {}'.format(self.id, symbol)) ccxt.base.errors.BadSymbol: binance does not have market symbol BTC/USDT



If i change 'future' by 'spot' it works, i wanna call all the historical data from binance futures for all symbols, but idk what im doing wrong, i read the docs.

Thanks for your answer!
Physicworld commented 3 years ago

Ok i update the library and now works!

Sekharonline4u commented 3 years ago

Hello Team, I have two questions while using the CCXT Library for Future Trading

1st Question: I have been using the CCXT Library for working with the Binance Futures Trading, it is working fine for the Spot while retrieving the data of OHLCV but while using the following _"bars = exchange.fetchohlcv(symbol, timeframe='1m', limit=100)" statement am getting the same value for all i.e the values for open, high, low, close has the same data and the value for the volume am getting is 0. Currently am using the "1.52.30" version of CCXT

Code:

exchange = ccxt.binance({
    "apiKey": config.BINANCE_FUTURE_API_KEY,
    "secret": config.BINANCE_FUTURE_SECRET_KEY,
    'enableRateLimit': True,
    'options': {
        'defaultType': 'future',  # testnet urls work with futures
    }
})
exchange.set_sandbox_mode(True)
exchange.load_markets()
symbol = 'DOGE/USDT'
market = exchange.market(symbol)
leverage =  20
response = exchange.fapiPrivate_post_leverage({
    'symbol': market['id'],
    'leverage': leverage,
})

def run_bot():
    print(f"Fetching new bars for {datetime.now().isoformat()}")

    print(exchange.has['fetchOHLCV'])

    bars = exchange.fetch_ohlcv(symbol, timeframe='1m', limit=100)

    df = pd.DataFrame(bars[:-1], columns=['timestamp',
                      'open', 'high', 'low', 'close', 'volume'])
    df['timestamp'] = pd.to_datetime(df['timestamp'], unit='ms') + pd.Timedelta('05:30:00')
    print(df)

Am getting the following output:

'symbol': 'DOGEUSDT', 'leverage': '20', 'maxNotionalValue': '25000'}
Getting your current position mode (One-way or Hedge Mode):
You are in One-way Mode
----------------------------------------------------------------------
Fetching new bars for 2021-07-04T00:45:04.871635
True
             timestamp     open     high      low    close  volume
0  2021-07-03 23:06:00  0.24769  0.24769  0.24769  0.24769     0.0
1  2021-07-03 23:07:00  0.24769  0.24769  0.24769  0.24769     0.0
2  2021-07-03 23:08:00  0.24769  0.24769  0.24769  0.24769     0.0
3  2021-07-03 23:09:00  0.24769  0.24769  0.24769  0.24769     0.0
4  2021-07-03 23:10:00  0.24769  0.24769  0.24769  0.24769     0.0
5  2021-07-03 23:11:00  0.24769  0.24769  0.24769  0.24769     0.0

2nd Question: Can we use the same exchange.create_market_buy_order(symbol, amount) and exchange.create_market_sell_order(symbol, amount) to place the orders in Binance Future Market.

Kindly do help me out

Thanks and Regards Sekhar

kroitor commented 3 years ago

@Sekharonline4u hi!

1st Question: ... the values for open, high, low, close has the same data and the value for the volume am getting is 0.

That is not an issue with CCXT. Nobody trades DOGE/USDT with Binance testnet, hence the sandbox volumes are zero. On real production systems, the volumes are real as well. Comment this line: exchange.set_sandbox_mode(True).

2nd Question: Can we use the same exchange.create_market_buy_order(symbol, amount) and exchange.create_market_sell_order(symbol, amount) to place the orders in Binance Future Market.

Yes.