2011-08-17 11 views
5
reqMktData(tws,twsOPT("AAPL 110820C00390000")) 

oR Ibrokers twsOPT utilizzo

reqMktData(tws,twsOPT("AAPL110820C00390000")) 

risultato: TWS Messaggio: 2 1 200 Nessuna definizione di sicurezza è stato trovato per la richiesta

Perché?

reqMktData(tws,twsSTK("AAPL")) 

funziona correttamente.

The man dice:

twsOption(local, 
      expiry="", 
      strike="", 
      right="", 
      exch="SMART", 
      primary="", 
      currency='USD', 
      symbol='', 
      multiplier="100", 
      include_expired='0', 
      conId=0) 

contratti di opzione su TWS sono alcune regole che sono diverse rispetto le richieste di dati standard.

Il simbolo locale è obbligatorio. Questo può essere trovato sulla schermata principale TWS sotto i dettagli del contratto, o tramite il web all'indirizzo www.interactivebrokers.com

Poiché è richiesto il simbolo locale, tutti gli altri valori sono ridondanti. È meglio specificare semplicemente il nome locale e lasciare che TWS gestisca la ricerca.

+0

io non sono sicuro perché si sta utilizzando "AAPL110820C00390000 !" Perché non stai usando "AAPL?" Non penso che il valore che stai usando sia il nome locale corretto. – Soumendra

risposta

5

Non si sta ottenendo il locale corretto. Il formato corretto utilizza un campo di sei caratteri (specifiche OSI) e stai provando rispettivamente a 5 e a 4.

Non è obbligatorio l'uso locale, naturalmente, ma richiede più dettagli su argomenti diversi.

> reqContractDetails(ibg, twsOPT("AAPL 110820C00390000")) 
[[1]] 
List of 18 
    $ version  : chr "6" 
    $ contract  :List of 16 
..$ conId   : chr "86896934" 
..$ symbol   : chr "AAPL" 
..$ sectype  : chr "OPT" 
..$ exch   : chr "SMART" 
..$ primary  : chr "" 
..$ expiry   : chr "20110819" 
..$ strike   : chr "390.0" 
..$ currency  : chr "USD" 
..$ right   : chr "C" 
..$ local   : chr "AAPL 110820C00390000" 
..$ multiplier  : chr "100" 
..$ combo_legs_desc: chr "" 
..$ comboleg  : chr "" 
..$ include_expired: chr "" 
..$ secIdType  : chr "" 
..$ secId   : chr "" 
..- attr(*, "class")= chr "twsContract" 
$ marketName : chr "AAPL" 
$ tradingClass : chr "AAPL" 
$ conId   : chr "86896934" 
$ minTick  : chr "0.01" 
$ orderTypes : chr [1:44] "ACTIVETIM" "ADJUST" "ALERT" "ALGO" ... 
$ validExchanges: chr [1:12] "SMART" "AMEX" "BATS" "BOX" ... 
$ priceMagnifier: chr "1" 
$ underConId : chr "265598" 
$ longName  : chr "APPLE INC" 
$ contractMonth : chr "201108" 
$ industry  : chr "Technology" 
$ category  : chr "Computers" 
$ subcategory : chr "Computers" 
$ timeZoneId : chr "EST" 
$ tradingHours : chr "20110817:0930-1600;20110818:0930-1600" 
$ liquidHours : chr "20110817:0930-1600;20110818:0930-1600" 

è possibile estrarre il contratto con as.twsContract:

as.twsContract(reqContractDetails(ibg, twsOPT("AAPL 110820C00390000"))) 

O semplicemente chiamare la richiesta reqMktData come è:

reqMktData(ibg, twsOPT("AAPL 110820C00390000")) 

## OR 

reqMktData(ibg, twsOPT("",symbol="AAPL",right="C", strike="390", expiry="201108")) 
+0

Capisco. 6 posti per ogni ticker. Grazie mille! – Pauly

5

È possibile evitare questi tipi di problemi utilizzando il pacchetto twsInstrument on R-Forge

library(twsInstrument) 

Ognuna di queste sarà possibile ottenere il twsContract

getContract("AAPL 111217P00390000") 
getContract("AAPL  111217P00390000") #number of spaces does not matter 
getContract("AAPL20111217P00390000") #year can be 4 digits or 2 
getContract("AAPL_111217P00390000") 
getContract("AAPL111217P00390000") 
getContract("AAPL111217P390") 
getContract("AAPL_111217P390") 
getContract("AAPL_20111217P390") 
getContract("AAPL_111217P390.00") 

#by conId 
getContract("93189601") 
getContract(93189601) 

Tutti coloro vi darà la stessa cosa:

> getContract(93189601) 
List of 16 
$ conId   : chr "93189601" 
$ symbol   : chr "AAPL" 
$ sectype  : chr "OPT" 
$ exch   : chr "SMART" 
$ primary  : chr "" 
$ expiry   : chr "20111216" 
$ strike   : chr "390" 
$ currency  : chr "USD" 
$ right   : chr "P" 
$ local   : chr "AAPL 111217P00390000" 
$ multiplier  : chr "100" 
$ combo_legs_desc: chr "" 
$ comboleg  : chr "" 
$ include_expired: chr "" 
$ secIdType  : chr "" 
$ secId   : chr "" 

Purtroppo, non è possibile ottenere dettagli del contratto per le opzioni che sono già scaduti. Non so se questo è un problema con IBrokers, o se Interactive Brokers non lo supporta, ma ottenere i dettagli del contratto per i future già scaduto non è un problema

> getContract("ESM1") 
Connected with clientId 100. 
Trying to resolve error in contract details. Using include_expired=1 
Contract details request complete. Disconnected. 
List of 16 
$ conId   : chr "73462897" 
$ symbol   : chr "ES" 
$ sectype  : chr "FUT" 
$ exch   : chr "GLOBEX" 
$ primary  : chr "" 
$ expiry   : chr "20110617" 
$ strike   : chr "0" 
$ currency  : chr "USD" 
$ right   : chr "" 
$ local   : chr "ESM1" 
$ multiplier  : chr "50" 
$ combo_legs_desc: chr "" 
$ comboleg  : chr "" 
$ include_expired: chr "1" 
$ secIdType  : chr "" 
$ secId   : chr "" 
+1

Benvenuti in SO, Garrett! –