[R-SIG-Finance] IBrokers and fill Price

Mark Harrison harrisonmark1 at gmail.com
Mon May 7 01:12:13 CEST 2012


I have been trying to figure out how to use IBrokers and the API to
place orders, etc.  I have read through the support archives, google,
the docs, presentations, etc and I still can not figure out where I am
going wrong.

Specifically I am trying to place a market order, get my fill price,
and then put in a stop order higher/lower than the fill price.  I am
able to get ids, place the orders, and even seeing what my fill price
is via reqOpenOrders but I am not sure how to get the fill price from
IB in a way that lets me use it - i.e. not just 'cat' to the screen.

Any help would be appreciated.

# Session Info:

R version 2.14.0 (2011-10-31)
Platform: x86_64-pc-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United
States.1252
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252

attached base packages:
[1] graphics  grDevices utils     datasets  stats     methods   base

other attached packages:
 [1] blotter_0.8.4              twsInstrument_1.4-0
IBrokers_0.9-3             qmao_1.2.1
 [5] FinancialInstrument_0.13.6 quantmod_0.3-17            TTR_0.21-1
               Defaults_1.1-1
 [9] xts_0.8-7                  zoo_1.7-7

loaded via a namespace (and not attached):
[1] grid_2.14.0    lattice_0.20-6 tools_2.14.0

# Code Examples
tws <- twsConnect(clientId=2)

symbol <- c("GC")
contract <- buildIBcontract(twsFUT(symbol, "NYMEX", '201206'))

id <- reqIds(tws)
a <- twsOrder(id, action = 'BUY', totalQuantity = '1', orderType = 'MKT')
placeOrder(tws, contract, a)
reqOpenOrders(tws)

TWS Message: 2 -1 2104 Market data farm connection is OK:cusfuture
TWS Message: 2 -1 2104 Market data farm connection is OK:usfuture
TWS Message: 2 -1 2104 Market data farm connection is OK:eurofarm
TWS Message: 2 -1 2104 Market data farm connection is OK:cashfarm
TWS Message: 2 -1 2104 Market data farm connection is OK:usopt
TWS Message: 2 -1 2104 Market data farm connection is OK:usfarm
TWS Message: 2 -1 2106 HMDS data farm connection is OK:ushmds
TWS Execution: orderId=1 time=2012-05-06 18:02:10 side=BOT shares=1
symbol=GC conId=45008148 price=1640.50
TWS OrderStatus: orderId=1 status=Filled filled=1 remaining=0
averageFillPrice=1640.50
TWS OrderStatus: orderId=1 status=Filled filled=1 remaining=0
averageFillPrice=1640.50
TWS OrderStatus: orderId=1 status=Filled filled=1 remaining=0
averageFillPrice=1640.50

twsDisconnect(tws)



More information about the R-SIG-Finance mailing list