¿ªÔÆÌåÓý

ctrl + shift + ? for shortcuts
© 2025 Groups.io
Date

Re: Marketdata Options Python

 

This option trades on multiple exchanges (see??) so try to replace SMART with a specific exchange name (e.g. "CBOE").


Marketdata Options Python

 

¿ªÔÆÌåÓý

?

Hello,

?

I simply want to get Marketdata for Options from the tws.

I tryed this code, but it always gives me the errorcode ?200¡° and says:

200

The contract description specified for VIAC is ambiguous.

?

Do you know what is wrong?

?

?

Thanks, Philipp

?

Code:

?

import ibapi

from ibapi.client import EClient

from ibapi.wrapper import EWrapper

#

from ibapi.contract import Contract

from ibapi.order import *

import threading

import time

?

#class for Interacite Vrokers Conneciton

class IBApi(EWrapper, EClient):

??? def __init__(self):

??????? EClient.__init__(self, self)

???? #Listen for Realtime Bars

??? def realtimeBar(self, reqID, time, open_, high, low, close, volume, wap, count):

??????? super().realtimeBar(self, reqID, time, open_, high, low, close, volume, wap, count)

??????? try:

??????????? bot.on_bar_update( reqID, time, open_, high, low, close, volume, wap, count)

??????? except Exception as e:

??????????? print(e)

??? def error(self, id, errorCode, errorMsg):

??????? print(errorCode)

??????? print(errorMsg)

???????

#Bot Logic

class Bot:

??? ib=None

??? def __init__(self):

??????? #connect to IB on init

??????? self.ib=IBApi()

??????? self.ib.connect("127.0.0.1", 7496,13)

??????? ib_thread=threading.Thread(target=self.run_loop, daemon=True)

??????? ib_thread.start()

??????? time.sleep(1)

??????? #get symbol info

??????? symbol=input("Enter the symbol you want to trade:")

??????? #create our IB Contract Object

??????? contract=Contract()

??????? contract.symbol=symbol.upper()

??????? contract.secType="OPT"

??????? contract.exchange="SMART"

??????? contract.currency="USD"

??????? contract.LastTradeDateOrContractMonth="20210618"

??????? contract.strike=38.5

??????? contract.right = "PUT"

??????? contract.multiplier="100"

??????? contract.tradingClass="VIAC"

??????? # Reqeust Market Data

??????? self.ib.reqRealTimeBars(0, contract,5, "TRADES", 1, [])

????

???????

????#listen to secket in sepreate thread

???????

????def run_loop(self):

??????? self.ib.run()

???

????#Pass realtime bar daata back to our obt object

??? def on_bar_update(self, reqID, time, open_, high, low, close, volume, wap, count):

??????? print(close)

???????

#Start Bot

bot=Bot()

?

?


Total Automation

Stuart Cracraft
 

Hi Everybody,

It¡¯s nice to see something emotionless.

Happy to report that the first fully automated money trade happened today (for entry at the open tomorrow as I do EOD analysis and market open trades with IB.)

I reduced my portfolio risk level by removing a couple of the high-beta items from the list which my friend had wanted. Gave him his own separate list.

Any arbitrary list is automatable. I just went for a mostly low-beta list as I am not fond of 100% exposure in the market due to the overnight gremlins.

The current list is quite vanilla except for Ethereum which, oddly, trades quite well (for me).

DIA
IWM
EEM
SPY
ETHE
QQQ

Cash is a legitimate position and the portfolio holds it.

A smallish current total ($17k) but it definitely is eating one¡¯s own dog food.

Can be entirely in some subset (or all, or none) of the above positions.

The thing actually got me out 100% as we hit the colonial pipeline / april inflation number / iron dome crisis and kept me out.

:-)

Stuart

P.S. Thanks to this group for facilitating this earlier in the year. Growing rather fond of IB actually.


Any C++ scanner code posted?

 

Hi,

Does anyone have their working scanner code posted somewhere (in C++)?

Thanks,


Re: Option BID/ASK and GREEKS

 

Perfect, Thank you - that fixed it!


Re: Since Today, scanner not working

 

OK, so today I'm pretty sure IBA upgraded the stable version of TWS and along with it, introduced this bug that was in the 'LATEST' version since way back in Jan.? They were informed of this error and didn't take ANY steps to remove it before making it a stable version.? I am really unimpressed with IBA.

So now what?? I have to find a way to downgrade?? There must be a better solution.? Maybe IBA is removing the marketCap filter on purpose?? If true, a statement from IBA would have been nice.
---


Re: Option BID/ASK and GREEKS

 

To receive the last available data from the markets after they have closed you need to switch to ¡®frozen¡¯ data.



with reqMarketDataType(2)


Option BID/ASK and GREEKS

 

The API is returning some sparce values - but they do not match TWS.
I am testing this over the weekend on live account - so I was expecting to receive values from Friday.
Below is my current test code.

Contract Test = new Contract();
Test.Symbol = "SPY";
Test.SecType = "OPT";
Test.Exchange = "SMART";
Test.LastTradeDateOrContractMonth = "20210609";
Test.Right = "P";
Test.Strike = 422;
?
ClientSocket.reqMktData(201, Test, "", true, false, null);
?
I also tried using false for snapshot
ClientSocket.reqMktData(201, Test, "", false, false, null);
?
The resulting Price does NOT match anything I can see related to the option
"EWrapperImpl.tickPrice() tickerId: 201, Field: 9, Price: 4.26"
The BID and ASK prices (below) do not match the values within TWS OptionTrader
"EWrapperImpl.tickPrice() tickerId: 201, Field: 0, Size: 0"
"EWrapperImpl.tickPrice() tickerId: 201, Field: 2, Price: -1"
?
Also, only ONE single time EWrapperImpl.tickOptionComputation() resulted with all the greeks.
Subsequent attempts over several hours did not produce greek results ever again - just regular tickPrice() results.

Thank you for any help.


Re: maintenance? outage?

Pankaj Agarwal
 

this is the message that i see on login page ...

Weekend Maintenance:?We will be performing system maintenance on?Saturday,?June 5th?between?9:00 AM?and?1:00 PM?New York time. At some points during this window you may be unable to access your account or related services. Please refer to our??during this period for the most current information regarding system availability.


On Sat, Jun 5, 2021 at 10:08 AM Stuart Cracraft via <smcracraft=[email protected]> wrote:
Hi,

I tried to login to at about 705am California time
but couldn¡¯t get in as a variety of accounts failed. Both regular and paper.

Are maintenance/outages listed somewhere?

What is the URL of the status dashboard for interactivebrokers?

Stuart







Re: maintenance? outage?

Nick
 

Sorry, I meant 6pm eastern on Sunday.

On 6/5/2021 11:22 AM, Nick wrote:
Things are back to normal by 6pm eastern since that's when futures markets open.


Re: maintenance? outage?

Nick
 

IB sometimes does extended maintenance over the weekend, I don't think they announce it ahead of time. Sometimes you will be able to connect over the weekend and sometimes not.

Things are back to normal by 6pm eastern since that's when futures markets open.

On 6/5/2021 10:08 AM, Stuart Cracraft via groups.io wrote:
Hi,

I tried to login to interactivebrokers.com at about 705am California time
but couldn¡¯t get in as a variety of accounts failed. Both regular and paper.

Are maintenance/outages listed somewhere?

What is the URL of the status dashboard for interactivebrokers?

Stuart






Re: TWS Historical Options Data - Python API code

 

My eyes hurt, during inspection of this piece of spaghetti code.
How do you manage to find any unexpected behavior? Any tests?


Re: maintenance? outage?

Stuart Cracraft
 

Here it be:

On Jun 5, 2021, at 7:08 AM, Stuart Cracraft via groups.io <smcracraft@...> wrote:

Hi,

I tried to login to interactivebrokers.com at about 705am California time
but couldn¡¯t get in as a variety of accounts failed. Both regular and paper.

Are maintenance/outages listed somewhere?

What is the URL of the status dashboard for interactivebrokers?

Stuart






maintenance? outage?

Stuart Cracraft
 

Hi,

I tried to login to interactivebrokers.com at about 705am California time
but couldn¡¯t get in as a variety of accounts failed. Both regular and paper.

Are maintenance/outages listed somewhere?

What is the URL of the status dashboard for interactivebrokers?

Stuart


Re: TWS Historical Options Data - Python API code

Nishant Verma
 

On Thu, Jun 3, 2021 at 02:35 AM, <wardloving@...> wrote:
Thanks for sharing the link. Will it download the options historical data with different expiry along with delta/theta etc ?


Re: TWS vs Gateway at reconnections

GUY
 

Hello everyone

I have been French and computer scientist for over 30 years. I am 72 years old and I have been using python for 6 months. I have developed an API to process the eurusd. When you are French, you absolutely have to preserve your euro capital? This is what my API does. I also ran into the shutdown of TWS. To remedy this, check the automatic restart box in the general configuration from "modification", "lock and exit" and specify the time for the automatic restart.

You should know that IB reboots its servers at 0am US time, ie 6am French time. It is therefore necessary to program the automatic restart after 0 hours to allow the reboots to take place. But this is not enough if you have an API that works 24 hours a day, you have to restart your API also automatically AFTER the TWS reboot. For that I use a DOS .bat to restart

. I hope I answered the question

Good weekend to all

cordially

Guy

?

?

?

?

> Message du 02/06/21 21:46
> De : "RobDawg35" <rob.sandberg26@...>
> A : "[email protected] Group Moderators" <[email protected]>
> Copie ¨¤ :
> Objet : Re: [TWS API] TWS vs Gateway at reconnections
>
>
Hi all,?

>
I have also had this problem and am currently switching to run this on a server. I am going to be paying around $20-40/month.?

>
I am in-between using "VULTR" or spinning up an EC2 instance then creating a UI for Linux on the server.?

>
Best,
Rob

>
On Wed, Jun 2, 2021 at 12:32 AM Despair <boris@...> wrote:
>
The problem is not the reconnection to the API. The problem is the TWS shuts down completely. So I have to restart the TWS manually before the client can connect to it again.

>

>


Need help debugging an issue getting market data

 

Hi,

I am using reqMktData to retrieve real-time bid/ask data on SPX vertical spreads.? I am making one request at a time and I am using a timeout of 10 seconds.? Whether I get something back or time-out, I call cancelMktData before I move to the next request.? I don't have a large number of spreads I am requesting data on, but I do want refresh data every 5 - 10 seconds so I plan on adding some parallelism to this.? At the moment, I just want to make sure my basic code is functioning correctly.? The problem I am having is that when I run my code, I don't always get a response on a spread.? There is no error message and I am quite certain I am not running into the 50 request per second limitation or the default 100 market lines limitation.? How can I go about figuring out why I am not getting any response?? Spreads I am interested in are near dated and close to ATM so it can't be a lack of bids or asks and it's not that I don't get data at all.? I make a batch of requests (serially, no concurrent requests), wait 5 seconds and go through the same batch again and some of the spreads will have responses in one run and some of them won't have responses in a subsequent run and I never get any error messages when this happens.? Thanks for reading and I would appreciate any suggestions or tips for debugging this issue.


how many minutes or seconds early, before Market Starts, to subscribe to reqRealTimeBars(). while subscribing for multiple instruments

 

Hi all,

To get live 5-second real time bars, from the beginning of market
how early to subscribe (considering number of instruments) just before market starts, for reqRealTimeBars()?

If reqRealTimeBars() invoked well before, say 2-3 minutes before market start time,
they don't respond once market starts

If reqRealTimeBars() invoked just before, say 1 minute before market start time, NOT all instruments gets subscribed,
that leads to few instruments failed to get the 1st bar, once market opens

so just like reqMktData() which has
"11 seconds delay to subscribe for real time prices for a symbol is by design" for any number of instruments

Query 1:
any time limit available for subscription of reqRealTimeBars() for multiple instruments

Thanks


Query 2:
For indices which are not traded as such,
is there a way to get ohlc like data via reqTickers() or reqMktData()
[tried, reqMktData(), genericTicks to get tick types using genericTickList='6, 7, 8, 9, 14' , but getting only ticktype 1 & 2]


Re: Limit on how far back historical tick-by-tick

 

Speaking from my experience with trade ticks for stocks, it's typically about 36 months or a bit more. However it can be much less in some issues.

§á§ä, 4 §Ú§ð§ß. 2021 §Ô., 03:47 ebtrader <jsiddique@...>:

Is there a limit to how far back you can go for historical tick-by-tick?


Limit on how far back historical tick-by-tick

 

Is there a limit to how far back you can go for historical tick-by-tick?