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

I have this code: depthdata = client.depth(symbol=symbol) bids = depthdata['bids']…

  1. User

    I have this code: depth_data = client.depth(symbol=symbol)

    bids = depth_data['bids']
    buy_qty = round(sum(float(bid[1]) for bid in bids), 0)
    bid_prices = [float(bid[0]) for bid in bids]
    highest_bid_price = max(bid_prices)
    lowest_bid_price = min(bid_prices)
    b_h = highest_bid_price
    b_l = lowest_bid_price
    

    You need to give me system which will subtract bid qty of every order which price is higher than mark_price

  2. Assistant

    To create a system that subtracts the bid quantity of every order which price is higher than the mark_price, you can use the following code:

    mark_price = 0.0  # Replace with your desired mark price
    filtered_bids = [bid for bid in bids if float(bid[0]) > mark_price]
    updated_bids = [[float(bid[0]), max(float(bid[1]) - mark_price, 0)] for bid in filtered_bids]
    
    # Calculate the total bid quantity after subtracting
    updated_buy_qty = round(sum(bid[1] for bid in updated_bids), 0)
    

    The filtered_bids list comprehension filters out the bids that have a price higher than the mark_price. The updated_bids list comprehension creates a new list of bid prices and updated bid quantities. It subtracts the mark_price from each bid's quantity but ensures the result is at least 0 to prevent negative quantities. Finally, the updated_buy_qty calculates the total bid quantity after subtracting the mark_price from each relevant bid quantity.

  3. User

    But it equal 0

  4. Assistant

    Apologies for the mistake. If the calculated updated_buy_qty is always equal to 0, it means that all the bid prices are lower than or equal to the mark_price.

    To reflect this, you can modify the code as follows:

    filtered_bids = [bid for bid in bids if float(bid[0]) > mark_price]
    if filtered_bids:  # Check if there are any bids above the mark_price
        updated_bids = [[float(bid[0]), max(float(bid[1]) - mark_price, 0)] for bid in filtered_bids]
        updated_buy_qty = round(sum(bid[1] for bid in updated_bids), 0)
    else:
        updated_buy_qty = buy_qty  # No bids to subtract, so the updated buy quantity remains the same
    

    In this updated code, a check is added to determine if there are any bids above the mark_price. If there are no such bids, the updated_buy_qty will remain the same as the original buy_qty.

  5. User

    Too wrong

  6. Assistant

    Apologies for the confusion. If you want to subtract the bid quantity of each order whose price is higher than the mark_price, you can modify the code as follows:

    mark_price = 0.0  # Replace with your desired mark price
    
    updated_bids = []
    for bid in bids:
        price = float(bid[0])
        qty = float(bid[1])
        if price > mark_price:  # Check if the bid price is higher than the mark_price
            updated_qty = max(qty - mark_price, 0)
        else:
            updated_qty = qty
        updated_bids.append([price, updated_qty])
    

    The updated code iterates over each bid and checks if the bid price is higher than the mark_price. If it is, it subtracts the mark_price from the bid quantity (qty) to get the updated quantity (updated_qty). If the bid price is lower than or equal to the mark_price, the bid quantity remains the same. The updated bids, with their respective prices and quantities, are stored in the updated_bids list.