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.45k stars 7.46k forks source link

Bybit fetchBalance makes call to /v5/asset/coin/query-info #23232

Closed ricardomatias closed 1 month ago

ricardomatias commented 1 month ago

Operating System

Mac OS Ventura 13.6.7

Programming Languages

JavaScript

CCXT Version

4.3.68

Description

As title says, when trying to fetch a balance and having verbose enabled I see a call the following: bybit GET https://api-demo.bybit.com/v5/asset/coin/query-info? 200 OK

And then I get the following error from the exchange: {"retCode":10032,"retMsg":"Demo trading are not supported.","result":{},"retExtInfo":{},"time":1722068066612}

Code

const exchangeClass = exchanges[broker];
const exchange = new exchangeClass({
    apiKey,
    secret: apiSecret,
    verbose: true,
    options: {
        fetchBalance: {
            coin: "USDT",
            accountType: "UNIFIED",
        },
    },
});

exchange.setSandboxMode(true);

if (exchange instanceof bybit) {
    exchange.options.defaultType = "future";

    exchange.urls["api"] = {
        spot: "https://api-demo.bybit.com",
        futures: "https://api-demo.bybit.com",
        v2: "https://api-demo.bybit.com",
        public: "https://api-demo.bybit.com",
        private: "https://api-demo.bybit.com",
    };
}

const balance = await exchange.fetchBalance({ type: "future"});
carlosmiei commented 1 month ago

Hello @ricardomatias

CCXT initially performs some calls to load and cache the markets and the currencies available at the exchange. In this case, that endpoint is not available in the demo trading but ccxt it handles it properly as long as you enable the sandbox mode (you don't need to override the urls)

Example:

exchange.set_sandbox_mode(True)
balance = await exchange.fetch_balance()
ricardomatias commented 1 month ago

Hello @carlosmiei, understood and working!