sammchardy / python-binance

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

how to create 2 future orders at the same time? #1019

Open bmw7 opened 2 years ago

bmw7 commented 2 years ago

At the very same time, create two future orders, one for LONG, and the other for SHORT. I mean, the long and short order prices are the same. That is what I want.

If you run the code like this: order1 = client.futures_create_order(symbol='ETHUSDT',side='SELL',type='MARKET',quantity=20) order2 = client.futures_create_order(symbol='ETHUSDT',side='BUY',type='MARKET',quantity=20)

You'll find that the runtime is about 1 second! and the two orders' prices are very different! Because the runtime difference between the two lines of code is too long.

SO ,HOW to create 2 future orders at the same time?

luk0y commented 2 years ago

You can put sl/tp in the same request. Check this for information https://binance-docs.github.io/apidocs/futures/en/#new-order-trade

bmw7 commented 2 years ago

You can put sl/tp in the same request. Check this for information https://binance-docs.github.io/apidocs/futures/en/#new-order-trade

thanks! But I cannot find anything about sl/tp in the url you offered. What am I supposed to do? Could you help me with an application example, please?

luk0y commented 2 years ago

SL - Stop loss TP - Take profit

check the "stopPrice" parameter

sinaFa commented 2 years ago

You can launch two different threads. That way it will not wait for the first command to finish to launch the second. Check out Process from multiprocessing library.

bmw7 commented 2 years ago

You can launch two different threads. That way it will not wait for the first command to finish to launch the second. Check out Process from multiprocessing library.

thanks! your answer is the solution !!! Could you kindly help me with this problem : https://github.com/sammchardy/python-binance/issues/1021

luk0y commented 2 years ago

Multithreading is okay if there is no relation between first and second order , but , if you want to keep the second order to close the existing position then no use of threading