question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

trade details for future bug?

See original GitHub issue
  • CCXT version: 1.84.75

It seems that there is some issue for future trade detail for some exchange as cost != price * amount and the trade details seems off.

kucoinfutures: price:29580.89, amount: 745 <- this seems very off, cost: 22037.76305 okx: ‘price’: 29474.0, ‘amount’: 10.0, ‘cost’: 2947.4 huobi: ‘price’: 29277.4, ‘amount’: 2364.0, <-- i think this got multiplied by 1000, ‘cost’: 69211.7736, mexc: ‘price’: 29444.5, ‘amount’: 319.0, ‘cost’: 939.27955 aax: ‘price’: 29717.53, ‘amount’: 1.0, ‘cost’: 29.71753, delta: ‘price’: 29420.0, ‘amount’: 100.0, ‘cost’: 3.3990482664853e-06,

import asyncio
import ccxt.async_support as ccxt
excluded_exchange =[
    "bequant", #access denied
    "buda", #access denied
    "tidebit",
    "xena",
    "vcc"
]

async def check_trade_details(exchange_id: str):
    try:
        exchange = getattr(ccxt, exchange_id)({"defaultType": "swap"})
        trades = await exchange.fetch_trades('BTC/USDT:USDT')
        for trade in trades:
            if abs(trade["cost"] - trade["amount"] * trade["price"]) > 0.01:

                print("XXXXX",exchange_id, trade)
            else:
                print(exchange_id, "ok")
            break
    except Exception as err:
        # print(err)
        return
    finally:
        await exchange.close()

async def main():
    tasks = []
    for exchange_id in ccxt.exchanges:
        if exchange_id in excluded_exchange:
            continue
        tasks.append(asyncio.create_task(check_trade_details(exchange_id)))
    await asyncio.gather(*tasks)
if __name__ == "__main__":
    asyncio.run(main())
XXXXX kucoinfutures {'info': {'sequence': 75846815, 'side': 'buy', 'size': 40, 'price': '29453.0000000000', 'takerOrderId': '629a1ff9a9fbf8000181bbc2', 'makerOrderId': '629a1ff8aff5340001003f8c', 'tradeId': '629a1ff93c7feb35233555dc', 'ts': 1654267897744739373}, 'id': '629a1ff93c7feb35233555dc', 'order': None, 'timestamp': None, 'datetime': None, 'symbol': 'BTC/USDT:USDT', 'type': None, 'takerOrMaker': None, 'side': 'buy', 'price': 29453.0, 'amount': 40.0, 'cost': 1178.12, 'fee': None, 'fees': []}
bitmex ok
bybit ok
XXXXX okex5 {'info': {'instId': 'BTC-USDT-SWAP', 'side': 'sell', 'sz': '13', 'px': '29463.4', 'tradeId': '311889230', 'ts': '1654267931269'}, 'timestamp': 1654267931269, 'datetime': '2022-06-03T14:52:11.269Z', 'symbol': 'BTC/USDT:USDT', 'id': '311889230', 'order': None, 'type': None, 'takerOrMaker': None, 'side': 'sell', 'price': 29463.4, 'amount': 13.0, 'cost': 3830.242, 'fee': None, 'fees': []}
XXXXX okex {'info': {'instId': 'BTC-USDT-SWAP', 'side': 'sell', 'sz': '2', 'px': '29463.3', 'tradeId': '311889231', 'ts': '1654267931269'}, 'timestamp': 1654267931269, 'datetime': '2022-06-03T14:52:11.269Z', 'symbol': 'BTC/USDT:USDT', 'id': '311889231', 'order': None, 'type': None, 'takerOrMaker': None, 'side': 'sell', 'price': 29463.3, 'amount': 2.0, 'cost': 589.266, 'fee': None, 'fees': []}
XXXXX okx {'info': {'instId': 'BTC-USDT-SWAP', 'side': 'sell', 'sz': '2', 'px': '29463.3', 'tradeId': '311889231', 'ts': '1654267931269'}, 'timestamp': 1654267931269, 'datetime': '2022-06-03T14:52:11.269Z', 'symbol': 'BTC/USDT:USDT', 'id': '311889231', 'order': None, 'type': None, 'takerOrMaker': None, 'side': 'sell', 'price': 29463.3, 'amount': 2.0, 'cost': 589.266, 'fee': None, 'fees': []}
XXXXX aax {'info': {'i': 'T2X8tNEKCS', 'p': '29717.53000000', 'q': '1.000000', 's': 'long', 't': '1654259923220'}, 'id': 'T2X8tNEKCS', 'timestamp': 1654259923220, 'datetime': '2022-06-03T12:38:43.220Z', 'symbol': 'BTC/USDT:USDT', 'type': None, 'side': 'buy', 'order': None, 'takerOrMaker': None, 'price': 29717.53, 'amount': 1.0, 'cost': 29.71753, 'fee': None, 'fees': []}
XXXXX delta {'id': None, 'order': None, 'timestamp': 1654267759000, 'datetime': '2022-06-03T14:49:19.000Z', 'symbol': 'BTC/USDT:USDT', 'type': None, 'side': 'buy', 'price': 29420.0, 'amount': 100.0, 'cost': 3.3990482664853e-06, 'takerOrMaker': None, 'fee': None, 'info': {'buyer_role': 'taker', 'price': '29420', 'seller_role': 'maker', 'size': '100', 'symbol': 'BTCUSDT', 'timestamp': '1654267759000000'}, 'fees': []}
bitget ok
XXXXX huobipro {'id': '1089324468160000', 'info': {'amount': '2', 'direction': 'sell', 'id': '1089324468160000', 'price': '29365.4', 'quantity': '0.002', 'trade_turnover': '58.7308', 'ts': '1654267407438'}, 'order': None, 'timestamp': 1654267407438, 'datetime': '2022-06-03T14:43:27.438Z', 'symbol': 'BTC/USDT:USDT', 'type': None, 'side': 'sell', 'takerOrMaker': None, 'price': 29365.4, 'amount': 2.0, 'cost': 58.7308, 'fee': None, 'fees': []}
ascendex ok
XXXXX huobi {'id': '1089324468160000', 'info': {'amount': '2', 'direction': 'sell', 'id': '1089324468160000', 'price': '29365.4', 'quantity': '0.002', 'trade_turnover': '58.7308', 'ts': '1654267407438'}, 'order': None, 'timestamp': 1654267407438, 'datetime': '2022-06-03T14:43:27.438Z', 'symbol': 'BTC/USDT:USDT', 'type': None, 'side': 'sell', 'takerOrMaker': None, 'price': 29365.4, 'amount': 2.0, 'cost': 58.7308, 'fee': None, 'fees': []}
hitbtc3 ok
XXXXX mexc3 {'id': '1654267902537-BTC_USDT-1-48-29447-taker', 'order': None, 'timestamp': 1654267902537, 'datetime': '2022-06-03T14:51:42.537Z', 'symbol': 'BTC/USDT:USDT', 'type': None, 'side': '1', 'takerOrMaker': 'taker', 'price': 29447.0, 'amount': 48.0, 'cost': 141.3456, 'fee': None, 'info': {'p': '29447', 'v': '48', 'T': '1', 'O': '3', 'M': '1', 't': '1654267902537'}, 'fees': []}

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:11 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
kroitorcommented, Aug 15, 2022

@leastchaos the ts issue should be fixed in the most recent version of CCXT, please, let us know if you still have difficulties with it.

1reaction
leastchaoscommented, Jun 4, 2022

I see, thank you. I now see a mismatch on delta exchange

async def check_trade_details(exchange_id: str, symbol: str = 'BTC/USDT:USDT'):
    try:
        exchange: ccxt.Exchange = getattr(ccxt, exchange_id)()
        await exchange.load_markets()
        market = exchange.market(symbol)
        contract_size = market["contractSize"] if market["contract"] else 1
        print(exchange.id, contract_size)
        trades = await exchange.fetch_trades(symbol)
        for trade in trades:
            if abs(trade["cost"] - trade["amount"] * trade["price"] * contract_size) > 0.01:
                print("XXXXX",exchange_id, trade)
                break
        else:
            print(exchange_id, "ok")
    except Exception as err:
        # print(err)
        return
    finally:
        await exchange.close()

async def main():
    tasks = []
    for exchange_id in ccxt.exchanges:
        if exchange_id in excluded_exchange:
            continue
        tasks.append(asyncio.create_task(check_trade_details(exchange_id)))
    await asyncio.gather(*tasks)
if __name__ == "__main__":
    asyncio.run(main())

contractSize = 0.001 XXXXX delta {‘id’: None, ‘order’: None, ‘timestamp’: 1654323172000, ‘datetime’: ‘2022-06-04T06:12:52.000Z’, ‘symbol’: ‘BTC/USDT:USDT’, ‘type’: None, ‘side’: ‘buy’, ‘price’: 29695.5, ‘amount’: 26.0, ‘cost’: 8.75553535047386e-07, ‘takerOrMaker’: None, ‘fee’: None, ‘info’: {‘buyer_role’: ‘taker’, ‘price’: ‘29695.5’, ‘seller_role’: ‘maker’, ‘size’: ‘26’, ‘symbol’: ‘BTCUSDT’, ‘timestamp’: ‘1654323172000000’}, ‘fees’: []}

Read more comments on GitHub >

github_iconTop Results From Across the Web

Possible Trading Errors and how to resolve them
It means a deal is already open on the same Futures contract, and until that deal closes no new deal or position can...
Read more >
Global X Cybersecurity ETF Overview - BUG - MarketWatch
BUG | A complete Global X Cybersecurity ETF exchange traded fund overview by MarketWatch. View the latest ETF prices and news for better...
Read more >
BUG - Cybersecurity ETF - Global X ETFs
The Global X Cybersecurity ETF (BUG) seeks to provide investment results that correspond generally to the price and yield performance, before fees and...
Read more >
BUG Global X Cybersecurity ETF
Learn everything about Global X Cybersecurity ETF (BUG). ... This measurement shows how easy it is to trade a $1 million USD block...
Read more >
Penny Fitzgerald bug (won't trade) - Steam Community
I get this weird bug with Penny where she won't talk to me after Dan ... will work out a console command that...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found