[Python] Error in using fetch_balance in Lib ccxt in python

Discussão em 'Python' iniciado por Stack, Fevereiro 6, 2025.

  1. Stack

    Stack Membro Participativo

    Good Day

    i try to connect to coinex exchange with below code:

    import asyncio

    import os
    from random import randint
    import sys
    from pprint import pprint

    root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
    sys.path.append(root + '/python')

    import ccxt.async_support as ccxt # noqa: E402



    print('CCXT Version:', ccxt.__version__)

    exchange = ccxt.coinex({
    'apiKey': '<REDACTED>',
    'secret': '<REDACTED>',
    })
    if sys.platform == 'win32':
    asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())


    # Example 1 :: Swap : fetch balance, create a limit swap order with leverage
    async def example_1():
    exchange.options['defaultType'] = 'swap'
    exchange.options['defaultMarginMode'] = 'cross' # or isolated


    markets = await exchange.load_markets()

    # fetch swap balance

    balance = await exchange.fetch_balance()
    print(balance)

    # set the desired leverage (has to be made before placing the order and for a specific symbol)
    leverage = 8
    symbol = 'ADA/USDT:USDT'
    leverage_response = await exchange.set_leverage(leverage, symbol)

    # create limit order
    symbol = 'ADA/USDT:USDT'
    type = 'limit'
    side = 'buy'
    amount = 50
    price = 0.3
    create_order = await exchange.create_order(symbol, type, side, amount, price)
    print('Create order id:', create_order['id'])



    async def main():
    await example_1()


    asyncio.run(main())



    when i run that code, i get a below error in fetch_balance() function :

    coinex Tonce check error, correct tonce should be within one minute of the current time

    i search in all of network but i can not find any solotion about that

    Continue reading...

Compartilhe esta Página