sammchardy / python-binance

Binance Exchange API python implementation for automated trading
https://python-binance.readthedocs.io/en/latest/
MIT License
6.01k stars 2.2k forks source link

Add - futures_modify_order function #1419

Closed danywayGit closed 1 month ago

danywayGit commented 3 months ago

Simple but missing function, to be able to modify an existing order. For example it is usefull for modifing the quantity, or the price of an open order.

Using the same url (order) as for creating a new order but with a PUT method instead of a POST method.

danywayGit commented 3 months ago

I have testing the function, like this:

def modify_take_profit_order_oneway_mode(symbol: str, orderId: int, side: str, quantity: float, price: float)-> dict: price = round(float(price),get_price_precision_futures(symbol)) price = round_step_size(float(price), get_tick_size_futures(symbol)) try: order = client.futures_modify_order( symbol=symbol, orderId=orderId, side=side, quantity=quantity, price=price, timeInForce='GTC' ) return order except Exception as e: log_to_file("ERROR modify_take_profit_order_oneway_mode : " + type(e).name, symbol) log_to_file("ERROR modify_take_profit_order_oneway_mode : " + str(e), symbol)

Example : Modify an existing Take Profit Order, for a Long(BUY) Position in One Way Mode

print(modify_take_profit_order_oneway_mode(symbol="HIGHUSDT", side="BUY", orderId=2397071111, quantity=20, price=2.844300))

sammchardy commented 1 month ago

Thanks @danywayGit