I used this code: markpricedata = client.tickerprice(symbol=symbol) mp =…
- User
I used this code: 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 b_l = lowest_bid_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_priceYou need to give me code which will print me buy_lowest_price which not lower than mark_price + (mark_price / 100) and highest_sell_price which not higher than mark_price - (mark_price / 100)
- Assistant
Here is the code that will print the buy_lowest_price and highest_sell_price based on your conditions:
buy_lowest_price = 0 highest_sell_price = 0 if b_l >= mp + (mp / 100): buy_lowest_price = b_l if s_h <= mp - (mp / 100): highest_sell_price = s_h print("Buy Lowest Price:", buy_lowest_price) print("Highest Sell Price:", highest_sell_price)In this code, we check if the lowest bid price (b_l) is greater than or equal to the mark price (mp) plus 1% of the mark price. If it satisfies this condition, we set the buy_lowest_price variable to b_l.
Similarly, we check if the highest ask price (s_h) is less than or equal to the mark price (mp) minus 1% of the mark price. If it satisfies this condition, we set the highest_sell_price variable to s_h.
Finally, we print the values of buy_lowest_price and highest_sell_price.
- User
Wait , but it wrong code
- Assistant
Apologies for the incorrect code. Here is the corrected code:
buy_lowest_price = 0 highest_sell_price = 0 if b_l >= mp + (mp / 100): buy_lowest_price = b_l else: buy_lowest_price = mp + (mp / 100) if s_h <= mp - (mp / 100): highest_sell_price = s_h else: highest_sell_price = mp - (mp / 100) print("Buy Lowest Price:", buy_lowest_price) print("Highest Sell Price:", highest_sell_price)In this code, we first check if the lowest bid price (b_l) is greater than or equal to the mark price (mp) plus 1% of the mark price. If it satisfies this condition, we set the buy_lowest_price variable to b_l. Otherwise, we set it to the mark price plus 1% of the mark price.
Similarly, we check if the highest ask price (s_h) is less than or equal to the mark price (mp) minus 1% of the mark price. If it satisfies this condition, we set the highest_sell_price variable to s_h. Otherwise, we set it to the mark price minus 1% of the mark price.
Finally, we print the values of buy_lowest_price and highest_sell_price.
- User
But it too wrong
- Assistant
Apologies for the confusion. Here is the revised code that should give you the correct buy_lowest_price and highest_sell_price based on your requirements:
buy_lowest_price = 0 highest_sell_price = 0 if b_l > mp + (mp / 100): buy_lowest_price = b_l if s_h < mp - (mp / 100): highest_sell_price = s_h if buy_lowest_price == 0: buy_lowest_price = mp + (mp / 100) if highest_sell_price == 0: highest_sell_price = mp - (mp / 100) print("Buy Lowest Price:", buy_lowest_price) print("Highest Sell Price:", highest_sell_price)In this code, we first check if the lowest bid price (b_l) is strictly greater than the mark price (mp) plus 1% of the mark price. If it satisfies this condition, we set the buy_lowest_price variable to b_l.
Similarly, we check if the highest ask price (s_h) is strictly less than the mark price (mp) minus 1% of the mark price. If it satisfies this condition, we set the highest_sell_price variable to s_h.
If buy_lowest_price is not updated (remains as 0), we set it to the mark price plus 1% of the mark price.
If highest_sell_price is not updated (remains as 0), we set it to the mark price minus 1% of the mark price.
Finally, we print the values of buy_lowest_price and highest_sell_price.
- User
No it need to count lowest bid price which will not lower than mark_price + (mark_price / 100)
- Assistant
Apologies for the confusion. Here is the revised code that should correctly compute the buy_lowest_price based on your requirement:
buy_lowest_price = 0 for bid_price in bid_prices: if bid_price >= mp + (mp / 100): buy_lowest_price = bid_price break if buy_lowest_price == 0: buy_lowest_price = mp + (mp / 100) print("Buy Lowest Price:", buy_lowest_price)In this code, we iterate over each bid price in the list of bid_prices. We check if the bid_price is greater than or equal to the mark price (mp) plus 1% of the mark price. If such a bid price is found, we set the buy_lowest_price variable to that bid price and exit the loop using the
breakstatement.If no bid price satisfies the condition and buy_lowest_price remains as 0, we set it to the mark price plus 1% of the mark price.
Finally, we print the value of buy_lowest_price.