Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/372.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
交互式代理Java API不从historicalData返回任何内容_Java_Api_Interactive Brokers - Fatal编程技术网

交互式代理Java API不从historicalData返回任何内容

交互式代理Java API不从historicalData返回任何内容,java,api,interactive-brokers,Java,Api,Interactive Brokers,假设下面的代码将返回并打印历史市场数据列表,如开盘、收盘、高位、低位、成交量。与交互式代理API的连接应该良好。但在Java控制台中,它没有打印回调中的市场数据。看起来它没有通过historicalData函数。如何激活该功能并将市场数据存储在对象中 id 1 -1 2104 Market data farm connection is OK:usfarm.nj -1 2104 Market data farm connection is OK:cashfarm -1 2104 Market d

假设下面的代码将返回并打印历史市场数据列表,如开盘、收盘、高位、低位、成交量。与交互式代理API的连接应该良好。但在Java控制台中,它没有打印回调中的市场数据。看起来它没有通过historicalData函数。如何激活该功能并将市场数据存储在对象中

id 1
-1 2104 Market data farm connection is OK:usfarm.nj
-1 2104 Market data farm connection is OK:cashfarm
-1 2104 Market data farm connection is OK:usfarm
-1 2106 HMDS data farm connection is OK:cashhmds
-1 2106 HMDS data farm connection is OK:hkhmds
-1 2106 HMDS data farm connection is OK:ushmds
-1 2158 Sec-def data farm connection is OK:secdefil
...
示例代码:

    void run() {
        m_client.eConnect("localhost", 7497, 123);
        final EReader reader = new EReader(m_client, m_signal);
        reader.start();
        new Thread() {
            @Override
            public void run() {
                while (m_client.isConnected()) {
                    m_signal.waitForSignal();
                    try {
                        reader.processMsgs();
                    } catch (Exception e) {
                        System.out.println("Exception: " + e.getMessage());
                    }
                }
            }
        }.start();

        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    @Override
    public void nextValidId(int orderId) {
        System.out.println("id "+orderId);
        nextOrderID = orderId;
        //Contract c = new StkContract("AAPL");
        Contract c = new Contract();
        c.symbol("EUR");
        c.exchange("IDEALPRO");
        c.secType("CASH");
        c.currency("USD");

        m_client.reqHistoricalData(1, c, 
                LocalDate.now().format(DateTimeFormatter.BASIC_ISO_DATE)+ " 16:00:00",
                "1 D", "1 min", "MIDPOINT", 1, 1, false, null);
        m_client.reqMktData(1, c, "", false, false, null);
    }

    @Override
    public void error(int id, int errorCode, String errorMsg) {
        System.out.println(id + " " + errorCode + " " + errorMsg);
    }

    @Override
    public void historicalData(int reqId, String date, double open, double high, double low, double close, int volume, int count, double WAP, boolean hasGaps) {
        //if being run on the next calendar day, this works
        if (LocalDate.now().minusDays(1).format(DateTimeFormatter.BASIC_ISO_DATE).equals(date)){
            this.date = date;
            this.high = high;
            this.low = low;
            this.open = open;
            this.close = close;
            System.out.println(date + " h: " + high + " l: " +low);
        }
        System.out.println("Requesting Data...");
        System.out.println(EWrapperMsgGenerator.historicalData(reqId, date, open, high, low, close, volume, count, WAP));
        System.out.println("Data Input Ended...");
    }

确保api日志记录在configure->api->settings选项卡中打开,您应该可以看到来回发送到TWS的所有内容。我曾尝试查看C:\Jts目录下的api日志记录,但其中不包含历史数据源的详细信息。我假设historicalData函数根本不运行来打印OHLC数据。您可以看到,如果请求被记录,它将看起来像
hh:mm:ss.sss 17
,17是历史数据回复的数字。确保在配置->api->设置选项卡中打开api日志记录,您应该可以看到来回发送到TWS的所有内容。我已经尝试过了查看C:\Jts目录下的api日志记录,但其中不包含历史数据源的详细信息。我假设historicalData函数根本不运行来打印OHLC数据。您可以看到,如果请求被记录,它将看起来像
hh:mm:ss.sss 17
,17是历史数据回复的数字。