Python code for bracket orders

for anyone interested, here is some working python code for submitSignal bracket orders

This code sends bracket orders to 3 different trading system id’s; just update your own apikey and trading system id’s and the collective2 url; then going forward the only parameters you need to change would be under the #order entry screen section of the code; You can also modify this to only send to two systems or just one by deleting some of the code

here you go:
import requests
import json

trading systemid

conservative = ‘xxxx’
moderate = ‘xxxx’
aggressive = ‘xxxx’

api_key = ‘xxxx’

order entry screen

buyorsell = ‘BTO’ # BTO for longs, STO for shorts
quantity = 3
symbol = ‘@ADU21
entryprice = 0.7000
stoploss = 0.6000
target1 = 0.8000
target2 = 0.8100
target3 = 0.8200

url = ‘xxxx’

headers = {‘content-type’: ‘application/json’, ‘Accept-Charset’: ‘UTF-8’}

data = [
{“apikey”: api_key,
“systemid”: conservative,
“signal”:{
“action”: buyorsell,
“quant”: quantity,
“symbol”: symbol,
“typeofsymbol”: “future”,
“limit”: entryprice,
“duration”: “GTC”,
“market”: 0, # 0 for limit order, 1 for market order
“profittarget”: target1,
“stoploss”: stoploss
#“signalid”: 1011
}
},
{“apikey”: api_key,
“systemid”: moderate,
“signal”:{
“action”: buyorsell,
“quant”: quantity,
“symbol”: symbol,
“typeofsymbol”: “future”,
“limit”: entryprice,
“duration”: “GTC”,
“market”: 0, # 0 for limit order, 1 for market order
“profittarget”: target2,
“stoploss”: stoploss
#“signalid”: 1011
}
},
{“apikey”: api_key,
“systemid”: aggressive,
“signal”:{
“action”: buyorsell,
“quant”: quantity,
“symbol”: symbol,
“typeofsymbol”: “future”,
“limit”: entryprice,
“duration”: “GTC”,
“market”: 0, # 0 for limit order, 1 for market order
“profittarget”: target3,
“stoploss”: stoploss
#“signalid”: 1011
}
}
]

for requestData in data:
r = requests.post(url, json=requestData, headers=headers)
#pastebin_url = r.text
#print (pastebin_url)
data = json.loads(r.text)
z = data[‘signalid’]
print('Order Number To Cancel ', z)