------------------------------------------------------------------------------------------------------------------
https://accounts.binance.com/register?ref=21391362 <- Get Discount on Binance Futures Fees With Referral Code
Referral Code : 21391362
------------------------------------------------------------------------------------------------------------------
1. RSI
Let's program automatic trading using RSI. Usually, the RSI is oversold when it is below 30 and overbought when it is above 70. Therefore, take a long position when the RSI reading is below 30 and a short position when the RSI reading is above 70.
2. logic
Waiting for buy order acceptance -> Accepting buy order when RSI is below 30 -> Waiting for buy order execution -> Completed buy order execution ->
Waiting for sell order acceptance -> Accepting sell order when RSI is above 70 -> Waiting for execution of sell order -> Complete execution of sell order -> Repeat
3. condition
The order status value lets you know whether an order has been filled or canceled. By using this, we prevent duplicate orders from being received and wait until the contract is completed. There are a total of 4 types: Receipt, Cancellation, Expiration date, and Placement of order, and a loop is applied using the 4 condition values.
ORDER_STATUS_NEW | Receiving new orders |
ORDER_STATUS_CANCELED ORDER_STATUS_EXPIRED |
withdraw order |
ORDER_STATUS_FILLED | order execution |
If the RSI is below 30 and there is no order in the order book, take the current price and place a buy order. For a buy order to be received at the limit price, it must be higher than the current price, so let's give it +1. The important point at this time is that unless you place an order at the market price, the buy order is not immediately executed, so you have to wait until the execution is completed.

While waiting for the purchase transaction to be completed, let's continuously check the order status value using the order id to prevent duplicate orders from entering, and check if the order has been executed or cancelled.
If order id is initialized due to program restart or other reasons, order information can be retrieved from the current order book using the get_open_orders method. Alternatively, you can prevent duplicate orders by checking the coin quantity.

If the ORDER_STATUS_FILLED status value comes out, the buy has been executed. Let's move on to the selling logic. The sell logic is the same as the buy logic.
If the RSI is above 70 and there is no order in the order book, take the current price and place a sell order. In order for a sell order to be received at the limit price, it must be higher than the current price, so let's give it +1. Automated trading requires a stop-loss in preparation for a sharp drop, so OCO trading sets both the profit-loss and stop-loss at the same time.
https://bitcoin-chart.tistory.com/17
As with the buy order, unless you place an order at the market price, the sell order is not immediately executed, so you have to wait until the order is completed.

Sell also has the same status value as Buy. Just check the order status value and wait. Once the sell is concluded, you can move on to the buy logic again.

------------------------------------------------------------------------------------------------------------------
https://accounts.binance.com/register?ref=21391362 <- Get Discount on Binance Futures Fees With Referral Code
Referral Code : 21391362
------------------------------------------------------------------------------------------------------------------