Python Code Example

I was able to make your code work with some modification and got an education in abstract classes in the process. I almost forgot C++ rules.

But I have two questions regarding that:
(1) I am still not able to save the position information in a variable
(2) reqAccountUpdates seems updates account information every 3 min (based on a google group thread). How do I make it update only once and stop.
Code:
def updatePortfolio(self, contract, position, marketPrice, marketValue, averageCost, unrealizedPNL, realizedPNL, accountName):
           self.myvariable = position

Code:
def cxlAccountUpdates(self):
       self.connection.reqAccountUpdates(False,"DU666")

PM me. I will write it for you
 
Good news: I was able to successfully install swigibipy on home machine and I am working through your example
hi globalarbtrader your website has been a great reading example. I am learning Python also and it's fun.

I was running your script using a code I created for myself:

  1. ibcontract = IBcontract()
  2. ibcontract.secType = "OPT"
  3. ibcontract.expiry = "20160115"
  4. ibcontract.symbol = "MSFT"

  5. ans = client.get_IB_market_data(ibcontract)

However, inside wrapper_v3.py I get error:
line 212, in get_IB_market_data
self.cb.init_tickdata(tickerid)
AttributeError: 'IBWrapper' object has no attribute 'init_tickdata'

Can you provide some hints regarding this ?
 
hi globalarbtrader your website has been a great reading example. I am learning Python also and it's fun.

I was running your script using a code I created for myself:

  1. ibcontract = IBcontract()
  2. ibcontract.secType = "OPT"
  3. ibcontract.expiry = "20160115"
  4. ibcontract.symbol = "MSFT"

  5. ans = client.get_IB_market_data(ibcontract)

However, inside wrapper_v3.py I get error:
line 212, in get_IB_market_data
self.cb.init_tickdata(tickerid)
AttributeError: 'IBWrapper' object has no attribute 'init_tickdata'

Can you provide some hints regarding this ?

First of all I assume that test3_IB works okay ( you should always check the official test code works before trying to modify it yourself). It would probably be be easier if you started with the test code and modified it rather than writing your own from scratch.

You must be missing some code. Can you give me *all* the code in your script up to this point (i.e. how do you define 'client') plus the full traceback when it fails. Can you also give me the results of running dir(client) and dir(client.cb)

GAT
 
Hi globalarbtrader

I played around more with your code and seems like test3_IB works great in pulling historical data for futures.

It however gives error when I try the following
  1. ibcontract2 = IBcontract()
  2. ibcontract2.secType = "STK"
  3. ibcontract2.symbol="MSFT"
  4. ans2=client.get_IB_historical_data(ibcontract2)
  5. print ans2

  6. ibcontract3 = IBcontract()
  7. ibcontract2.secType = "OPT"
  8. ibcontract2.expiry="20160219"
  9. ibcontract2.symbol="MSFT"
  10. ans3=client.get_IB_historical_data(ibcontract3)
  11. print ans3
I am wondering what the required fields when I want to pull the option and stock historical data.
 
Hi globalarbtrader

I played around more with your code and seems like test3_IB works great in pulling historical data for futures.

It however gives error when I try the following
  1. ibcontract2 = IBcontract()
  2. ibcontract2.secType = "STK"
  3. ibcontract2.symbol="MSFT"
  4. ans2=client.get_IB_historical_data(ibcontract2)
  5. print ans2

  6. ibcontract3 = IBcontract()
  7. ibcontract2.secType = "OPT"
  8. ibcontract2.expiry="20160219"
  9. ibcontract2.symbol="MSFT"
  10. ans3=client.get_IB_historical_data(ibcontract3)
  11. print ans3
I am wondering what the required fields when I want to pull the option and stock historical data.
Probably the exchange and strike respectively. But I hope someone else can tell you for sure as I don't trade these
 
First of all I assume that test3_IB works okay ( you should always check the official test code works before trying to modify it yourself). It would probably be be easier if you started with the test code and modified it rather than writing your own from scratch.

You must be missing some code. Can you give me *all* the code in your script up to this point (i.e. how do you define 'client') plus the full traceback when it fails. Can you also give me the results of running dir(client) and dir(client.cb)

GAT

Hello GAT,

I was wondering how you determine in IB if a market is closed? What specific things do you look for. For example when I query the BBO for a closed market it gives me negative prices. Is this consistent for a closed market? Is it a reliable?
 
Hello GAT,

I was wondering how you determine in IB if a market is closed? What specific things do you look for. For example when I query the BBO for a closed market it gives me negative prices. Is this consistent for a closed market? Is it a reliable?

I don't know if this is reliable. My code checks for zero or negative prices, and treats them the same - as an 'untradeable' market. I don't care if a market is closed, or just happens to have no liquidity at that moment.

GAT
 
Back
Top