简体   繁体   English

通过API'g错误ID = -1,errorCode = 2104,errorMsg = Market data farm连接正常时在Interactive Broker中获取错误:hfarm

[英]Getting Error in Interactive Broker while connectiong through API 'error id=-1, errorCode=2104, errorMsg=Market data farm connection is OK:hfarm

I keep getting the below errors while testing the below code. 在测试以下代码时,我不断收到以下错误。 I've a paper trading account with IB. 我在IB有一个模拟交易帐户。

Not sure what exactly these errors are. 不知道这些错误到底是什么。 Tried searching online but could not get any hint. 尝试过在线搜索,但没有任何提示。

 from ib.opt import Connection, message
from ib.ext.Contract import Contract as C
from ib.ext.Order import Order  
import time
def make_contract(symbol,sec_type,exch,prim_exch,curr):
    C.m_symbol=symbol
    C.m_secType=sec_type
    C.m_exch=exch
    C.m_primaryExch=prim_exch
    C.m_currency=curr
    return C

def make_order(action,quantity,price=None): 
    if price is not None:
        order=Order()
        order.m_orderType = 'LMT'
        order.m_totalQuantity = quantity
        order.m_action = action
        order.m_lmtprice = price
        print(price)

    else:
        order=Order()
        order.m_orderType = 'MKT'
        order.m_totalQuantity = quantity
        order.m_action = action
        print('hi')

    return order    

def handleAll(msg):
    print(msg)

cid = 103

conn = Connection.create(port=7497) #clietnID=888)  
conn.connect()
conn.registerAll(handleAll)
oid = cid
cont = make_contract('AAPL','STK', 'SMART','SMART', 'USD')
offer = make_order('BUY', 1, 157)

    conn.placeOrder(oid,cont,offer)

while 1:
        time.sleep(1)

That's not really an error, just information saying you're connected to market data. 这并不是真正的错误,只是信息表明您已连接到市场数据。 However, the conn.disconnect() disconnects before you can do anything. 但是,conn.disconnect()会在执行任何操作之前断开连接。

Also the primary exchange for AAPL is not SMART. 同样,AAPL的主要交换不是SMART。 You don't need to put one except in rare cases where the symbol is ambiguous and it's never SMART. 您不需要放一个,除非在极少数情况下该符号是含糊不清的,并且永远不是SMART。

Please add if __name__ == "__main__": in order to run order placing smoothly. if __name__ == "__main__":请添加if __name__ == "__main__":为了顺利进行订单下达。 By the way, the primary exchange for AAPL is not SMART, you may leave it empty as '' for the most of US stocks. 顺便说一句,对于AAPL主交换机不聪明,你可以把它作为空''为最美股。

from ib.opt import Connection, message
from ib.ext.Contract import Contract
from ib.ext.Order import Order
import time

def make_contract(symbol, sec_type, exch, prim_exch, curr):

    Contract.m_symbol = symbol
    Contract.m_secType = sec_type
    Contract.m_exchange = exch
    Contract.m_primaryExch = prim_exch
    Contract.m_currency = curr
    return Contract


def make_order(action,quantity, price = None):

    if price is not None:
        order = Order()
        order.m_orderType = 'LMT'
        order.m_totalQuantity = quantity
        order.m_action = action
        order.m_lmtPrice = price

    else:
        order = Order()
        order.m_orderType = 'MKT'
        order.m_totalQuantity = quantity
        order.m_action = action


    return order


cid = 103

def handleAll(msg):
    print(msg)

if __name__ == "__main__":

    conn = Connection.create(port=4002, clientId=103)
    conn.connect()
    conn.registerAll(handleAll)
    oid = cid
    cont = make_contract('AAPL', 'STK', 'SMART', 'ISLAND', 'USD')
    offer = make_order('BUY', 1, 200)
    conn.placeOrder(oid, cont, offer)
    time.sleep(1)
    conn.disconnect()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM