Keyboard Shortcuts
Likes
- Twsapi
- Messages
Search
Re: TWS 50/sec limit
Limit requests to 50/sec. There is no other option.
--
SI: ?+386-30-315-640 |
||||||||||||||||||
Re: FUNDAMENTAL_RATIOS
In the reqMktData() EClient Socket Method, specify
'258' as the third parameter.? Then in the tickString() EWrapper
Method, look for tick value 47 which should contain those fields, one per
callback.
toggle quoted message
Show quoted text
[rwk] At 08:37 AM 12/22/2015, you wrote: I have a simple c# program setup with the following code: |
||||||||||||||||||
FUNDAMENTAL_RATIOS
Hi All,
I have a simple c# program setup with the following code: Contract contract = new Contract(); contract.Symbol = "GE"; contract.SecType = "STK"; contract.Currency = "USD"; contract.Exchange = "SMART"; contract.PrimaryExch = "NASDAQ"; This works great, no issues at all.? However how do I go about using the code from this URL:
? I have checked the API samples and there is nothing at all Any advice / help would be greatly appreciated, thank you! |
||||||||||||||||||
Re: IBController.jar on Mac
ce
I don't know about mac but I did it in Linux , so mac should be similar. Do you click on :
IBControllerStart.sh or IBControllerGatewayStart.sh ?
?
in IBControllerGatewayStart.sh I changed following parameters :
IBCDIR=/home/....../IBController
IIBCINI="/home/......./IBController/IBController.ini"
TWSDIR="/home/......./IGW/IBJts"
?
-----Original Message----- From: "felixdietrich87b@... [TWSAPI]" [TWSAPI@...] Date: 12/21/2015 08:12 PM To: TWSAPI@... Subject: [TWS API] IBController.jar on Mac ? ? Hi. Is anybody using the IBController on a Mac? I have done everything as stated in the documentation, but when I try to launch the Controller it says "The Java JAR file IBController.jar could not be launched". Is this the correct way to launch it, by double-clicking? Kind regards, Felix? ? |
||||||||||||||||||
IBController.jar on Mac
Hi. Is anybody using the IBController on a Mac? I have done everything as stated in the documentation, but when I try to launch the Controller it says "The Java JAR file IBController.jar could not be launched". Is this the correct way to launch it, by double-clicking? Kind regards, Felix? |
||||||||||||||||||
Building an options trading algo using TWS. Need some help!
Hello All
Kurt wrote "You can't stop the
full data from coming in on the socket
Bear with me, I am missing the answer to the getting disconnected problem. If there is a better solution out there than the IB java test client please let me know. This should be the easy stuff. It is really bogging down the fun work.
Here is what we need to make a trade decision. For a group of underlying symbols:
SPYSupport = 208.75 SPYResistance = 210.55 AAPLSupport = 100.00 AAPLResistance = 105.00 SPYPrice = Current price AAPLPrice = Current price And so on_____. //Support and resistance?levels are adjusted daily before market open. ?????? if?SPYPrice < SPYSupport an opportunity for a BullPutSpread exist. SPYBullPutSpread = true ?????? If SPYPrice > SPYResistance an opportunity for a BearCallSpread exist. BearCallSpread = true
dte?= A // These are theta positive strategies. Time decay starts to accelerate at 45days. ShortDeltaBull = .20 // This correlates to an 80% chance of success. Adjust these levels for your risk tolerance. The algo could also adjust these levels based on current 52 week IV percentile. ShortDeltaBear = .80 // Same 80% chance of success. spread = D // The difference in short and long strike prices. Thinking further, each underlying will need its own spread variable (SPYSpread = X, AAPLSpread = Y) The formula for a SPYBullPutSpread short contract is: if SPYBullPutSpread = true Search the options chain for deltas < shortDeltaBull Filter the resulting contracts by variable dte The results are the short side contract candidates.
Again using the SPYBullPutSpread strategy, We take the short contract candidates strike price from above and subtract variable SPYSpread. The result is the long side contract. The two contracts are matched somehow into a combo trade. The credit on this combo is now calculated using the bid (sell the short) price for the short minus the ask (buy the long) on the long (bidPriceShort ¨C askPriceLong). The resulting credit for this combo is now checked for sufficient ROI. Currently I use ROI => DTE. For example, 10 contracts with a $1 spread requires $1000 buying power effect. A $230 credit = 23% ROI. The DTE will need to be 23 days or less. When the smoke clears from all the above, We have a credit spread to trade!!! The next step is to execute the trade. Protections will need to be built into the framework such as: Excluding days the markets?are closed.? FOMC meetings and market moving news days. Earnings. I generally do not enter trades in the first hour on SPY. Weekly SPY trades are not held over night. This list will continue to build. As you can see, I can explain the strategy. Writing code to make it dance is along ways away for me. Any help will definitely be rewarding! I will explain the rest of the strategy when we get the entry portion completed. Terry ? |
||||||||||||||||||
Re: Building an options trading algo using TWS. Need some help!
On 12/19/15, 4:22 PM, "todell826@... [TWSAPI]"
<TWSAPI@...> wrote: Can the options chain be limited toNo. 1- you only have the choice to specify specific dates (or months, by omitting the two day digits, perhaps years--haven't tried) or not 2- you only have the option to specify a single strike price or not You will have to request more than you need, and filter the result accordingly. In that sense, of course you can do it, and as efficiently as you like. You can't stop the full data from coming in on the socket however. You could specify one expiration at a time, or one month at a time, to limit the throughput, if that actually mattered, which probably it will not. -Kurt |
||||||||||||||||||
Re: Building an options trading algo using TWS. Need some help!
¿ªÔÆÌåÓýare you willing to finish my code
this is what i do in VB ?ListBox1.Items.Add("getting chain") ??????? contractend = 0 ??????? AxTws1.reqContractDetailsEx(1, contract) ??????? While contractend = 0 ??????????? Application.DoEvents() ??????? End While ??????? ListBox1.Items.Add("chain completed") ??????? ListBox1.Items.Add("getting market data for " & fullarray.Count.ToString & " options") ??????? fullarray.Sort() ??????? TextBox1.Text.ToUpper() ??????? rnumber = 0 ??????? tickend = 0 ??????? While rnumber < fullarray.Count ??????????? Application.DoEvents() ??????????? marktime = GetTickCount ??????????? While GetTickCount < marktime + 3 ??????????????? Application.DoEvents() ??????????? End While ??????????? ss = fullarray(rnumber).split(",") ??????????? 'execute the? req market data events ??????????? AxTws1.reqMktData(Convert.ToInt32(ss(3)), TextBox1.Text, "OPT", ss(0), Convert.ToDouble(ss(1)), ss(2), "", "SMART", "", "USD", "", 2)????? '0 =streaming 1=snapshot" ??????????? Application.DoEvents() ??????????? rnumber += 1 ??????? End While ??????? While (tickend < fullarray.Count) ??????????? Application.DoEvents() ??????? End While On 12/18/2015 10:15 PM, Patrick Actor patrick.actor@... [TWSAPI] wrote:
|
||||||||||||||||||
Re: Building an options trading algo using TWS. Need some help!
Yes, but the request is too big to do all at once. IB has a throttle on how many symbols can be requested in a single request. I assume he is using the Java client IB provides and had the same problem. Disconnects if you request the entire chain even though IB built the client. I had to request one expiration then loop to the next but this is clunky as the expirations are not always Fridays. He could manually enter each expiration date in a structure and iterate through that I suppose.? PA
|
||||||||||||||||||
Re: Building an options trading algo using TWS. Need some help!
I'm not sure I understand what you're doing.?
It only takes one request to get an entire chain.? The limitation is
on request, not responses.
toggle quoted message
Show quoted text
[rwk] At 07:30 PM 12/18/2015, you wrote: I have been looking at the IB sample application. From what I can see it has a lot of the functions needed for the option strategies I am working on. One problem it has is when requesting options chain data, the api loses connection due to exceeding the request per second limit of 50. Does anyone have a solution? |
||||||||||||||||||
Re: Building an options trading algo using TWS. Need some help!
I have been looking at the IB sample application. From what I can see it has a lot of the functions needed for the option strategies I am working on. One problem it has is when requesting options chain data, the api loses connection due to exceeding the request per second limit of 50. Does anyone have a solution? This is the option chain panel in the latest version. /* Copyright (C) 2013 Interactive Brokers LLC. All rights reserved.? This code is subject to the terms ?* and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ package apidemo; import static com.ib.controller.Formats.fmtNz; import static com.ib.controller.Formats.fmtPct; import java.awt.BorderLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import javax.swing.Box; import javax.swing.BoxLayout; import javax.swing.JCheckBox; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.JTextField; import javax.swing.Timer; import javax.swing.border.TitledBorder; import javax.swing.table.AbstractTableModel; import apidemo.util.HtmlButton; import apidemo.util.NewTabbedPanel; import apidemo.util.NewTabbedPanel.NewTabPanel; import apidemo.util.TCombo; import apidemo.util.UpperField; import apidemo.util.Util; import apidemo.util.VerticalPanel; import com.ib.client.Contract; import com.ib.client.ContractDetails; import com.ib.client.TickType; import com.ib.client.Types.Right; import com.ib.client.Types.SecType; import com.ib.controller.ApiController.IContractDetailsHandler; import com.ib.controller.ApiController.IOptHandler; import com.ib.controller.ApiController.TopMktDataAdapter; public class OptionChainsPanel extends JPanel { ?private Contract m_underContract = new Contract(); ?private NewTabbedPanel m_tabbedPanel = new NewTabbedPanel(); ?private JTextField m_optExch = new UpperField(); ?private UpperField m_symbol = new UpperField(); ?private TCombo<SecType> m_secType = new TCombo<SecType>( SecType.values() ); ?private UpperField m_exchange = new UpperField(); ?private UpperField m_currency = new UpperField(); ?private JCheckBox m_snapshot = new JCheckBox(); ?OptionChainsPanel() { ??m_symbol.setText( "IBM"); ??m_secType.setSelectedItem( SecType.STK); ??m_exchange.setText( "SMART"); ??m_currency.setText( "USD"); ??m_optExch.setText( "SMART"); ?? ??HtmlButton button = new HtmlButton( "Go") { ???@Override protected void actionPerformed() { ????onAdd(); ???} ??}; ?? ??VerticalPanel topPanel = new VerticalPanel(); ??topPanel.add( "Symbol", m_symbol); ??? ?topPanel.add( "Currency", m_currency); ??? ?topPanel.add( "Underlying sec type", m_secType); ??? ?topPanel.add( "Underlying exchange", m_exchange, Box.createHorizontalStrut(20), button); ??topPanel.add( "Option exchange", m_optExch); ??topPanel.add( "Use snapshot data", m_snapshot); ?? ??setLayout( new BorderLayout() ); ??add( topPanel, BorderLayout.NORTH); ??add( m_tabbedPanel); ?} ?protected void onAdd() { ??m_underContract.symbol( m_symbol.getText().toUpperCase() ); ??m_underContract.secType( m_secType.getSelectedItem() ); ??m_underContract.exchange( m_exchange.getText().toUpperCase() ); ??m_underContract.currency( m_currency.getText().toUpperCase() ); ??ApiDemo.INSTANCE.controller().reqContractDetails( m_underContract, new IContractDetailsHandler() { ???@Override public void contractDetails(ArrayList<ContractDetails> list) { ????onRecUnderDetails( list); ???} ??}); ?} ?protected void onRecUnderDetails(ArrayList<ContractDetails> list) { ??if (list.size() != 1) { ???ApiDemo.INSTANCE.show( "Error: " + list.size() + " underlying contracts returned"); ???return; ??} ?? ??// request option chains ??Contract optContract = new Contract(); ??optContract.symbol( m_underContract.symbol() ); ??optContract.currency( m_underContract.currency() ); ??optContract.exchange( m_optExch.getText() ); ??optContract.secType( SecType.OPT); ?? ??final ChainPanel symbolPanel = new ChainPanel(); ??m_tabbedPanel.addTab( optContract.symbol(), symbolPanel, true, true); ?? ??ApiDemo.INSTANCE.controller().reqContractDetails( optContract, symbolPanel); ?} ? ?private class ChainPanel extends NewTabPanel implements IContractDetailsHandler, ActionListener? { ??ChainModel m_putsModel = new ChainModel(); ??JTable m_putsTable = new JTable( m_putsModel); ??ChainModel m_callsModel = new ChainModel(); ??JTable m_callsTable = new JTable( m_callsModel); ??Timer m_timer = new Timer( 800, this); ???? JLabel m_labUnderPrice = new JLabel(); ???? TopMktDataAdapter m_stockListener = new TopMktDataAdapter() { ??????????? @Override public void tickPrice(TickType tickType, double price, int canAutoExecute) { ??????????????? if (tickType == TickType.LAST) { ??????????????????? m_labUnderPrice.setText( "" + price); ??????????????? } ??????????? } ??????? }; ???? ??ChainPanel() { ???JScrollPane scrollPuts = new JScrollPane( m_putsTable); ???scrollPuts.setBorder( new TitledBorder( "Puts")); ???JScrollPane scrollCalls = new JScrollPane( m_callsTable); ???scrollCalls.setBorder( new TitledBorder( "Calls")); ???VerticalPanel underPanel = new VerticalPanel(); ??????????? underPanel.add( "Underlying price", m_labUnderPrice); ??????????? ???JPanel mainPanel = new JPanel(); ???mainPanel.setLayout( new BoxLayout( mainPanel, BoxLayout.X_AXIS)); ???mainPanel.add( scrollCalls); ??????????? mainPanel.add( scrollPuts); ??? ???setLayout( new BorderLayout() ); ???add( underPanel, BorderLayout.NORTH); ???add( mainPanel); ??? ???m_timer.start(); ??? ???ApiDemo.INSTANCE.controller().reqTopMktData( m_underContract, "", false, m_stockListener); ??} ?? ??/** Called when the tab is first visited. */ ??????? @Override public void activated() { ??????? } ??? ?/** Called when the tab is closed by clicking the X. */ ??????? @Override public void closed() { ??????????? ApiDemo.INSTANCE.controller().cancelTopMktData( m_stockListener); ??????????? m_putsModel.desubscribe(); ??????????? m_callsModel.desubscribe(); ??????????? m_timer.stop(); ??????? } ??@Override public void actionPerformed(ActionEvent e) { ???m_putsModel.fireTableDataChanged(); ???m_callsModel.fireTableDataChanged(); ??} ?? ??@Override public void contractDetails(ArrayList<ContractDetails> list) { ???for (ContractDetails data : list) { ????Contract contract = data.contract(); ???? ????if (contract.right() == Right.Put) { ?????m_putsModel.addRow( contract, m_snapshot.isSelected() ); ????} ????else { ?????m_callsModel.addRow( contract, m_snapshot.isSelected() ); ????} ???} ???m_putsModel.sort(); ???m_callsModel.sort(); ??} ?? ??private class ChainModel extends AbstractTableModel { ???Comparator<ChainRow> c = new Comparator<ChainRow>() { ????@Override public int compare(ChainRow o1, ChainRow o2) { ?????int rc = o1.m_c.lastTradeDateOrContractMonth().compareTo( o2.m_c.lastTradeDateOrContractMonth()); ?????if (rc == 0) { ??????if (o1.m_c.strike() < o2.m_c.strike()) { ???????rc = -1; ??????} ??????if (o1.m_c.strike() > o2.m_c.strike()) { ???????rc = 1; ??????} ?????} ?????return rc; ????} ???}; ??? ???ArrayList<ChainRow> m_list = new ArrayList<ChainRow>(); ??? ??????????? public void desubscribe() { ??????????????? for (ChainRow row : m_list) { ??????????????????? ApiDemo.INSTANCE.controller().cancelOptionMktData( row); ??????????????? } ??????????? } ??? ???@Override public int getRowCount() { ????return m_list.size(); ???} ???public void sort() { ????Collections.sort( m_list, c); ????fireTableDataChanged(); ???} ???public void addRow(Contract contract, boolean snapshot) { ????ChainRow row = new ChainRow( contract); ????m_list.add( row); ???? ????ApiDemo.INSTANCE.controller().reqOptionMktData(contract, "", snapshot, row); ???? ????if (snapshot) { ?????Util.sleep( 11); // try to avoid pacing violation at TWS ????} ???} ???@Override public int getColumnCount() { ????return m_snapshot.isSelected() ? 10 : 9; ???} ??? ???@Override public String getColumnName(int col) { ????switch( col) { ?????case 0: return "Last trade date"; ?????case 1: return "Strike"; ?????case 2: return "Bid"; ?????case 3: return "Ask"; ?????case 4: return "Imp Vol"; ?????case 5: return "Delta"; ?????case 6: return "Gamma"; ?????case 7: return "Vega"; ?????case 8: return "Theta"; ?????default: return null; ????} ???} ???@Override public Object getValueAt(int rowIn, int col) { ????ChainRow row = m_list.get( rowIn); ????switch( col) { ?????case 0: return row.m_c.lastTradeDateOrContractMonth(); ?????case 1: return row.m_c.strike(); ?????case 2: return fmtNz( row.m_bid); ?????case 3: return fmtNz( row.m_ask); ?????case 4: return fmtPct( row.m_impVol); ?????case 5: return fmtNz( row.m_delta); ?????case 6: return fmtNz( row.m_gamma); ?????case 7: return fmtNz( row.m_vega); ?????case 8: return fmtNz( row.m_theta); ?????case 9: return row.m_done ? "*" : null; ?????default: return null; ????} ???} ? ???private class ChainRow extends TopMktDataAdapter implements IOptHandler { ????Contract m_c; ????double m_bid; ????double m_ask; ????double m_impVol; ????double m_delta; ????double m_gamma; ????double m_vega; ????double m_theta; ????boolean m_done; ?? ????public ChainRow(Contract contract) { ?????m_c = contract; ????} ?? ????@Override public void tickPrice(TickType tickType, double price, int canAutoExecute) { ?????switch( tickType) { ??????case BID: ???????m_bid = price; ???????break; ??????case ASK: ???????m_ask = price; ???????break; ????????????????? default: break; ?????} ????} ?? ????@Override public void tickOptionComputation( TickType tickType, double impVol, double delta, double optPrice, double pvDividend, double gamma, double vega, double theta, double undPrice) { ?????if (tickType == TickType.MODEL_OPTION) { ??????m_impVol = impVol; ??????m_delta = delta; ??????m_gamma = gamma; ??????m_vega = vega; ??????m_theta = theta; ?????} ????} ???? ????@Override public void tickSnapshotEnd() { ?????m_done = true; ????} ???} ??} ?} } |
||||||||||||||||||
Re: how long does historical pull take?
great! thanks for update (updated faq)
?
D
On Wed, Dec 16, 2015 at 12:28 PM, orionn2 <no_reply@...> wrote:
?
-- §ã §é.§Ô§Ý.§å§Ó.,
§¥§Ú§Þ§Ñ §º. ?
|
||||||||||||||||||
Re: 5 sec. Bars
¿ªÔÆÌåÓýJust curious if real time bars make your own five min bars would produce same results as historical data request seconds after a five min bar ended.? I suspect in both cases it's the same from my experience only after the market closes does IB fill in the blanks but I'm curious if you think switching to creating your own five mins bars would produce better results than historicaldatarequest for that same five mins. Sent from my iPhone On Dec 17, 2015, at 7:36 PM, "Nick news1000@... [TWSAPI]" <TWSAPI@...> wrote:
|
||||||||||||||||||
Re: 5 sec. Bars
Nick
¿ªÔÆÌåÓýIf you want/need realtime data to match historical data as close as possible then realtime bars is the only choice.If you don't care about that you can use market data (ticks) or realtime volume (rtv). Those have less problems with data not arriving. Realtime bars often do not survive session changes so you should unsubscribe and re-subscribe if your app runs across sessions. On 12/17/2015 7:03 PM, ernst.tmp@...
[TWSAPI] wrote:
? |
||||||||||||||||||
Re: 5 sec. Bars
Hi souqmate,
thanks for your questions. It happened in the Real account. I did not subscribe to Realtime Ticks No SPY data appeared in the last 32 minutes. I did not look inside TWS to look for bars (I should have, thanks, that is a good idea!!!) I have not tried resubscribing, but I think than the bars would appear again. This is a good idea, I could program sth. that unsubscribes and subscribes the bars whenever there is no bar for more than 10 minutes during opening hours. But still I would have some gaps. Are similar problems appearing with realtime ticks, or would it make sense to use realtime ticks to create the bars ? Thanks, Ernst |
||||||||||||||||||
Re: 5 sec. Bars
Scary.? I don't use 5sec (realtime) bars.? Several questions come to mind:
Paper or real account? Did you also subscribe to realtime ticks, and did your api get any for SPY in the last 32 minutes? Did you try unsubscribing and re-subscribing ? Did your TWS show SPY ticks in the last 32 minutes? Did your try Ctrl-Alt-F in your TWS to refresh realtime data ? Would a second client get SPY 5sec bars when the first doesn't ? Gd luck SouqMate. ---In TWSAPI@..., <ernst.tmp@...> wrote : Hello, I have written a Java program to subscribe to the 5 sec. bars, but I had missing data, so I rewrote everything in Python, but I still have problems. For instance, 32 minutes before todays Close, SPY bars stopped appearing, while all the other 5 sec. bars (VIX,? QQQ, ...) where coming in. I contacted IB tech support about this problem, but they where of no help. Do you have any ideas? Thanks, Ernst |