⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 eclientsocket.java

📁 网上期货交易的外挂原码,可实现自动交易功能,自动添加模块
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                    double upper = order.m_orderType.equals("VOL") ? order.m_stockRangeUpper : Double.MAX_VALUE;                    sendMax(lower);                    sendMax(upper);                }                sendMax(order.m_referencePriceType);            }            if (m_serverVersion >= 30) { // TRAIL_STOP_LIMIT stop price                sendMax(order.m_trailStopPrice);            }        } catch (Exception e) {            error(id, EClientErrors.FAIL_SEND_ORDER, "" + e);            close();        }    }    public synchronized void reqAccountUpdates(boolean subscribe, String acctCode) {        // not connected?        if (!m_connected) {            error(EClientErrors.NO_VALID_ID, EClientErrors.NOT_CONNECTED, "");            return;        }        final int VERSION = 2;        // send cancel order msg        try {            send(REQ_ACCOUNT_DATA);            send(VERSION);            send(subscribe);            // Send the account code. This will only be used for FA clients            if (m_serverVersion >= 9) {                send(acctCode);            }        } catch (Exception e) {            error(EClientErrors.NO_VALID_ID, EClientErrors.FAIL_SEND_ACCT, "" + e);            close();        }    }    public synchronized void reqExecutions(ExecutionFilter filter) {        // not connected?        if (!m_connected) {            error(EClientErrors.NO_VALID_ID, EClientErrors.NOT_CONNECTED, "");            return;        }        final int VERSION = 2;        // send cancel order msg        try {            send(REQ_EXECUTIONS);            send(VERSION);            // Send the execution rpt filter data            if (m_serverVersion >= 9) {                send(filter.m_clientId);                send(filter.m_acctCode);                // Note that the valid format for m_time is "yyyymmdd-hh:mm:ss"                send(filter.m_time);                send(filter.m_symbol);                send(filter.m_secType);                send(filter.m_exchange);                send(filter.m_side);            }        } catch (Exception e) {            error(EClientErrors.NO_VALID_ID, EClientErrors.FAIL_SEND_EXEC, "" + e);            close();        }    }    public synchronized void cancelOrder(int id) {        // not connected?        if (!m_connected) {            error(EClientErrors.NO_VALID_ID, EClientErrors.NOT_CONNECTED, "");            return;        }        final int VERSION = 1;        // send cancel order msg        try {            send(CANCEL_ORDER);            send(VERSION);            send(id);        } catch (Exception e) {            error(id, EClientErrors.FAIL_SEND_CORDER, "" + e);            close();        }    }    public synchronized void reqOpenOrders() {        // not connected?        if (!m_connected) {            error(EClientErrors.NO_VALID_ID, EClientErrors.NOT_CONNECTED, "");            return;        }        final int VERSION = 1;        // send cancel order msg        try {            send(REQ_OPEN_ORDERS);            send(VERSION);        } catch (Exception e) {            error(EClientErrors.NO_VALID_ID, EClientErrors.FAIL_SEND_OORDER, "" + e);            close();        }    }    public synchronized void reqIds(int numIds) {        // not connected?        if (!m_connected) {            error(EClientErrors.NO_VALID_ID, EClientErrors.NOT_CONNECTED, "");            return;        }        final int VERSION = 1;        try {            send(REQ_IDS);            send(VERSION);            send(numIds);        } catch (Exception e) {            error(EClientErrors.NO_VALID_ID, EClientErrors.FAIL_SEND_CORDER, "" + e);            close();        }    }    public synchronized void reqNewsBulletins(boolean allMsgs) {        // not connected?        if (!m_connected) {            error(EClientErrors.NO_VALID_ID, EClientErrors.NOT_CONNECTED, "");            return;        }        final int VERSION = 1;        try {            send(REQ_NEWS_BULLETINS);            send(VERSION);            send(allMsgs);        } catch (Exception e) {            error(EClientErrors.NO_VALID_ID, EClientErrors.FAIL_SEND_CORDER, "" + e);            close();        }    }    public synchronized void cancelNewsBulletins() {        // not connected?        if (!m_connected) {            error(EClientErrors.NO_VALID_ID, EClientErrors.NOT_CONNECTED, "");            return;        }        final int VERSION = 1;        // send cancel order msg        try {            send(CANCEL_NEWS_BULLETINS);            send(VERSION);        } catch (Exception e) {            error(EClientErrors.NO_VALID_ID, EClientErrors.FAIL_SEND_CORDER, "" + e);            close();        }    }    public synchronized void setServerLogLevel(int logLevel) {        // not connected?        if (!m_connected) {            error(EClientErrors.NO_VALID_ID, EClientErrors.NOT_CONNECTED, "");            return;        }        final int VERSION = 1;        // send the set server logging level message        try {            send(SET_SERVER_LOGLEVEL);            send(VERSION);            send(logLevel);        } catch (Exception e) {            error(EClientErrors.NO_VALID_ID, EClientErrors.FAIL_SEND_SERVER_LOG_LEVEL, "" + e);            close();        }    }    public synchronized void reqAutoOpenOrders(boolean bAutoBind) {        // not connected?        if (!m_connected) {            error(EClientErrors.NO_VALID_ID, EClientErrors.NOT_CONNECTED, "");            return;        }        final int VERSION = 1;        // send req open orders msg        try {            send(REQ_AUTO_OPEN_ORDERS);            send(VERSION);            send(bAutoBind);        } catch (Exception e) {            error(EClientErrors.NO_VALID_ID, EClientErrors.FAIL_SEND_OORDER, "" + e);            close();        }    }    public synchronized void reqAllOpenOrders() {        // not connected?        if (!m_connected) {            error(EClientErrors.NO_VALID_ID, EClientErrors.NOT_CONNECTED, "");            return;        }        final int VERSION = 1;        // send req all open orders msg        try {            send(REQ_ALL_OPEN_ORDERS);            send(VERSION);        } catch (Exception e) {            error(EClientErrors.NO_VALID_ID, EClientErrors.FAIL_SEND_OORDER, "" + e);            close();        }    }    public synchronized void reqManagedAccts() {        // not connected?        if (!m_connected) {            error(EClientErrors.NO_VALID_ID, EClientErrors.NOT_CONNECTED, "");            return;        }        final int VERSION = 1;        // send req FA managed accounts msg        try {            send(REQ_MANAGED_ACCTS);            send(VERSION);        } catch (Exception e) {            error(EClientErrors.NO_VALID_ID, EClientErrors.FAIL_SEND_OORDER, "" + e);            close();        }    }    public synchronized void requestFA(int faDataType) {        // not connected?        if (!m_connected) {            error(EClientErrors.NO_VALID_ID, EClientErrors.NOT_CONNECTED, "");            return;        }        // This feature is only available for versions of TWS >= 13        if (m_serverVersion < 13) {            error(EClientErrors.NO_VALID_ID, EClientErrors.UPDATE_TWS.code(), EClientErrors.UPDATE_TWS.msg());            return;        }        final int VERSION = 1;        try {            send(REQ_FA);            send(VERSION);            send(faDataType);        } catch (Exception e) {            error(faDataType, EClientErrors.FAIL_SEND_FA_REQUEST, "" + e);            close();        }    }    public synchronized void replaceFA(int faDataType, String xml) {        // not connected?        if (!m_connected) {            error(EClientErrors.NO_VALID_ID, EClientErrors.NOT_CONNECTED, "");            return;        }        // This feature is only available for versions of TWS >= 13        if (m_serverVersion < 13) {            error(EClientErrors.NO_VALID_ID, EClientErrors.UPDATE_TWS.code(), EClientErrors.UPDATE_TWS.msg());            return;        }        final int VERSION = 1;        try {            send(REPLACE_FA);            send(VERSION);            send(faDataType);            send(xml);        } catch (Exception e) {            error(faDataType, EClientErrors.FAIL_SEND_FA_REPLACE, "" + e);            close();        }    }    protected synchronized void error(String err) {        m_anyWrapper.error(err);    }    protected synchronized void error(int id, int errorCode, String errorMsg) {        m_anyWrapper.error(id, errorCode, errorMsg);    }    protected void close() {        eDisconnect();        m_anyWrapper.connectionClosed();    }    private static boolean is(String str) {        // return true if the string is not empty        return str != null && str.length() > 0;    }    private static boolean isNull(String str) {        // return true if the string is null or empty        return!is(str);    }    private void error(int id, EClientErrors.CodeMsgPair pair, String tail) {        error(id, pair.code(), pair.msg() + tail);    }    protected void send(String str) throws IOException {        // write string to data buffer; writer thread will        // write it to socket        if (str != null) {            m_dos.write(str.getBytes());        }        sendEOL();    }    private void sendEOL() throws IOException {        m_dos.write(EOL);    }    protected void send(int val) throws IOException {        send(String.valueOf(val));    }    protected void send(char val) throws IOException {        m_dos.write(val);        sendEOL();    }    protected void send(double val) throws IOException {        send(String.valueOf(val));    }    protected void send(long val) throws IOException {        send(String.valueOf(val));    }    private void sendMax(double val) throws IOException {        if (val == Double.MAX_VALUE) {            sendEOL();        } else {            send(String.valueOf(val));        }    }    private void sendMax(int val) throws IOException {        if (val == Integer.MAX_VALUE) {            sendEOL();        } else {            send(String.valueOf(val));        }    }    protected void send(boolean val) throws IOException {        send(val ? 1 : 0);    }    /** Overridden in subclass. */    public EReader createReader(EClientSocket socket, DataInputStream dis) {        return new EReader(socket, dis);    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -