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

📄 eclientsocket.java

📁 网上期货交易的外挂原码,可实现自动交易功能,自动添加模块
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
    public synchronized void reqHistoricalData(int tickerId, Contract contract, String endDateTime, String durationStr,                                               String barSizeSetting, String whatToShow, int useRTH, int formatDate) {        // not connected?        if (!m_connected) {            error(tickerId, EClientErrors.NOT_CONNECTED, "");            return;        }        final int VERSION = 4;        try {            if (m_serverVersion < 16) {                error(EClientErrors.NO_VALID_ID, EClientErrors.UPDATE_TWS,                      "  It does not support historical data backfill.");                return;            }            send(REQ_HISTORICAL_DATA);            send(VERSION);            send(tickerId);            send(contract.m_symbol);            send(contract.m_secType);            send(contract.m_expiry);            send(contract.m_strike);            send(contract.m_right);            send(contract.m_multiplier);            send(contract.m_exchange);            send(contract.m_primaryExch);            send(contract.m_currency);            send(contract.m_localSymbol);            if (m_serverVersion >= 31) {                send(contract.m_includeExpired ? 1 : 0);            }            if (m_serverVersion >= 20) {                send(endDateTime);                send(barSizeSetting);            }            send(durationStr);            send(useRTH);            send(whatToShow);            if (m_serverVersion > 16) {                send(formatDate);            }            if (BAG_SEC_TYPE.equalsIgnoreCase(contract.m_secType)) {                if (contract.m_comboLegs == null) {                    send(0);                } else {                    send(contract.m_comboLegs.size());                    ComboLeg comboLeg;                    for (int i = 0; i < contract.m_comboLegs.size(); i++) {                        comboLeg = (ComboLeg) contract.m_comboLegs.get(i);                        send(comboLeg.m_conId);                        send(comboLeg.m_ratio);                        send(comboLeg.m_action);                        send(comboLeg.m_exchange);                    }                }            }        } catch (Exception e) {            error(tickerId, EClientErrors.FAIL_SEND_REQHISTDATA, "" + e);            close();        }    }    public synchronized void reqContractDetails(Contract contract) {        // not connected?        if (!m_connected) {            error(EClientErrors.NO_VALID_ID, EClientErrors.NOT_CONNECTED, "");            return;        }        // This feature is only available for versions of TWS >=4        if (m_serverVersion < 4) {            error(EClientErrors.NO_VALID_ID, EClientErrors.UPDATE_TWS.code(), EClientErrors.UPDATE_TWS.msg());            return;        }        final int VERSION = 3;        try {            // send req mkt data msg            send(REQ_CONTRACT_DATA);            send(VERSION);            send(contract.m_symbol);            send(contract.m_secType);            send(contract.m_expiry);            send(contract.m_strike);            send(contract.m_right);            if (m_serverVersion >= 15) {                send(contract.m_multiplier);            }            send(contract.m_exchange);            send(contract.m_currency);            send(contract.m_localSymbol);            if (m_serverVersion >= 31) {                send(contract.m_includeExpired);            }        } catch (Exception e) {            error(EClientErrors.NO_VALID_ID, EClientErrors.FAIL_SEND_REQCONTRACT, "" + e);            close();        }    }    public synchronized void reqMktDepth(int tickerId, Contract contract, int numRows) {        // not connected?        if (!m_connected) {            error(EClientErrors.NO_VALID_ID, EClientErrors.NOT_CONNECTED, "");            return;        }        // This feature is only available for versions of TWS >=6        if (m_serverVersion < 6) {            error(EClientErrors.NO_VALID_ID, EClientErrors.UPDATE_TWS.code(), EClientErrors.UPDATE_TWS.msg());            return;        }        final int VERSION = 3;        try {            // send req mkt data msg            send(REQ_MKT_DEPTH);            send(VERSION);            send(tickerId);            send(contract.m_symbol);            send(contract.m_secType);            send(contract.m_expiry);            send(contract.m_strike);            send(contract.m_right);            if (m_serverVersion >= 15) {                send(contract.m_multiplier);            }            send(contract.m_exchange);            send(contract.m_currency);            send(contract.m_localSymbol);            if (m_serverVersion >= 19) {                send(numRows);            }        } catch (Exception e) {            error(tickerId, EClientErrors.FAIL_SEND_REQMKTDEPTH, "" + e);            close();        }    }    public synchronized void cancelMktData(int tickerId) {        // not connected?        if (!m_connected) {            error(EClientErrors.NO_VALID_ID, EClientErrors.NOT_CONNECTED, "");            return;        }        final int VERSION = 1;        // send cancel mkt data msg        try {            send(CANCEL_MKT_DATA);            send(VERSION);            send(tickerId);        } catch (Exception e) {            error(tickerId, EClientErrors.FAIL_SEND_CANMKT, "" + e);            close();        }    }    public synchronized void cancelMktDepth(int tickerId) {        // not connected?        if (!m_connected) {            error(EClientErrors.NO_VALID_ID, EClientErrors.NOT_CONNECTED, "");            return;        }        // This feature is only available for versions of TWS >=6        if (m_serverVersion < 6) {            error(EClientErrors.NO_VALID_ID, EClientErrors.UPDATE_TWS.code(), EClientErrors.UPDATE_TWS.msg());            return;        }        final int VERSION = 1;        // send cancel mkt data msg        try {            send(CANCEL_MKT_DEPTH);            send(VERSION);            send(tickerId);        } catch (Exception e) {            error(tickerId, EClientErrors.FAIL_SEND_CANMKTDEPTH, "" + e);            close();        }    }    public synchronized void exerciseOptions(int tickerId, Contract contract, int exerciseAction, int exerciseQuantity,                                             String account, int override) {        // not connected?        if (!m_connected) {            error(tickerId, EClientErrors.NOT_CONNECTED, "");            return;        }        final int VERSION = 1;        try {            if (m_serverVersion < 21) {                error(EClientErrors.NO_VALID_ID, EClientErrors.UPDATE_TWS,                      "  It does not support options exercise from the API.");                return;            }            send(EXERCISE_OPTIONS);            send(VERSION);            send(tickerId);            send(contract.m_symbol);            send(contract.m_secType);            send(contract.m_expiry);            send(contract.m_strike);            send(contract.m_right);            send(contract.m_multiplier);            send(contract.m_exchange);            send(contract.m_currency);            send(contract.m_localSymbol);            send(exerciseAction);            send(exerciseQuantity);            send(account);            send(override);        } catch (Exception e) {            error(tickerId, EClientErrors.FAIL_SEND_REQMKT, "" + e);            close();        }    }    public synchronized void placeOrder(int id, Contract contract, Order order) {        // not connected?        if (!m_connected) {            error(EClientErrors.NO_VALID_ID, EClientErrors.NOT_CONNECTED, "");            return;        }        final int VERSION = 21;        // send place order msg        try {            send(PLACE_ORDER);            send(VERSION);            send(id);            // send contract fields            send(contract.m_symbol);            send(contract.m_secType);            send(contract.m_expiry);            send(contract.m_strike);            send(contract.m_right);            if (m_serverVersion >= 15) {                send(contract.m_multiplier);            }            send(contract.m_exchange);            if (m_serverVersion >= 14) {                send(contract.m_primaryExch);            }            send(contract.m_currency);            if (m_serverVersion >= 2) {                send(contract.m_localSymbol);            }            // send main order fields            send(order.m_action);            send(order.m_totalQuantity);            send(order.m_orderType);            send(order.m_lmtPrice);            send(order.m_auxPrice);            // send extended order fields            send(order.m_tif);            send(order.m_ocaGroup);            send(order.m_account);            send(order.m_openClose);            send(order.m_origin);            send(order.m_orderRef);            send(order.m_transmit);            if (m_serverVersion >= 4) {                send(order.m_parentId);            }            if (m_serverVersion >= 5) {                send(order.m_blockOrder);                send(order.m_sweepToFill);                send(order.m_displaySize);                send(order.m_triggerMethod);                send(order.m_ignoreRth);            }            if (m_serverVersion >= 7) {                send(order.m_hidden);            }            // Send combo legs for BAG requests            if (m_serverVersion >= 8 && BAG_SEC_TYPE.equalsIgnoreCase(contract.m_secType)) {                if (contract.m_comboLegs == null) {                    send(0);                } else {                    send(contract.m_comboLegs.size());                    ComboLeg comboLeg;                    for (int i = 0; i < contract.m_comboLegs.size(); i++) {                        comboLeg = (ComboLeg) contract.m_comboLegs.get(i);                        send(comboLeg.m_conId);                        send(comboLeg.m_ratio);                        send(comboLeg.m_action);                        send(comboLeg.m_exchange);                        send(comboLeg.m_openClose);                    }                }            }            if (m_serverVersion >= 9) {                send(order.m_sharesAllocation); // deprecated            }            if (m_serverVersion >= 10) {                send(order.m_discretionaryAmt);            }            if (m_serverVersion >= 11) {                send(order.m_goodAfterTime);            }            if (m_serverVersion >= 12) {                send(order.m_goodTillDate);            }            if (m_serverVersion >= 13) {                send(order.m_faGroup);                send(order.m_faMethod);                send(order.m_faPercentage);                send(order.m_faProfile);            }            if (m_serverVersion >= 18) { // institutional short sale slot fields.                send(order.m_shortSaleSlot); // 0 only for retail, 1 or 2 only for institution.                send(order.m_designatedLocation); // only populate when order.m_shortSaleSlot = 2.            }            if (m_serverVersion >= 19) {                send(order.m_ocaType);                send(order.m_rthOnly);                send(order.m_rule80A);                send(order.m_settlingFirm);                send(order.m_allOrNone);                sendMax(order.m_minQty);                sendMax(order.m_percentOffset);                send(order.m_eTradeOnly);                send(order.m_firmQuoteOnly);                sendMax(order.m_nbboPriceCap);                sendMax(order.m_auctionStrategy);                sendMax(order.m_startingPrice);                sendMax(order.m_stockRefPrice);                sendMax(order.m_delta);                // Volatility orders had specific watermark price attribs in server version 26                double lower = (m_serverVersion == 26 && order.m_orderType.equals("VOL")) ? Double.MAX_VALUE :                               order.m_stockRangeLower;                double upper = (m_serverVersion == 26 && order.m_orderType.equals("VOL")) ? Double.MAX_VALUE :                               order.m_stockRangeUpper;                sendMax(lower);                sendMax(upper);            }            if (m_serverVersion >= 22) {                send(order.m_overridePercentageConstraints);            }            if (m_serverVersion >= 26) { // Volatility orders                sendMax(order.m_volatility);                sendMax(order.m_volatilityType);                if (m_serverVersion < 28) {                    send(order.m_deltaNeutralOrderType.equalsIgnoreCase("MKT"));                } else {                    send(order.m_deltaNeutralOrderType);                    sendMax(order.m_deltaNeutralAuxPrice);                }                send(order.m_continuousUpdate);                if (m_serverVersion == 26) {                    // Volatility orders had specific watermark price attribs in server version 26                    double lower = order.m_orderType.equals("VOL") ? order.m_stockRangeLower : Double.MAX_VALUE;

⌨️ 快捷键说明

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