Keyboard Shortcuts
Likes
- Twsapi
- Messages
Search
Re: TWS API Error 2019: Order Event Warning - got when trying to submit Bracket order for execution outside RTH. Entry, profit OK. Stop NG.
Nick
When I have encountered this it was due to the rthOnly setting (or whatever it is called now). If you reverse the rthOnly setting for the stop order the warning will probably go away.
toggle quoted message
Show quoted text
I never figured out the actual rules but when I got error 2109 I noted the symbol, order type and exchange. Within my order placement routine I added a check for these combinations and forced rthOnly to be whatever didn't cause the error. Not? helpful in explaining the root cause I know, but it let order processing happen without warnings. On 8/31/2018 11:46 AM, loududka@... wrote:
I'm trying to submit a Backet order,(in this case, for SQ) to fill outside of regular trading hours.? It successfully submits EXCEPT for this warning on the StopLoss: |
historical and live recording of tick data
Hi all,
I'm trying to request historical ticks data for trades but i also want to see the bid/offer at the time of the trades in order to reconstruct the time and sales. However ib has this in 2 different functions, I've no idea why. Can anyone help with how can I piece info from these two streams together in a way that is identical to the time and sales screen, so the little red and green dots are also constructed. If this is not possible,? can i live record the market data to recreate this effect? how does tws do it? thank you for any assistance Dave |
Re: Ibrokers package in R - Get option prices
Simone
I found the functions eWrapper.data.Last and snapShot?on web so I'm not truly able to understand correctly what is the problem. For the moment, I solved using the basic functions: ? ? opt=twsOption(local="",symbol="SPX",expiry=exp,strike=k,right="P") ? ? optPrice=reqMktData(tws,opt,snapshot = T) It takes some time to get option prices (about 10-15 seconds for each contract) but at least works. I'll try to find an alternative way to speeding up the process.? Il giorno ven 31 ago 2018 alle ore 17:23 mark collins <mark.collins@...> ha scritto:
|
TWS API Error 2019: Order Event Warning - got when trying to submit Bracket order for execution outside RTH. Entry, profit OK. Stop NG.
Hi All,
I tried searching twsapi group for this and didn't find a hit.? Hope I didn't miss anything. I'm trying to submit a Backet order,(in this case, for SQ) to fill outside of regular trading hours.? It successfully submits EXCEPT for this warning on the StopLoss: "Error: 2109 Order Event Warning:Attribute 'Outside Regular Trading Hours' is ignored based on the order type and destination. PlaceOrder is now being processed." I've been using bracket orders thru the API for a lot of years, so I don't think it's my code. Set Extended Attributes Range("D72") = 1 - works for Entry and profit.? IB TWS chokes on StopLoss, but "successfully" submits the order. Win7 TWS Build 963.3g May 30, 2017 API_Version=9.71 (.idl and.ocx strangely dated 2013) ActiveX/Excel Any help truly appreciated, Thanks Again, Lou Dudka |
Re: Ibrokers package in R - Get option prices
Well, your R code does have a while(TRUE) loop control so I'd not expect it to stop unless something hits the conditions for breaking the loop.... it's probably stuck there or somewhere similar. Are you printing out the process steps as it goes? Best wishes, M On 31 August 2018 at 15:43, Simone <simone.gallo1990@...> wrote:
--
(T) +44 (0) 131 2202413 ?? (M) +44 (0) 7528 551604 ? (W) Gulfstream Software - Winner Risk Management Awards 2010 This message is subject to : |
Re: Ibrokers package in R - Get option prices
Simone
Richard, Josh, thank you so much for the explanation. With OPRA subscription (using the R code I posted in the first mail)
I get the last values for few option strikes/expirations only (maybe for those contracts that are traded). Now, I've just made the subscription to
US Equity and Options Add-On Streaming Bundle.
If I run the R code with the new subscription I do not get the following message anymore:
"Part of requested market data is not subscribed.
Subscription-independent ticks are still active.Delayed market data is
available.SPX S&P 500 Stock Index/TOP/ALL"
However, like before the code does not stop running and does not create objects (it's 15 min I run the code, I'll wait), I don't know if this is a problem related to the R code I'm using. Can I overcome the limitation of the last price getting only bid/ask prices for a particular day? I just need to bring in R an option chain. Thanks Simone Il giorno ven 31 ago 2018 alle ore 16:14 Josh via Groups.Io <jb201448=yahoo.com@groups.io> ha scritto: Simone, |
Re: Ibrokers package in R - Get option prices
Simone,
If you have the OPRA subscription it covers the options but not the underlying SPX index. For the index you would need CBOE Streaming Market Indexes or US Securities Snapshot and Futures Value Bundle.?
?
So with only the options subscription TWS can return some tick types such as bid/ask/last, but can't return the greek values which require the real time index price to calculate. Thats why it returns the message:?
?
"Part of requested market data is not subscribed. Subscription-independent ticks are still active.Delayed market data is available.SPX S&P 500 Stock Index/TOP/ALL"
?
However you can still receive the bid/ask/last/ values for the options. I would double-check if those are being returned. Please note there won't be a 'last' price in the current day if the option hasn't traded. Josh (IBKR) |
Re: Ibrokers package in R - Get option prices
开云体育I can’t see anything in the market data subscriptions page called ‘OPRA (US Options Exchanges)’, so I’m not sure what you’re referring to. ? I believe the subscription you need is this: ? ‘US Equity and Options Add-On Streaming Bundle Includes streaming realtime quotes for NYSE (CTA/Network A), AMEX (CTA/Network B), NASDAQ (UTP/Network C), and OPRA (US Options). US Securities Snapshot and Futures Value Bundle is required prior to activating this service.’ ? I have that subscription and can access the SPX options with no problems. ? Richard ? ? ? From: twsapi@groups.io <twsapi@groups.io> On Behalf Of Simone
Sent: 31 August 2018 13:20 To: twsapi@groups.io Subject: Re: [TWS API] Ibrokers package in R - Get option prices ? Hi Richard? ? I relate to options on spx index on CBOE, for which I have the following market data subscription: OPRA (US Options Exchanges):?Provide options data of AMEX, ARCA, BATS, BOX, BSE, CBOE2, CBOE, ISE NASDAQ and PHLX. Do I need a different data subscription? ? Thanks Simone ? Il giorno ven 31 ago 2018 alle ore 13:34 Richard L King <rlking@...> ha scritto:
|
Re: Ibrokers package in R - Get option prices
Simone
Hi Richard? I relate to options on spx index on CBOE, for which I have the following market data subscription: OPRA (US Options Exchanges):?Provide options data of AMEX, ARCA, BATS, BOX, BSE, CBOE2, CBOE, ISE NASDAQ and PHLX. Do I need a different data subscription? Thanks Simone Il giorno ven 31 ago 2018 alle ore 13:34 Richard L King <rlking@...> ha scritto:
|
Re: Ibrokers package in R - Get option prices
开云体育Simone ? If you don’t specify the exchange, you get the SPX options on CBOE, which would indeed be a separate subscription. ? Richard ? ? From: twsapi@groups.io <twsapi@groups.io> On Behalf Of Simone
Sent: 30 August 2018 23:42 To: twsapi@groups.io Subject: [TWS API] Ibrokers package in R - Get option prices ? Hi everyone, ? I'm trying to get SPX put option prices for a given strike and expiration using the IBrokers package in R. ? require(IBrokers) tws=twsConnect() ticker="SPX" exp="20181115" k=2700 opt=twsOption(local="",symbol=ticker,expiry=exp,strike=k,right="P") optPrice=reqMktData(tws,opt,eventWrapper=eWrapper.data.Last(1),CALLBACK=snapShot)
? eWrapper.data.Last <- function(n) { ? eW <- eWrapper(NULL)? # use basic template ? eW$assign.Data("data", rep(list(structure(.xts(matrix(rep(NA_real_,2),nc=2),0), ? .Dimnames=list(NULL,c("LastSize","Last")))),n)) ? ? eW$tickPrice <- function(curMsg, msg, timestamp, file, ...) ??{ ??? tickType = msg[3] ??? msg <- as.numeric(msg) ??? id <- msg[2] #as.numeric(msg[2]) ??? data <- eW$get.Data("data") #[[1]]? # list position of symbol (by id == msg[2]) ??? attr(data[[id]],"index") <- as.numeric(Sys.time()) ??? nr.data <- NROW(data[[id]]) ??? if(tickType == .twsTickType$LAST) { ????? data[[id]][nr.data,2] <- msg[4] ??? } ??? eW$assign.Data("data", data) ??? c(curMsg, msg) ? } ? eW$tickSize? <- function(curMsg, msg, timestamp, file, ...) ??{ ????data <- eW$get.Data("data") ??? tickType = msg[3] ??? msg <- as.numeric(msg) ??? id <- as.numeric(msg[2]) ??? attr(data[[id]],"index") <- as.numeric(Sys.time()) ??? nr.data <- NROW(data[[id]]) ??? if(tickType == .twsTickType$LAST_SIZE) { ????? data[[id]][nr.data,1] <- msg[4] ??? } ????eW$assign.Data("data", data) ??? c(curMsg, msg) ? } ? return(eW) } ? ? ? snapShot <- function (twsCon, eWrapper, timestamp, file, playback = 1, ...){ ? if (missing(eWrapper)) ??? eWrapper <- eWrapper() ? names(eWrapper$.Data$data) <- eWrapper$.Data$symbols ? con <- twsCon[[1]] ? if (inherits(twsCon, "twsPlayback")) { ??? sys.time <- NULL ??? while (TRUE) { ????? if (!is.null(timestamp)) { ??????? last.time <- sys.time ??????? sys.time <- as.POSIXct(strptime(paste(readBin(con, ????????????????????????????????????????????????????? character(), 2), collapse = " "), timestamp)) ??????? if (!is.null(last.time)) { ????????? Sys.sleep((sys.time - last.time) * playback) ??????? } ??????? curMsg <- .Internal(readBin(con, "character", ??????????????????????????????????? 1L, NA_integer_, TRUE, FALSE)) ??????? if (length(curMsg) < 1) ????????? next ??????? processMsg(curMsg, con, eWrapper, format(sys.time, ???????????????????????????????????????????????? timestamp), file, ...) ????? } ????? else { ??????? curMsg <- readBin(con, character(), 1) ??????? if (length(curMsg) < 1) ????????? next ??????? processMsg(curMsg, con, eWrapper, timestamp, ?????????????????? file, ...) ??????? if (curMsg == .twsIncomingMSG$REAL_TIME_BARS) ????????? Sys.sleep(5 * playback) ????? } ??? } ? } ? else { ??? while (TRUE) { ????? socketSelect(list(con), FALSE, NULL) ????? curMsg <- .Internal(readBin(con, "character", 1L, ????????????????????????????????? NA_integer_, TRUE, FALSE)) ????? if (!is.null(timestamp)) { ??????? processMsg(curMsg, con, eWrapper, format(Sys.time(), ???????????????????????????????????????????????? timestamp), file, ...) ????? } ?? ???else { ??????? processMsg(curMsg, con, eWrapper, timestamp, ?????????????????? file, ...) ????? } ????? if (!any(sapply(eWrapper$.Data$data, ))) ??????? return(do.call(rbind, lapply(eWrapper$.Data$data, ?? ??????????????????????????????????as.data.frame))) ??? } ? } } I get this on the console:?? 2 -1 2104 Connessione con il Server dei dati di mercato è OK:usfuture 2 -1 2104 Connessione con il Server dei dati di mercato è OK:eufarm 2 -1 2104 Connessione con il Server dei dati di mercato è OK:usopt 2 -1 2104 Connessione con il Server dei dati di mercato è OK: 2 -1 2106 Connessione con il HMDS data farm è OK:euhmds 2 -1 2106 Connessione con il HMDS data farm è OK:ushmds 2 1 10090 Parte dei dati di mercato richiesti non sono sottoscritti. Tick indipendenti dalle sottoscrizioni sono ancora attivi.Dati di mercato differiti non disponibili.SPX S&P 500 Stock Index/TOP/ALL The last R message is not very clear since OPRA market data (which includes SPX) is already included in my market data subscription. In some cases, I get the last put option price for only few strike prices, for others R does not stop running and stamp the message: ?"2 1 10090 Parte dei dati di mercato richiesti non sono sottoscritti. Tick indipendenti dalle sottoscrizioni sono ancora attivi.Dati di mercato differiti non disponibili.SPX S&P 500 Stock Index/TOP/ALL This lead to problems in loops with multiple expirations and strikes. Any help would be greatly appreciated. Simone |
Re: Ibrokers package in R - Get option prices
my italian is bad, too. But may this is issue be related to spx-index-and spx-futures different subscriptions? I mixed this type of assets in the past as well. Not sure if this is of any help. But maybe it is worth of checking... Simone <simone.gallo1990@...> schrieb am 12:42 Freitag, 31.August 2018: Hi Mark, I've checked my?data subscriptions,?OPRA (which includes SPX) is already included.?Do you think other data subscriptions are required for SPX? I tried also during trading hours to avoid deferred market data but the result is the same. Is there an alternative way to get historical option prices (specifying for example yesterday at a particular hour)?? Thanks, Simone Il giorno ven 31 ago 2018 alle ore 12:23 mark collins <mark.collins@...> ha scritto:
|
Re: Ibrokers package in R - Get option prices
Simone
Hi Mark, I've checked my?data subscriptions,?OPRA (which includes SPX) is already included.?Do you think other data subscriptions are required for SPX? I tried also during trading hours to avoid deferred market data but the result is the same. Is there an alternative way to get historical option prices (specifying for example yesterday at a particular hour)?? Thanks, Simone Il giorno ven 31 ago 2018 alle ore 12:23 mark collins <mark.collins@...> ha scritto:
|
Re: Ibrokers package in R - Get option prices
My Italian is terrible, but I think it means you are not subscribed (lit. under written) and it suggests that you activate it. Could that be the case, that you have not subscribed or activated the necessary subscription?? Someone with better Italian will probably be able to help more M On Fri, 31 Aug 2018, 09:26 Simone, <simone.gallo1990@...> wrote: Hi everyone, |
Ibrokers package in R - Get option prices
Simone
Hi everyone,
?
I'm trying to get SPX put option prices for a given strike and expiration using the IBrokers package in R. The final aim is to fill an option price chain from IB. Not necessarily with the latest option prices available, but also with bid/ask prices for a given date/hour would be useful. I'm using the following code: ?
?
I get this on the console:??
The last R message is not very clear since OPRA market data (which includes SPX) is already included in my market data subscription. In some cases, I get the last put option price for only few strike prices, for others R does not stop running and stamp the message: ?"2 1 10090 Parte dei dati di mercato richiesti non sono sottoscritti. Tick indipendenti dalle sottoscrizioni sono ancora attivi.Dati di mercato differiti non disponibili.SPX S&P 500 Stock Index/TOP/ALL This lead to problems in loops with multiple expirations and strikes. Any help would be greatly appreciated. Simone |
Re: braket order failed
Nick
All orders except the final child should be transmit false. Only the final child should be transmit true.
toggle quoted message
Show quoted text
On 8/30/2018 7:17 PM, Jeff Han wrote:
I have the parent transmit set as false, both children as true, and placeOrder sequence is parent goes first and then children. |
Re: braket order failed
Jeff Han
Hi Josh/Richard,
Looking at my own log again, I deleted my previous posting, and I think I still have not find reason my orderid as following: parent: 1535724415 SYM[IBAT] ([AAPL][P][OPT][327473110]) OpenOrder ID: 1535724415, @ SMART BUY: LMT, 7 status: Submitted ct[1775][0][1774][14][13:33:37-632] SYM[IBAT] OrderStatus. Id: 1535724415, Status: Submitted, Filled: 0, Remaining: 7, AvgFillPrice: 0, PermId: 1087925538, LastFillPrice: 0, ClientId: 0, WhyHeld:? ct[1776][0][1775][14][13:33:37-632] SYM[IBAT] ([AAPL][P][OPT][327473110]) OpenOrder ID: 1535724415, @ SMART BUY: LMT, 7 status: Filled ct[1779][0][1778][20][13:33:37-723] SYM[IBAT] OrderStatus. Id: 1535724415, Status: Filled, Filled: 7, Remaining: 0, AvgFillPrice: 3.55, PermId: 1087925538, LastFillPrice: 3.55, ClientId: 0, WhyHeld:? ct[1781][0][1780][14][13:33:37-723] child2: profit taking lmt order (failed) 1535724417 SYM[IBAT] ([AAPL][P][OPT][327473110]) OpenOrder ID: 1535724417, @ SMART SELL: LMT, 7 status: Inactive ct[1782][0][1781][13][13:33:37-723] SYM[IBAT] OrderStatus. Id: 1535724417, Status: Inactive, Filled: 0, Remaining: 7, AvgFillPrice: 0, PermId: 1087925540, LastFillPrice: 0, ClientId: 0, WhyHeld:? ct[1784][0][1783][12][13:33:37-723] Error. SYM[IBAT][13:33:37-723] Id: 1535724417, Code: 201, Msg: Order rejected - reason:The parent order is being canceled. child1: stoploss (stp order and it is OK) 1535724416 SYM[IBAT] ([AAPL][P][OPT][327473110]) OpenOrder ID: 1535724416, @ SMART SELL: STP, 7 status: PreSubmitted ct[1773][0][1772][21][13:33:37-632] SYM[IBAT] OrderStatus. Id: 1535724416, Status: PreSubmitted, Filled: 0, Remaining: 7, AvgFillPrice: 0, PermId: 1087925539, LastFillPrice: 0, ClientId: 0, WhyHel + + +? d: child,locate,trigger ct[1774][0][1773][23][13:33:37-632] SYM[IBAT] OrderStatus. Id: 1535724416, Status: PreSubmitted, Filled: 0, Remaining: 7, AvgFillPrice: 0, PermId: 1087925539, LastFillPrice: 0, ClientId: 0, WhyHel + + +? d: locate,trigger ct[1786][0][1785][15][13:33:37-793] SYM[IBAT] ([AAPL][P][OPT][327473110]) OpenOrder ID: 1535724416, @ SMART SELL: STP, 7 status: PreSubmitted ct[1786][1][1772][13][13:33:40-232] SYM[IBAT] ([AAPL][P][OPT][327473110]) OpenOrder ID: 1535724416, @ SMART SELL: STP, 7 status: PreSubmitted ct[1786][1][1772][13][13:33:42-759] SYM[IBAT] OrderStatus. Id: 1535724416, Status: PreSubmitted, Filled: 0, Remaining: 7, AvgFillPrice: 0, PermId: 1087925539, LastFillPrice: 0, ClientId: 0, WhyHeld: locate,trigger ct[1786][1][1785][11][13:33:42-827] .... SYM[IBAT] ([AAPL][P][OPT][327473110]) OpenOrder ID: 1535724416, @ SMART SELL: STP, 7 status: PreSubmitted ct[1739][1][170][30][14:13:42-878] SYM[IBAT] ([AAPL][P][OPT][327473110]) OpenOrder ID: 1535724416, @ SMART SELL: STP, 7 status: PendingCancel ct[1740][0][1739][25][14:13:44-539] SYM[IBAT] OrderStatus. Id: 1535724416, Status: PendingCancel, Filled: 0, Remaining: 7, AvgFillPrice: 0, PermId: 1087925539, LastFillPrice: 0, ClientId: 0, WhyHeld:? ct[1741][0][1740][12][14:13:44-539] my c++ code: ?int triggerMethod = pc_cmshm->get_conf_int("order.triggerMethod"); ??? vector<Order> orders; ??? //GCL/GPL/GPS order kicked in here ??? if( isGrp ) { ??????? Order parent; ??????? int pordid = pc_cmshm->get_trade_id(); ??????? parent.orderId????????? = pordid; ??????? parent.action?????????? = grp[0].buysell; ??????? parent.totalQuantity??? = pos; ??????? parent.optOutSmartRouting= true; ??????? parent.transmit???????? = false; ??????? //using the orderType and lmtPrice ??????? if(om.orderType.size()>0 && om.lmtPrice > 0 ) { ??????????? parent.orderType??? = om.orderType; ??????????? double lmtPrice???? = om.lmtPrice; ??????????? //make auxPrice/profit_price incr ??????????? if ( incr > 0.01 ) { ??????????????? double amod = fmod(lmtPrice,incr); ??????????????? if ( amod != NAN ) { ??????????????????? lmtPrice += (incr-amod); ??????????????? } ??????????? } ??????????? //increment ??????????? parent.lmtPrice???? = lmtPrice; ??????????? parent.triggerMethod= triggerMethod; ??????? }else{ ??????????? parent.orderType??? = grp[0].orderType; ??????? } ??????? //timed cancel ??????? if(om.enableCancel > 0) { ??????????? string cancelAfterTime? = jat_now_plus_seconds(om.enableCancel); ??????????? TimeCondition* timeCond = dynamic_cast<TimeCondition *>(OrderCondition::create(OrderCondition::OrderConditionType::Time)); ??????????? timeCond->isMore(true); ??????????? timeCond->time(cancelAfterTime); ??????????? parent.conditionsCancelOrder = true; ??????????? parent.conditions.push_back(shared_ptr<TimeCondition>(timeCond)); ??????? } ??????? orders.push_back(parent); ??????? //stoploss must be the second ??????? int this_oid = pc_cmshm->get_trade_id(); ??????? Order stoploss; ??????? stoploss.orderId??????? = this_oid; ??????? stoploss.parentId?????? = pordid; ??????? stoploss.action???????? = grp[1].buysell; ??????? stoploss.orderType????? = grp[1].orderType; ??????? stoploss.auxPrice?????? = grp[1].price; ??????? stoploss.totalQuantity? = pos; ??????? stoploss.optOutSmartRouting = true; ??????? stoploss.triggerMethod? = triggerMethod; ??????? stoploss.transmit?????? = false; ??????? orders.push_back(stoploss); ??????? this_oid = pc_cmshm->get_trade_id(); ??????? Order profit; ??????? profit.orderId????????? = this_oid; ??????? profit.parentId???????? = pordid; ??????? profit.action?????????? = grp[2].buysell; ??????? profit.orderType??????? = grp[2].orderType; ??????? profit.lmtPrice???????? = grp[2].price; ??????? profit.totalQuantity??? = pos; ??????? profit.optOutSmartRouting = true; ??????? profit.triggerMethod??? = triggerMethod; ??????? profit.transmit???????? = true; ??????? orders.push_back(profit); ... ?? for(auto o:orders) { ??????????? errno=0; ??????????? pc_cmshm->wait_for_ok_to_send(); ???????? ??????????????? m_pClient->placeOrder(o.orderId, con, o); ? ??????????? jat_pmsg(); ???? } |
Re: braket order failed
开云体育Your images are too small to read. ? The information returned by the API in the openOrder(), orderStatus() and errMsg() callbacks should help you determine what’s wrong. ? ? From: twsapi@groups.io <twsapi@groups.io> On Behalf Of Jeff Han
Sent: 30 August 2018 20:50 To: twsapi@groups.io Subject: Re: [TWS API] braket order failed ? most of cases, things are ok, such as the following: |