donewiththedollar / directionalscalper

CCXT based algorithmic trading framework for Bybit and other CCXT supported exchanges

Home Page:https://quantumvoid.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Binance problem TP order

ariezz opened this issue · comments

commented

self.exchange.create_normal_take_profit_order_binance(symbol, order_side, pos_qty, take_profit_price, take_profit_price):

existing_tps = {list: 0} []
new_order_id = {str} 'tp_L_044515b72d'
open_orders = {list: 0} []
order_side = {str} 'SELL'
pos_qty = {float} 67.0
position_side = {str} 'LONG'
self = {BinanceAutoHedgeStrategy} <directionalscalper.core.strategies.binance.binance_auto_hedge.BinanceAutoHedgeStrategy object at 0x000001FB184AFFD0>
checked_amount_validity_binance = {bool} False
config = {Bot} Bot(bot_name='Antares_bot', min_distance=0.15, min_distance_largecap=0.085, min_volume=15000, min_qty_threshold=0.0, symbol='D...ALGOUSDT', 'SANDUSDT', 'MANAUSDT', 'FTMUSDT', 'CTSIUSDT', 'COMPUSDT', 'STMXUSDT', 'APEUSDT'], blacklist=['BTCUSDT', 'ETHUSDT'])
current_wallet_exposure = {float} 1.0
exchange = {Exchange} <directionalscalper.core.exchange.Exchange object at 0x000001FB1627A810>
initial_max_long_trade_qty = {float} 977.0
initial_max_short_trade_qty = {float} 977.0
last_cancel_time = {int} 0
last_mfirsi_signal = {NoneType} None
long_expected_profit_usdt = {float} 0.01797810999999981
long_leverage_increased = {bool} False
long_pos_leverage = {float} 1.0
long_tp_distance_percent = {float} 0.3548869197196101
manager = {Manager} <api.manager.Manager object at 0x000001FB16C7E010>
max_long_trade_qty = {float} 977.0
max_short_trade_qty = {float} 977.0
printed_trade_quantities = {bool} True
short_expected_profit_usdt = {float} 0.0
short_leverage_increased = {bool} False
short_pos_leverage = {float} 1.0
short_tp_distance_percent = {float} 0.0
symbol = {str} 'DOGE/USDT:USDT'
taker_fee_rate = {float} 0.00055
version = {str} '2.0.6'
symbol = {str} 'DOGEUSDT'
take_profit_price = {float} 0.07587833

Traceback (most recent call last):
File "D:\Python project\directionalscalper-main\directionalscalper\venv\Lib\site-packages\ccxt\base\exchange.py", line 600, in fetch
response.raise_for_status()
File "D:\Python project\directionalscalper-main\directionalscalper\venv\Lib\site-packages\requests\models.py", line 1021, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://fapi.binance.com/fapi/v1/order

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "D:\Python project\directionalscalper-main\directionalscalper\directionalscalper\core\strategies\strategy.py", line 1579, in binance_hedge_placetp_maker
self.exchange.create_normal_take_profit_order_binance(symbol, order_side, pos_qty, take_profit_price, take_profit_price)#, {'newClientOrderId': new_order_id, 'reduceOnly': True})
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Python project\directionalscalper-main\directionalscalper\directionalscalper\core\exchange.py", line 2322, in create_normal_take_profit_order_binance
return self.exchange.create_order(symbol, 'limit', side, quantity, price, params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Python project\directionalscalper-main\directionalscalper\venv\Lib\site-packages\ccxt\binance.py", line 4095, in create_order
response = getattr(self, method)(request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Python project\directionalscalper-main\directionalscalper\venv\Lib\site-packages\ccxt\base\types.py", line 26, in unbound_method
return _self.request(self.path, self.api, self.method, params, config=self.config)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Python project\directionalscalper-main\directionalscalper\venv\Lib\site-packages\ccxt\binance.py", line 7489, in request
response = self.fetch2(path, api, method, params, headers, body, config)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Python project\directionalscalper-main\directionalscalper\venv\Lib\site-packages\ccxt\base\exchange.py", line 2986, in fetch2
return self.fetch(request['url'], request['method'], request['headers'], request['body'])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Python project\directionalscalper-main\directionalscalper\venv\Lib\site-packages\ccxt\base\exchange.py", line 616, in fetch
skip_further_error_handling = self.handle_errors(http_status_code, http_status_text, url, method, headers, http_response, json_response, request_headers, request_body)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Python project\directionalscalper-main\directionalscalper\venv\Lib\site-packages\ccxt\binance.py", line 7467, in handle_errors
raise ExchangeError(feedback)
ccxt.base.errors.ExchangeError: binance {"code":-4061,"msg":"Order's position side does not match user's setting."}

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "D:\Python project\directionalscalper-main\directionalscalper\bot.py", line 260, in
strategy.run(symbol)
File "D:\Python project\directionalscalper-main\directionalscalper\directionalscalper\core\strategies\binance\binance_auto_hedge.py", line 389, in run
self.binance_hedge_placetp_maker(symbol, long_pos_qty, long_take_profit, "LONG", open_orders)
File "D:\Python project\directionalscalper-main\directionalscalper\directionalscalper\core\strategies\strategy.py", line 1585, in binance_hedge_placetp_maker
raise Exception(f"Error in placing {position_side} TP: {e}") from e
Exception: Error in placing LONG TP: binance {"code":-4061,"msg":"Order's position side does not match user's setting."}

Hmmm if this is not related to CCXT version, then it could be your position mode is not changing properly. I will look into this today😊

For what it's worth, on the main branch using this:

python3.11 bot.py --exchange binance --symbol DOGEUSDT --strategy binance_auto_hedge_maker --config config_binance_main.json

Works just fine for me, has been profitable. However, I'd like to make the take profit orders post only but it seems Binance has limitations for that.

Will definitely look into this bug today though. It could possibly have to do with the strategy, as I am using binance_auto_hedge_maker strategy at the moment and it is working smoothly.