I used this code: while True: lookback = 10080 df = getklines(symbol, interval,…
- User
I used this code: while True: lookback = 10080 df = get_klines(symbol, interval, lookback)
if df is not None: signals = signal_generator(df) mark_price_data = client.ticker_price(symbol=symbol) mark_price = float(mark_price_data['price']) if 'price' in mark_price_data else 0.0 print(f"The signal time is: {dt.datetime.now().strftime('%Y-%m-%d %H:%M:%S')} Price: [{mark_price}] - Signals: {signals}") if signals == ['buy']: try: account_info = client.account() token_price = mark_price margin = 50 quantity = usdt_balance * margin / token_price order = client.new_order(symbol=symbol, side='BUY', type='MARKET', quantity=quantity) print("Long order executed!") except BinanceAPIException as e: print("Error executing long order:") time.sleep(1) if signals == ['sell']: try: account_info = client.account() token_price = mark_price margin = 50 quantity = usdt_balance * margin / token_price order = client.new_order(symbol=symbol, side='SELL', type='MARKET', quantity=quantity) print("Short order executed!") except BinanceAPIException as e: print("Error executing short order:") time.sleep(1) time.sleep(1)But I getting ERROR: The signal time is: 2023-08-22 17:43:14 Price: [185.21] - Signals: ['sell'] Traceback (most recent call last): File "c:\Users\Alan.vscode\jew_bot\jew_bot\jew_bot.py", line 204, in quantity = usdt_balance * margin / token_price ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~ TypeError: unsupported operand type(s) for /: 'str' and 'float'
- Assistant
This error occurs because the variable
usdt_balanceis of type string ('str') and the variabletoken_priceis of type float. You cannot perform mathematical operations between operands of different types.To fix this issue, you need to convert the
usdt_balancevariable to a float before performing the division operation. You can use thefloat()function to convert the string to a float. Here's the modified code:if signals == ['buy']: try: account_info = client.account() token_price = mark_price margin = 50 quantity = float(usdt_balance) * margin / token_price order = client.new_order(symbol=symbol, side='BUY', type='MARKET', quantity=quantity) print("Long order executed!") except BinanceAPIException as e: print("Error executing long order:") time.sleep(1) if signals == ['sell']: try: account_info = client.account() token_price = mark_price margin = 50 quantity = float(usdt_balance) * margin / token_price order = client.new_order(symbol=symbol, side='SELL', type='MARKET', quantity=quantity) print("Short order executed!") except BinanceAPIException as e: print("Error executing short order:") time.sleep(1) - User
But I getting ERROR: The signal time is: 2023-08-22 17:46:06 Price: [185.33] - Signals: ['buy'] Traceback (most recent call last): File "c:\Users\Alan.vscode\jew_bot\jew_bot\jew_bot.py", line 190, in order = client.new_order(symbol=symbol, side='BUY', type='MARKET', quantity=quantity)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Alan\AppData\Roaming\Python\Python311\site-packages\binance\um_futures\account.py", line 113, in new_order ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Alan\AppData\Roaming\Python\Python311\site-packages\binance\api.py", line 83, in sign_request return self.send_request(http_method, url_path, payload, special) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Alan\AppData\Roaming\Python\Python311\site-packages\binance\api.py", line 118, in send_request self._handle_exception(response) File "C:\Users\Alan\AppData\Roaming\Python\Python311\site-packages\binance\api.py", line 172, in _handle_exception raise ClientError(status_code, err["code"], err["msg"], response.headers) binance.error.ClientError: (400, -1111, 'Precision is over the maximum defined for this asset.', {'Date': 'Tue, 22 Aug 2023 14:46:07 GMT', 'Content-Type': 'application/json', 'Content-Length': '76', 'Connection': 'keep-alive', 'Server': 'Tengine', 'x-mbx-used-weight-1m': '-1', 'x-mbx-order-count-10s': '1', 'x-mbx-order-count-1m': '1', 'x-response-time': '1ms', 'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS'}) - Assistant
The new error "Precision is over the maximum defined for this asset" suggests that the quantity value you are trying to pass to the
new_orderfunction exceeds the allowed decimal places for the trading asset.To fix this issue, you need to determine the correct precision value for the trading asset and apply it to the
quantityvariable. You can use theget_symbol_infofunction to retrieve the trading asset's precision information. Here's the modified code: - User
Remove symbol_info
- Assistant
If you remove the
symbol_infovariable, you won't be able to retrieve the symbol's precision information. However, you can manually set the precision value for the symbol based on its decimal places. Here's the modified code without usingsymbol_info:if signals == ['buy']: try: account_info = client.account() token_price = mark_price margin = 50 quantity_precision = 8 # Change this value with the correct precision for your trading symbol quantity = float(usdt_balance) * margin / token_price quantity = round(quantity, quantity_precision) order = client.new_order(symbol=symbol, side='BUY', type='MARKET', quantity=quantity) print("Long order executed!") except BinanceAPIException as e: print("Error executing long order:") time.sleep(1) if signals == ['sell']: try: account_info = client.account() token_price = mark_price margin = 50 quantity_precision = 8 # Change this value with the correct precision for your trading symbol quantity = float(usdt_balance) * margin / token_price quantity = round(quantity, quantity_precision) order = client.new_order(symbol=symbol, side='SELL', type='MARKET', quantity=quantity) print("Short order executed!") except BinanceAPIException as e: print("Error executing short order:") time.sleep(1)
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.