📄 eclientsocket.java
字号:
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 fields 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 reqRealTimeBars(int tickerId, Contract contract, int barSize, String whatToShow, boolean useRTH) { // not connected? if (!m_connected ) { error(EClientErrors.NO_VALID_ID, EClientErrors.NOT_CONNECTED, ""); return; } if (m_serverVersion < MIN_SERVER_VER_REAL_TIME_BARS) { error(EClientErrors.NO_VALID_ID, EClientErrors.UPDATE_TWS, " It does not support real time bars."); return; } final int VERSION = 1; try { // send req mkt data msg send(REQ_REAL_TIME_BARS); send(VERSION); send(tickerId); // send contract fields 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); send(barSize); send(whatToShow); send(useRTH); } catch( Exception e) { error( tickerId, EClientErrors.FAIL_SEND_REQRTBARS, "" + 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 = 4; try { // send req mkt data msg send( REQ_CONTRACT_DATA); send( VERSION); // send contract fields if (m_serverVersion >= MIN_SERVER_VER_CONTRACT_CONID) { send(contract.m_conId); } 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 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); 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 fields 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; } if (m_serverVersion < MIN_SERVER_VER_SCALE_ORDERS) { if (order.m_scaleNumComponents != Integer.MAX_VALUE || order.m_scaleComponentSize != Integer.MAX_VALUE || order.m_scalePriceIncrement != Double.MAX_VALUE) { error(id, EClientErrors.UPDATE_TWS, " It does not support Scale orders."); return; } } if (m_serverVersion < MIN_SERVER_VER_SSHORT_COMBO_LEGS) { if (!contract.m_comboLegs.isEmpty()) { ComboLeg comboLeg; for (int i = 0; i < contract.m_comboLegs.size(); ++i) { comboLeg = (ComboLeg)contract.m_comboLegs.get(i); if (comboLeg.m_shortSaleSlot != 0 || !IsEmpty(comboLeg.m_designatedLocation)) { error(id, EClientErrors.UPDATE_TWS, " It does not support SSHORT flag for combo legs."); return; } } } } if (m_serverVersion < MIN_SERVER_VER_WHAT_IF_ORDERS) { if (order.m_whatIf) { error(id, EClientErrors.UPDATE_TWS, " It does not support what-if orders."); return; } } final int VERSION = 25; // 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); if (m_serverVersion < 38) { // will never happen send(/* order.m_ignoreRth */ false); } else { send (order.m_outsideRth); } } 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 >= MIN_SERVER_VER_SSHORT_COMBO_LEGS) { send( comboLeg.m_shortSaleSlot); send( comboLeg.m_designatedLocation); } } } } if ( m_serverVersion >= 9 ) { // send deprecated sharesAllocation field send( ""); } 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); if (m_serverVersion < 38) { // will never happen send( /* order.m_rthOnly */ false); } 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"))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -