使用Interactive Broker的C#API访问基础数据

时间:2017-11-27 11:11:05

标签: interactive-brokers

我一直在尝试使用C#API访问HOng Kong Stock Fundamental Data。 一些背景:

我尝试使用相同的程序访问香港股票市场数据,它正在运作,如下:

namespace IB_Real_time_Console_CS
{
    class Program
    {
        static void Main(string[] args)
        {
            Samples.EWrapperImpl ibClient = new Samples.EWrapperImpl();
            ibClient.ClientSocket.eConnect("", 7496, 0);
            var reader = new EReader(ibClient.ClientSocket, ibClient.Signal);
            reader.Start();
            new Thread(() =>
            {
                while (ibClient.ClientSocket.IsConnected())
                {
                    ibClient.Signal.waitForSignal();
                    reader.processMsgs();
                }
            })
            { IsBackground = true }.Start();
            while (ibClient.NextOrderId <= 0) { }

            Contract contract = new Contract();
            contract.Symbol = "700";
            contract.SecType = "STK";
            contract.Exchange = "SEHK";
            contract.Currency = "HKD";

            List<TagValue> mktDataOptions = new List<TagValue>();
ibClient.ClientSocket.reqMktData(1, contract, "", true, false, mktDataOptions);

            // Pause so we can view the output
            Console.ReadKey();

            ibClient.ClientSocket.cancelMktData(1);
            ibClient.ClientSocket.eDisconnect();


        }   //end Main
    }       //end class Program
}           //end namespace IB_Real_time_console_cs

我的目标是访问基础数据。所以我更改了这行代码: ibClient.ClientSocket.reqMktData(1, contract, "", true, false, mktDataOptions);

进入: ibClient.ClientSocket.reqMktData(1, contract, "258", true, false, mktDataOptions);

但是我遇到了以下错误:

Error ID:-1 code:2104: Msg: Market data farm connection is OK:hfarm
Error ID:-1 code:2104: Msg: Market data farm connection is OK:usfuture
Error ID:-1 code:2104: Msg: Market data farm connection is OK:cashfarm
Error ID:-1 code:2104: Msg: Market data farm connection is OK:usfarm

Error ID:-1 code:2106: Msg: HMDS data farm connection is OK:ushmds.us
Error ID:-1 code:2106: Msg: HMDS data farm connection is OK:hkhmds
Error ID:-1 code:2106: Msg: HMDS data farm connection is OK:fundfarm
Error ID:-1 code:2106: Msg: HMDS data farm connection is OK:ushmds
  

错误ID:1,代码321,消息:验证请求时出错: - &#39; bo&#39;:原因快照市场数据订阅不适用于通用滴答

Error ID:-1 code 2108, Msg: Market data farm connection is inactive but should be available upon demand.usfuture
Error ID:-1 code 2108, Msg: Market data farm connection is inactive but should be available upon demand.usfuture
Error ID:-1 code 2108, Msg: Market data farm connection is inactive but should be available upon demand.cashfarm
Error ID:-1 code 2108, Msg: Market data farm connection is inactive but should be available upon demand.cashfarm

任何人都可以指出这个代码更改有什么问题吗? 或者,如何访问基础数据? 非常感谢..

1 个答案:

答案 0 :(得分:1)

读取您的错误,其中大多数只是关于连接的信息,我突出显示的问题告诉您。你要快照而你不被允许。第4个arg是bool snapshot,将其设置为false。

void reqMktData (   int     tickerId,
    Contract    contract,
    string  genericTickList,
    bool    snapshot,
    bool    regulatorySnaphsot,
    List< TagValue >    mktDataOptions 
)       

ibClient.ClientSocket.reqMktData(1, contract, "258", false, false, mktDataOptions);