簡體   English   中英

IBpy python結構查詢

[英]IBpy python structure query

嗨,大家好我不是一個訓練有素的編碼人員,但是我想找出這個問題,請您告訴我如何解決此錯誤?

按照下面我試圖構造代碼,底部顯示一個錯誤

from __future__ import print_function #I'm using 3.x style print
from ib.opt import ibConnection, message
from ib.ext.Contract import Contract
from ib.ext.TickType import TickType as tt
from time import sleep
import pandas as pd

class account_update :
   acc_info = [999] # list to store all your account info

def updateAccount_handler(self,msg):
       if msg.key in ['AccountType','NetLiquidation']:
           self.acc_info.append(msg.key, msg.value)

def error_handler(msg):
    print (msg)

def my_callback_handler(msg):
    if msg.field in [tt.BID,tt.ASK,tt.LAST]:
        #now we can just store the response in the data frame
        contracts.loc[msg.tickerId,tt.getField(msg.field)] = msg.price
        if msg.field == tt.LAST:
            print(contracts.loc[msg.tickerId,'sym'],msg.price)

def main(self):
  conn = Connection.create(port=7497, clientId = 93
  conn.connect()

  conn.register(error_handler, 'Error')
  conn.register(updateAccount_handler,message.updateAccountValue)

  conn.reqAccountUpdates(1,"Uxxxx008")
  time.sleep(0.5)

  conn.disconnect()            



tws = ibConnection(clientId=999)
tws.register(my_callback_handler, message.tickPrice, message.tickSize)
tws.register(error_handler, 'Error')
tws.connect()

contracts = pd.DataFrame([
        ['IBM','SMART','USD'],
        ['AAPL','SMART','USD'],
        ['GOOG','SMART','USD'],
        ['ES','GLOBEX','USD','201609','50'],
        ['CL','NYMEX','USD','201609','1000']
])

# make decent column names
contracts.columns = ['sym','exch','curr','expiry','mult']

#add these specific column names to match the name returned by TickType.getField()
contracts['bidPrice'] = 0
contracts['askPrice'] = 0
contracts['lastPrice'] = 0

for index, row in contracts.iterrows():
    c = Contract()
    c.m_symbol = row['sym']
    c.m_exchange = row['exch']
    c.m_currency = row['curr']
    c.m_secType = 'STK' if row['expiry'] is None else 'FUT'
    c.m_expiry = row['expiry']
    c.m_multiplier = row['mult']
    # the tickerId is just the index in but for some reason it needs str()
    tws.reqMktData(str(index),c,"",False)

if __name__ == "__main__" :
     account_update().main()          

我得到這個錯誤

Server Version: 76
TWS Time at connection:20160810 20:50:31 SGT
<error id=-1, errorCode=2104, errorMsg=Market data farm connection is OK:usfarm>
<error id=-1, errorCode=2106, errorMsg=HMDS data farm connection is OK:ushmds.us>
<error id=-1, errorCode=2106, errorMsg=HMDS data farm connection is OK:ushmds>
Traceback (most recent call last):
  File "C:\Python Learning\Models\Python Livedata", line 72, in <module>
    account_update().main()           
AttributeError: account_update instance has no attribute 'main'
[Finished in 1.3s]

此消息表示連接正常。 每次運行代碼時,都必須更改clientid。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM