I solved the ordering problem with everyone's help in the third question, but when I tested the historical data today, I discovered a strange thing. I want to operate on 6 currency pairs (GBP_USD, EUR_USD, USD_CAD and USD_CHF, USD_JPY, AUD_USD). I want GBP_USD, EUR_USD, USD_CAD to buy when placing a buy order, and USD_CHF, USD_JPY, and AUD_USD to sell when placing a buy order. Start a few transactions. There is no problem, but after trying to sell when placing a buy order once, GBP_USD, EUR_USD, USD_CAD also changed to selling when placing a buy order. The procedure is as follows:
import requests def trade(action,pairs,unit="1"): account_id = '101-011-5898545-001' access_token = '33c7d4049fe8720c37918482bc830c12-06467701c963e60220d7e18436f3225d' url = 'https://api-fxpractice.oanda.com/v3/accounts/'+account_id+'/orders' headers = {'Content-Type' : 'application/json','Authorization':'Bearer '+access_token} if pairs == "GBP_USD" or "EUR_USD" or "AUD_USD" : if action == "buy" : data = {"order":{"instrument":pairs,"type":"MARKET","units":unit}} if action == "sell" : data = {"order":{"instrument":pairs,"type":"MARKET","units":"-"+unit}} if pairs == "USD_CHF" or "USD_JPY" or "USD_CAD" : if action == "buy" : data = {"order":{"instrument":pairs,"type":"MARKET","units":"-"+unit}} if action == "sell" : data = {"order":{"instrument":pairs,"type":"MARKET","units":unit}} req = requests.post(url,json=data,headers=headers) #print(req.text) if __name__=='__main__' : trade("buy","GBP_USD","3")
Please check the transaction status at https://trade.oanda.com/, username: cawa11, password: 1122334455, thank you
There is something wrong with your code
Your code can be simplified to this. Buy and sell orders are determined by whether the unit is positive or negative: