Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0613· openaiHugging Face Suzhen/CodeChat

I saw in binance documentation that for cancelorder I need symbol orderId and…

  1. User

    I saw in binance documentation that for cancel_order I need symbol orderId and origClientOrderId , but get_acount_trades returing me only this: {'symbol': 'BCHUSDT', 'id': 619785813, 'orderId': 24398443258, 'side': 'SELL', 'price': '224.81', 'qty': '0.043', 'realizedPnl': '0.04429000', 'marginAsset': 'USDT', 'quoteQty': '9.66683', 'commission': '0.00483341', 'commissionAsset': 'USDT', 'time': 1700591831789, 'positionSide': 'BOTH', 'buyer': False, 'maker': False}

    What is here origClientOrderId ?

  2. Assistant

    In the response you provided, there is no origClientOrderId field. The origClientOrderId refers to the original client-assigned order ID when the order was created. It is not included in the response you mentioned. You might need to check the documentation or contact the Binance support team for further assistance in obtaining the origClientOrderId.

  3. User

    Okay, where I can get it ?

  4. Assistant

    To obtain the origClientOrderId, you need to check the response received when the order was originally created. When you create an order using the Binance API, you will receive a response that includes the origClientOrderId field. By saving or recording that response, you can retrieve the origClientOrderId for later use, such as for canceling the order.

    If you don't have access to the original response or if it was not stored, you may need to contact the Binance support team for assistance in retrieving the origClientOrderId for a specific order.

  5. User

    How I can get this response ?

  6. Assistant

    When you place an order using the Binance API, you will receive a response containing various details about the order, including the origClientOrderId. The exact method of obtaining this response depends on the programming language or API implementation you are using.

    Here is a general example in Python using the Binance Python API library:

    from binance.client import Client
    
    # Initialize the Binance client
    client = Client(api_key, api_secret)
    
    # Place an order
    order = client.create_order(
        symbol='BCHUSDT',
        side='SELL',
        type='LIMIT',
        timeInForce='GTC',
        quantity=0.043,
        price='224.81'
    )
    
    # Print the response
    print(order)
    

    After executing this code, the response will be printed in the console, and it will contain the origClientOrderId field along with other information about the order.

    Make sure to replace api_key and api_secret with your actual Binance API credentials.

  7. User

    I used this code: if 'buy' in signals and active_signal != 'buy': try: active_signal = 'buy' buy_entry_price = mark_price # Record the Buy entry price print(f"Buy Entry Price: {buy_entry_price}") order = client.new_order(symbol=symbol, side='BUY', type='MARKET', quantity=quantity) client.new_order(symbol=symbol, side='BUY', type='MARKET', quantity=quantity) print(f"Long order executed!{order}") except binance.error.ClientError as e: print(f"Error executing long order: ")

    But it returned me: The signal time is: 2023-11-21 22:12:42, Price 224.62 - Signals: ['buy'] Buy Entry Price: 224.62 Error executing long order: Sell Entry price or Buy Entry price is not defined.

  8. Assistant

    The error message you received indicates that the long order execution failed, and it mentions that the 'Sell Entry Price' or 'Buy Entry Price' is not defined. This issue seems to be related to the variables sell_entry_price and buy_entry_price.

    From the code you shared, it appears that you are trying to execute a market buy order based on a signal. However, you haven't defined the sell_entry_price and buy_entry_price variables before calling the client.new_order() function. This error might occur if these variables are not assigned any values.

    To resolve this issue, make sure you have assigned values to sell_entry_price and buy_entry_price before executing the order. You can review your code and ensure that these variables are assigned appropriate values based on your trading strategy or the logic you are using. Once you define and assign values to these variables, you should be able to execute the order successfully.

  9. User

    I doesn't tolking about them , it didn't return me order resopnse

  10. Assistant

    Apologies for the confusion. To capture the order response, you can try assigning the result of client.new_order() to a variable. Here's an updated version of your code snippet:

    if 'buy' in signals and active_signal != 'buy':
        try:
            active_signal = 'buy'
            buy_entry_price = mark_price  # Record the Buy entry price
            print(f"Buy Entry Price: {buy_entry_price}")
            order = client.new_order(symbol=symbol, side='BUY', type='MARKET', quantity=quantity)
            print(f"Long order executed! {order}")
        except binance.error.ClientError as e:
            print(f"Error executing long order: {e}")
    

    In this code, the variable order is assigned the result of client.new_order(). You can then print or utilize this order response as needed.

    Remember to handle any exceptions that may arise during the order execution and error handling appropriately.

    If you're still experiencing issues, please provide more details, such as the exact error message you're receiving, for further assistance.