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

Bingx - parse order price / cost wrong #22560

Closed
xmatthias opened this issue May 20, 2024 · 2 comments · Fixed by #22573
Closed

Bingx - parse order price / cost wrong #22560

xmatthias opened this issue May 20, 2024 · 2 comments · Fixed by #22573
Assignees
Labels

Comments

@xmatthias
Copy link
Contributor

xmatthias commented May 20, 2024

Operating System

python

Programming Languages

Python

CCXT Version

4.3.28

Description

For (filled) stop orders - average is missing (probably a duplicate of #21419).

What's worse though is that cost is NOT correct.

This order filled at 0.0000094949 - and was for 10_417_100 - a USDT cost of 98.9103370717.

The (parsed) result from ccxt however has "98.80306837" as cost - which (i assume) is simply price * amount.
The "stoploss" response from the exchange does have a corresponding field in "cummulativeQuoteQty" - which does contain the correct cost - and which i think should be used by ccxt.

I understand that price is the limit of the stop limit price - and i also kinda understand that average is not filled currently - as it's not provided by the exchange.

However unfortunately, the absence of average - combined with the wrongness of cost makes it currently near impossible to correctly calculate the price for an order (without using the info object) - which i find rather unfortunate.

image

{
    "info": {
        "symbol": "PEPE-USDT",
        "orderId": "xxxxxx",
        "price": "0.0000094847",
        "StopPrice": "0.0000094941",
        "origQty": "10417100",
        "executedQty": "10417100",
        "cummulativeQuoteQty": "98.91033707177569",
        "status": "FILLED",
        "type": "TAKE_STOP_LIMIT",
        "side": "SELL",
        "time": "1716226349971",
        "updateTime": "1716226676000",
        "origQuoteOrderQty": "0",
        "fee": "-0.09891033707214325",
        "feeAsset": "USDT",
        "clientOrderID": ""
    },
    "id": "xxxxxx",
    "clientOrderId": None,
    "symbol": "PEPE/USDT",
    "timestamp": 1716226349971,
    "datetime": "2024-05-20T17:32:29.971Z",
    "lastTradeTimestamp": 1716226676000,
    "lastUpdateTimestamp": 1716226676000,
    "type": "take_stop_limit",
    "timeInForce": None,
    "postOnly": None,
    "side": "sell",
    "price": 9.4847e-06,
    "stopPrice": None,
    "triggerPrice": None,
    "stopLossPrice": 9.4941e-06,
    "takeProfitPrice": 9.4941e-06,
    "average": None,
    "cost": 98.80306837,
    "amount": 10417100.0,
    "filled": 10417100.0,
    "remaining": 0.0,
    "status": "closed",
    "fee": {
        "currency": "USDT",
        "cost": "0.09891033707214325"
    },
    "trades": [],
    "reduceOnly": None,
    "fees": [
        {
            "currency": "USDT",
            "cost": 0.09891033707214325
        }
    ]
}

Code

import ccxt
exchange = ccxt.bingx({
    'apiKey': '<yourApiKey>', 
    'secret': '<yoursecret>', 
    })
exchange.fetch_order(<orderid>, 'PEPE/USDT')
print(res)
@sc0Vu sc0Vu self-assigned this May 21, 2024
@sc0Vu sc0Vu added the bug label May 21, 2024
@sc0Vu
Copy link
Contributor

sc0Vu commented May 21, 2024

@xmatthias looks like the cost was wrong, what's the price of the order? I used cummulativeQuoteQty / executedQty (9.494997366999999e-6) or (cummulativeQuoteQty - fee) / executedQty (9.485502369632964e-6), but the number didn't match......

@xmatthias
Copy link
Contributor Author

xmatthias commented May 21, 2024

hi @sc0Vu,

Well the price is shown in the screenshot (took a highlighted screenshot from the order below for you to highlight this).
the price shown on exchange IS 0.0000094949 - which is what your first calculation yielded cummulativeQuoteQty / executedQty.
you got 0.00000949497366999999 - which is the same for the first 10(!) decimals - and the rest, I'd assume to be a rounding problem (it'll most likely disappear if you do string math).

Now the exchange will truncate the remaining decimals - but it's a LOT better than what ccxt is currently providing - which is using the price of the limit order - so "stop price - 1%" in my case - which is 1% below the actual execution price.

Screenshot

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

Successfully merging a pull request may close this issue.

2 participants