I use a code (link is below) to open an order in Interactive Brokers ( I use a paper account) but when I tried to close the opened order after 5 seconds I was not able to do so.What am I doing wrong?
library(IBrokers)
myconid = 3
twsobj = twsConnect(myconid)
myaud = twsCurrency("AUD",currency="USD",exch="IDEALPRO",primary="",strike="0.0",right="",local="",multiplier="",include_expired="0",conId=myconid)
Sys.sleep(2)
myorderid = as.integer(reqIds(twsobj))
print(myorderid)
Sys.sleep(2)
# my workaround:
options("scipen"=4)
placeOrder(twsobj, myaud, twsOrder(myorderid,"SELL", 1, "MKT"))
Sys.sleep(5)
placeOrder(twsobj, myaud, twsOrder(myorderid,"BUY", 1, "MKT"))
Link that I used:[IBrokers - How I send 100000 to IBrokers:::.placeOrder?
UPDATE( Following brian's answer ): I use a code (link is below) to open an order in Interactive Brokers ( I use a paper account) but when I tried to close the opened order after 5 seconds I was not able to do so.What am I doing wrong?
library(IBrokers)
myconid = 3
twsobj = twsConnect(myconid)
myaud = twsCurrency("AUD",currency="USD",exch="IDEALPRO",primary="",strike="0.0",right="",local="",multiplier="",include_expired="0",conId=myconid)
Sys.sleep(2)
print(myorderid)
Sys.sleep(2)
# my workaround:
options("scipen"=4)
placeOrder(twsobj, myaud, twsOrder(122,"SELL", 1, "MKT"))
Sys.sleep(5)
placeOrder(twsobj, myaud, twsOrder(123,"BUY", 1, "MKT"))