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

I have this code: def signalgenerator(df): if df is None or len(df) < 2: return ''…

  1. User

    I have this code:

    def signal_generator(df): if df is None or len(df) < 2: return ''

    signal = []
    final_signal = []
    exit = []
    sell_result = 0.0
    buy_result = 0.0
    active_signal = None
    
    mark_price_data = client.ticker_price(symbol=symbol)
    mp = float(mark_price_data['price']) if 'price' in mark_price_data else 0.0
    mark_price_data_change = client.ticker_24hr_price_change(symbol=symbol)
    mark_price_percent = float(mark_price_data_change['priceChangePercent']) if 'priceChangePercent' in mark_price_data_change else 0.0
    
    
    # Retrieve depth data
    depth_data = client.depth(symbol=symbol)
    
    bids = depth_data['bids']
    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
    buy_lowest_price = lowest_bid_price
    
    b_l = buy_lowest_price
    
    asks = depth_data['asks']
    ask_prices = [float(ask[0]) for ask in asks]
    highest_ask_price = max(ask_prices)
    lowest_ask_price = min(ask_prices)
    
    s_h = highest_ask_price
    s_l = lowest_ask_price
    
    buy_qty = round(sum(float(bid[1]) for bid in bids), 0)
    sell_qty = round(sum(float(ask[1]) for ask in asks), 0)
    

    Return this code, and give me code which will print me in [] order prices which higher than mark_price

  2. Assistant

    Here's the code that will print the prices higher than the mark_price in [] order:

    def signal_generator(df):
        if df is None or len(df) < 2:
            return ''
        
        signal = []
        final_signal = []
        exit = []
        sell_result = 0.0
        buy_result = 0.0
        active_signal = None
    
        mark_price_data = client.ticker_price(symbol=symbol)
        mark_price = float(mark_price_data['price']) if 'price' in mark_price_data else 0.0
        mark_price_data_change = client.ticker_24hr_price_change(symbol=symbol)
        mark_price_percent = float(mark_price_data_change['priceChangePercent']) if 'priceChangePercent' in mark_price_data_change else 0.0
    
        # Retrieve depth data
        depth_data = client.depth(symbol=symbol)
        
        bids = depth_data['bids']
        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
        buy_lowest_price = lowest_bid_price
    
        b_l = buy_lowest_price
    
        asks = depth_data['asks']
        ask_prices = [float(ask[0]) for ask in asks]
        higher_prices = [price for price in ask_prices if price > mark_price]
        higher_prices.sort()
        
        print(higher_prices)
        
        s_h = highest_ask_price
        s_l = lowest_ask_price
    
        buy_qty = round(sum(float(bid[1]) for bid in bids), 0)
        sell_qty = round(sum(float(ask[1]) for ask in asks), 0)
    

    In this code, I added a new line that creates a list called "higher_prices" which contains all the ask prices that are higher than the mark_price. Then, I sorted the list in ascending order and printed it.

  3. User

    Return this code, and give me code which will print me in [] order prices which higher than mark_price , this code need for bids

  4. Assistant

    Certainly! Here's the modified code that prints the prices higher than the mark_price in [] order for the bids:

    def signal_generator(df):
        if df is None or len(df) < 2:
            return ''
        
        signal = []
        final_signal = []
        exit = []
        sell_result = 0.0
        buy_result = 0.0
        active_signal = None
    
        mark_price_data = client.ticker_price(symbol=symbol)
        mark_price = float(mark_price_data['price']) if 'price' in mark_price_data else 0.0
        mark_price_data_change = client.ticker_24hr_price_change(symbol=symbol)
        mark_price_percent = float(mark_price_data_change['priceChangePercent']) if 'priceChangePercent' in mark_price_data_change else 0.0
    
        # Retrieve depth data
        depth_data = client.depth(symbol=symbol)
        
        bids = depth_data['bids']
        bid_prices = [float(bid[0]) for bid in bids]
        higher_prices = [price for price in bid_prices if price > mark_price]
        higher_prices.sort()
        
        print(higher_prices)
        
        highest_bid_price = max(bid_prices)
        lowest_bid_price = min(bid_prices)
        b_h = highest_bid_price
        buy_lowest_price = lowest_bid_price
    
        b_l = buy_lowest_price
    
        asks = depth_data['asks']
        ask_prices = [float(ask[0]) for ask in asks]
        s_h = highest_ask_price
        s_l = lowest_ask_price
    
        buy_qty = round(sum(float(bid[1]) for bid in bids), 0)
        sell_qty = round(sum(float(ask[1]) for ask in asks), 0)
    

    In this modified code, I added a new line that creates a list called "higher_prices" which contains all the bid prices that are higher than the mark_price. Then, I sorted the list in ascending order and printed it.

  5. User

    Okay, return it , give me code which will only give me only bid and ask prices

  6. Assistant

    Certainly! Here's the modified code that only retrieves and prints the bid and ask prices:

    def signal_generator(df):
        if df is None or len(df) < 2:
            return ''
        
        signal = []
        final_signal = []
        exit = []
        sell_result = 0.0
        buy_result = 0.0
        active_signal = None
    
        # Retrieve depth data
        depth_data = client.depth(symbol=symbol)
        
        bids = depth_data['bids']
        bid_prices = [float(bid[0]) for bid in bids]
        
        asks = depth_data['asks']
        ask_prices = [float(ask[0]) for ask in asks]
        
        print("Bid Prices:", bid_prices)
        print("Ask Prices:", ask_prices)
        
        highest_bid_price = max(bid_prices)
        lowest_bid_price = min(bid_prices)
        b_h = highest_bid_price
        buy_lowest_price = lowest_bid_price
    
        b_l = buy_lowest_price
        
        highest_ask_price = max(ask_prices)
        lowest_ask_price = min(ask_prices)
    
        s_h = highest_ask_price
        s_l = lowest_ask_price
    
        buy_qty = round(sum(float(bid[1]) for bid in bids), 0)
        sell_qty = round(sum(float(ask[1]) for ask in asks), 0)
    

    In this modified code, I removed the parts related to mark_price and mark_price_data since they were not used to print the desired bid and ask prices. Now, the code will only retrieve and print the bid and ask prices.

  7. User

    Okay, of those it need to analyze those prices and print me prices which higher than mark_price

  8. Assistant

    I apologize for the confusion. Here's the revised code to analyze the bid and ask prices and print the prices that are higher than the mark_price:

    def signal_generator(df):
        if df is None or len(df) < 2:
            return ''
        
        signal = []
        final_signal = []
        exit = []
        sell_result = 0.0
        buy_result = 0.0
        active_signal = None
    
        mark_price_data = client.ticker_price(symbol=symbol)
        mark_price = float(mark_price_data['price']) if 'price' in mark_price_data else 0.0
        mark_price_data_change = client.ticker_24hr_price_change(symbol=symbol)
        mark_price_percent = float(mark_price_data_change['priceChangePercent']) if 'priceChangePercent' in mark_price_data_change else 0.0
    
        # Retrieve depth data
        depth_data = client.depth(symbol=symbol)
        
        bids = depth_data['bids']
        bid_prices = [float(bid[0]) for bid in bids]
        higher_bid_prices = [price for price in bid_prices if price > mark_price]
        
        asks = depth_data['asks']
        ask_prices = [float(ask[0]) for ask in asks]
        higher_ask_prices = [price for price in ask_prices if price > mark_price]
        
        print("Higher Bid Prices:", higher_bid_prices)
        print("Higher Ask Prices:", higher_ask_prices)
        
        highest_bid_price = max(bid_prices)
        lowest_bid_price = min(bid_prices)
        b_h = highest_bid_price
        buy_lowest_price = lowest_bid_price
    
        b_l = buy_lowest_price
        
        highest_ask_price = max(ask_prices)
        lowest_ask_price = min(ask_prices)
    
        s_h = highest_ask_price
        s_l = lowest_ask_price
    
        buy_qty = round(sum(float(bid[1]) for bid in bids), 0)
        sell_qty = round(sum(float(ask[1]) for ask in asks), 0)
    

    In this revised code, I added two new variables higher_bid_prices and higher_ask_prices which contain the bid and ask prices that are higher than the mark_price, respectively. Then, I print these lists to display the prices that satisfy the condition.

  9. User

    And now leasten me , I need code which will count bid lowest prices which are not lower than market price + (mark_price / 100) and for ask I need code which will give em ask_highest prices which are not higher than market price - (mark_price / 100)

  10. Assistant

    Certainly! Here's the updated code that counts the number of bid lowest prices that are not lower than the market price plus (mark_price / 100), and also finds the ask highest prices that are not higher than the market price minus (mark_price / 100):

    def signal_generator(df):
        if df is None or len(df) < 2:
            return ''
        
        signal = []
        final_signal = []
        exit = []
        sell_result = 0.0
        buy_result = 0.0
        active_signal = None
    
        mark_price_data = client.ticker_price(symbol=symbol)
        mark_price = float(mark_price_data['price']) if 'price' in mark_price_data else 0.0
        mark_price_data_change = client.ticker_24hr_price_change(symbol=symbol)
        mark_price_percent = float(mark_price_data_change['priceChangePercent']) if 'priceChangePercent' in mark_price_data_change else 0.0
    
        # Retrieve depth data
        depth_data = client.depth(symbol=symbol)
        
        bids = depth_data['bids']
        bid_prices = [float(bid[0]) for bid in bids]
        bid_lowest_price = min(bid_prices)
        bid_lowest_filtered = [price for price in bid_prices if price >= (mark_price + (mark_price / 100))]
        bid_lowest_count = len(bid_lowest_filtered)
        print("Number of Bid lowest prices not lower than market price + (mark_price/100):", bid_lowest_count)
        
        asks = depth_data['asks']
        ask_prices = [float(ask[0]) for ask in asks]
        ask_highest_price = max(ask_prices)
        ask_highest_filtered = [price for price in ask_prices if price <= (mark_price - (mark_price / 100))]
        ask_highest_count = len(ask_highest_filtered)
        print("Number of Ask highest prices not higher than market price - (mark_price/100):", ask_highest_count)
        
        highest_bid_price = max(bid_prices)
        lowest_bid_price = min(bid_prices)
        b_h = highest_bid_price
        buy_lowest_price = lowest_bid_price
    
        b_l = buy_lowest_price
        
        highest_ask_price = max(ask_prices)
        lowest_ask_price = min(ask_prices)
    
        s_h = highest_ask_price
        s_l = lowest_ask_price
    
        buy_qty = round(sum(float(bid[1]) for bid in bids), 0)
        sell_qty = round(sum(float(ask[1]) for ask in asks), 0)
    

    In this updated code, I added two new sections to count the bid lowest prices that are not lower than the market price plus (mark_price / 100) and find the ask highest prices that are not higher than the market price minus (mark_price / 100).

    I created bid_lowest_filtered which is a list of bid prices that satisfy the condition, and then I used the len() function to get the count of those prices. Similarly, I created ask_highest_filtered to hold the ask prices that satisfy the condition and counted them using len().

    Finally, I printed the counts of the bid lowest and ask highest prices that meet the criteria.

  11. User

    Time to time it giving me it : Higher Ask Prices: [228.86, 228.87, 228.88, 228.89] , write the code which will check those prices are they highers or no ?

  12. Assistant

    Certainly! Here's the code that checks whether the higher ask prices are actually higher or not:

    def signal_generator(df):
        if df is None or len(df) < 2:
            return ''
        
        signal = []
        final_signal = []
        exit = []
        sell_result = 0.0
        buy_result = 0.0
        active_signal = None
    
        mark_price_data = client.ticker_price(symbol=symbol)
        mark_price = float(mark_price_data['price']) if 'price' in mark_price_data else 0.0
        mark_price_data_change = client.ticker_24hr_price_change(symbol=symbol)
        mark_price_percent = float(mark_price_data_change['priceChangePercent']) if 'priceChangePercent' in mark_price_data_change else 0.0
    
        # Retrieve depth data
        depth_data = client.depth(symbol=symbol)
        
        asks = depth_data['asks']
        ask_prices = [float(ask[0]) for ask in asks]
        
        higher_ask_prices = [price for price in ask_prices if price > mark_price]
        
        print("Higher Ask Prices:", higher_ask_prices)
        
        for ask_price in higher_ask_prices:
            if ask_price > mark_price:
                print(f"{ask_price} is higher than mark_price.")
            else:
                print(f"{ask_price} is not higher than mark_price.")
        
        highest_bid_price = max(bid_prices)
        lowest_bid_price = min(bid_prices)
        b_h = highest_bid_price
        buy_lowest_price = lowest_bid_price
    
        b_l = buy_lowest_price
        
        highest_ask_price = max(ask_prices)
        lowest_ask_price = min(ask_prices)
    
        s_h = highest_ask_price
        s_l = lowest_ask_price
    
        buy_qty = round(sum(float(bid[1]) for bid in bids), 0)
        sell_qty = round(sum(float(ask[1]) for ask in asks), 0)
    

    In this code, I added a loop that iterates through each higher ask price. Inside the loop, it checks whether each ask price is higher than the mark_price or not. If the ask price is higher, it prints that it is higher than the mark_price. Otherwise, it prints that it is not higher than the mark_price.

    This way, the code will validate whether each ask price in the higher_ask_prices list is actually higher than the mark_price.

  13. User

    I sued this code: #Main Signal if (((buy_qty > th) > (sell_qty < th)) and (b_l > mp + pth)): signal.append('buy') elif (((sell_qty > th) > (buy_qty < th)) and (s_h < mp - pth)): signal.append('sell') else: signal.append('')

    #Signal confirmation
    if signal == ['buy'] and not (((br < th) < sell_qty) and (b_l < mp + pth)):
        final_signal.append('buy')
    elif signal == ['sell'] and not (((sr < th) < buy_qty) and (s_h > mp - pth)):
        final_signal.append('sell')
    else:
        final_signal.append('')
    
    #Exit
    if final_signal == ['buy'] and (((br < th) < sell_qty) and (b_h < mp + pth)):
        exit.append('buy_exit')
    elif final_signal == ['sell'] and (((sr < th) < buy_qty) and (s_l > mp - pth)):
        exit.append('sell_exit')
    else:
        exit.append('')
    

    But I getting ERROR: Traceback (most recent call last): File "c:\Users\Alan.vscode\jew_bot\jew_bot\jew_bot.py", line 225, in
    signals = signal_generator(df) ^^^^^^^^^^^^^^^^^^^^ File "c:\Users\Alan.vscode\jew_bot\jew_bot\jew_bot.py", line 170, in signal_generator elif final_signal == ['sell'] and (((sr < th) < buy_qty) and (s_l > mp - pth)):
    ^^^^^^^^^^^^^^
    TypeError: '>' not supported between instances of 'list' and 'float'

  14. Assistant

    The error message suggests that there is a comparison issue between a list and a float. Looking at the code you provided, the problem appears to be with the variable sr.

    In the line elif final_signal == ['sell'] and (((sr < th) < buy_qty) and (s_l > mp - pth)): you are comparing (sr < th) with buy_qty, which might be causing the error.

    To resolve this issue, make sure that sr is a float value and th is also a float or a compatible type for comparison.

    You can update the code like this:

    sr = <assign sr value as float or compatible type>
    
    # Main Signal
    if (((buy_qty > th) > (sell_qty < th)) and (b_l > mp + pth)):
        signal.append('buy')
    elif (((sell_qty > th) > (buy_qty < th)) and (s_h < mp - pth)):
        signal.append('sell')
    else:
        signal.append('')
    
    # Signal confirmation
    if signal == ['buy'] and not (((br < th) < float(sell_qty)) and (b_l < mp + pth)):
        final_signal.append('buy')
    elif signal == ['sell'] and not (((float(sr
    

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.