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: fetchOrder() fetchOrders() UsdcSettled, future and inverse markets question #14275

Closed wunderb1t closed 10 months ago

wunderb1t commented 2 years ago

We notice that in last version there is no fetchOrder support for UsdcSettled, future and inverse markets in bybit.js. Also by the logic in bybit.js code alternatives enters into fetchOrders were i.e. future and inverse markets actually supported.

bybit.js fetchOrder method code snippet:

if (isUsdcSettled || market['future'] || market['inverse']) {
    throw new NotSupported (this.id + ' fetchOrder() supports spot markets and linear non-USDC perpetual swap markets only');
} else {
    // only linear swap markets allow using all purpose
    // fetchOrders endpoint filtering by id
        const orders = await this.fetchOrders (symbol, undefined, undefined, params);
        const order = this.safeValue (orders, 0);
        if (order === undefined) {
            throw new OrderNotFound (this.id + ' fetchOrder() order ' + id + ' not found');
        }
        return order;
}

bybit.js fetchOrders method code snippet:

if (market['linear']) {
        method = isConditionalOrder ? 'privateGetPrivateLinearStopOrderList' : 'privateGetPrivateLinearOrderList';
} else if (market['future']) {
        method = isConditionalOrder ? 'privateGetFuturesPrivateStopOrderList' : 'privateGetFuturesPrivateOrderList';
} else {
        // inverse swap
        method = isConditionalOrder ? 'privateGetV2PrivateStopOrderList' : 'privateGetV2PrivateOrderList';
}

That is just mistake or this can be described by some logic that we don't see? If that's all is correct then which method should we use instead of fetchOrder for UsdcSettled, future and inverse markets?

carlosmiei commented 2 years ago

Hello @wunderb1t,

Bybit has different APIs depending on the market type (spot, swap, usdc, etc). Our current definition of "fetchOrder" says that it should return the order associated with a specific id regardless of its state. For some markets Bybit does not support this, we have to choose between fetching open or closed orders.

Our suggestion: if fetchOrder is not supported you could try replace it by fetchOpenOrders and/or fetchClosedOrders

shyrik13 commented 2 years ago

Is there any possibility to resolve this on ccxt side in fetchOrder method (use different fetchOrders methods for different market types)? Because that will be really handy to use only one fetchOrder method for different markets (like it is made on different exchanges instances). Also I've noticed that e.g. for inverse markets there is order id in received response from exchange if pass into fetchOrders, but there is very strange price, cost, average fields results.

OS: Debian (Docker) Programming Language version: NodeJS, JavaScript CCXT version: PRO 1.1.88

wunderb1t commented 2 years ago

Is there any possibility to resolve this on ccxt side in fetchOrder method (use different fetchOrders methods for different market types)? Because that will be really handy to use only one fetchOrder method for different markets (like it is made on different exchanges instances). Also I've noticed that e.g. for inverse markets there is order id in received response from exchange if pass into fetchOrders, but there is very strange price, cost, average fields results.

OS: Debian (Docker) Programming Language version: NodeJS, JavaScript CCXT version: PRO 1.1.88

@carlosmiei there will be possibilities in future that mentioned in this comment?

carlosmiei commented 2 years ago

Hello @wunderb1t We can't add that on the ccxt side, fetchOrder conceptually should be able to fetch the information about an order regardless of its state with a single REST API call. You can always monkey patch the exchange on your side and override the fetchOrder definition to make 2 calls, fetchOpenOrders + fetchClosedOrders

Kinzowa commented 1 year ago

Hello @wunderb1t,

Bybit has different APIs depending on the market type (spot, swap, usdc, etc). Our current definition of "fetchOrder" says that it should return the order associated with a specific id regardless of its state. For some markets Bybit does not support this, we have to choose between fetching open or closed orders.

Our suggestion: if fetchOrder is not supported you could try replace it by fetchOpenOrders and/or fetchClosedOrders

Hi Carlos,

I'm facing a situation where an order in inverse market was cancelled and I'm unable to update my database because fetchOrder is not supported with COIN-margined perp, and fetchOpenOrders and fetchClosedOrders don't return this cancelled order. fetchCanceledOrders is not supported neither. Seems like we must extrapolate in this specific case.

frosty00 commented 1 year ago

you can use fetchOrders ({ settle: 'USDC' })