├── TWS API ├── API_VersionNum.txt ├── samples │ ├── CSharp │ │ ├── Testbed │ │ │ ├── .gitignore │ │ │ └── app.config │ │ └── IBSampleApp │ │ │ ├── .gitignore │ │ │ ├── LogoIcon.gif │ │ │ ├── ib_logo_2015.ico │ │ │ ├── app.config │ │ │ ├── Properties │ │ │ ├── Settings.settings │ │ │ └── Settings.Designer.cs │ │ │ ├── messages │ │ │ ├── SecurityDefinitionOptionParameterEndMessage.cs │ │ │ ├── OpenOrderEndMessage.cs │ │ │ ├── ContractDetailsEndMessage.cs │ │ │ ├── IBMessage.cs │ │ │ ├── OrderMessage.cs │ │ │ ├── TickSizeMessage.cs │ │ │ ├── FundamentalsMessage.cs │ │ │ ├── ScannerEndMessage.cs │ │ │ ├── ConnectionStatusMessage.cs │ │ │ ├── PositionMultiEndMessage.cs │ │ │ ├── ScannerParametersMessage.cs │ │ │ ├── AccountSummaryEndMessage.cs │ │ │ ├── AccountDownloadEndMessage.cs │ │ │ ├── UpdateAccountTimeMessage.cs │ │ │ ├── AccountUpdateMultiEndMessage.cs │ │ │ ├── ManagedAccountsMessage.cs │ │ │ ├── CommissionMessage.cs │ │ │ ├── MarketDataMessage.cs │ │ │ ├── AdvisorDataMessage.cs │ │ │ ├── TickPriceMessage.cs │ │ │ ├── ContractDetailsMessage.cs │ │ │ ├── SecurityDefinitionOptionParameterMessage.cs │ │ │ ├── ExecutionMessage.cs │ │ │ ├── HistoricalDataEndMessage.cs │ │ │ ├── OpenOrderMessage.cs │ │ │ └── ErrorMessage.cs │ │ │ ├── ui │ │ │ ├── SoftDollarTiersMessage.cs │ │ │ └── DataManager.cs │ │ │ ├── Program.cs │ │ │ └── util │ │ │ └── Utils.cs │ ├── VB │ │ ├── Testbed │ │ │ ├── .gitignore │ │ │ ├── My Project │ │ │ │ ├── Settings.settings │ │ │ │ ├── Application.Designer.vb │ │ │ │ ├── Application.myapp │ │ │ │ └── AssemblyInfo.vb │ │ │ └── app.config │ │ └── VB_API_Sample │ │ │ ├── .gitignore │ │ │ ├── _DTwsEvents_securityDefinitionOptionParameterEnd.vb │ │ │ ├── _DTwsEvents_currentTimeEvent.vb │ │ │ ├── _DTwsEvents_execDetailsEndEvent.vb │ │ │ ├── _DTwsEvents_nextValidIdEvent.vb │ │ │ ├── _DTwsEvents_scannerDataEndEvent.vb │ │ │ ├── _DTwsEvents_positionMultiEndEvent.vb │ │ │ ├── _DTwsEvents_scannerParametersEvent.vb │ │ │ ├── _DTwsEvents_tickSnapshotEndEvent.vb │ │ │ ├── _DTwsEvents_verifyMessageAPIEvent.vb │ │ │ ├── _DTwsEvents_contractDetailsEndEvent.vb │ │ │ ├── _DTwsEvents_managedAccountsEvent.vb │ │ │ ├── _DTwsEvents_updateAccountTimeEvent.vb │ │ │ ├── _DTwsEvents_accountDownloadEndEvent.vb │ │ │ ├── _DTwsEvents_accountSummaryEndEvent.vb │ │ │ ├── _DTwsEvents_accountUpdateMultiEndEvent.vb │ │ │ ├── _DTwsEvents_commissionReportEvent.vb │ │ │ ├── _DTwsEvents_fundamentalDataEvent.vb │ │ │ ├── _DTwsEvents_receiveFAEvent.vb │ │ │ ├── _DTwsEvents_displayGroupListEvent.vb │ │ │ ├── _DTwsEvents_marketDataTypeEvent.vb │ │ │ ├── _DTwsEvents_verifyCompletedEvent.vb │ │ │ ├── _DTwsEvents_displayGroupUpdatedEvent.vb │ │ │ ├── _DTwsEvents_verifyAndAuthMessageAPIEvent.vb │ │ │ ├── _DTwsEvents_contractDetailsExEvent.vb │ │ │ ├── _DTwsEvents_deltaNeutralValidationEvent.vb │ │ │ ├── _DTwsEvents_verifyAndAuthCompletedEvent.vb │ │ │ ├── _DTwsEvents_errMsgEvent.vb │ │ │ ├── _DTwsEvents_historicalDataEnd.vb │ │ │ ├── _DTwsEvents_tickSizeEvent.vb │ │ │ ├── _DTwsEvents_tickStringEvent.vb │ │ │ ├── _DTwsEvents_tickGenericEvent.vb │ │ │ ├── _DTwsEvents_execDetailsExEvent.vb │ │ │ ├── _DTwsEvents_positionEvent.vb │ │ │ ├── _DTwsEvents_tickPriceEvent.vb │ │ │ ├── _DTwsEvents_updateAccountValueEvent.vb │ │ │ ├── _DTwsEvents_updateNewsBulletinEvent.vb │ │ │ ├── _DTwsEvents_openOrderExEvent.vb │ │ │ ├── _DTwsEvents_accountSummaryEvent.vb │ │ │ ├── _DTWsEvents_securityDefinitionOptionParameterEvent.vb │ │ │ ├── _DTwsEvents_accountUpdateMultiEvent.vb │ │ │ ├── _DTwsEvents_positionMultiEvent.vb │ │ │ ├── _DTwsEvents_updateMktDepthEvent.vb │ │ │ ├── _DTwsEvents_updateMktDepthL2Event.vb │ │ │ ├── _DTwsEvents_scannerDataExEvent.vb │ │ │ ├── _DTwsEvents_realtimeBarEvent.vb │ │ │ ├── _DTwsEvents_updatePortfolioExEvent.vb │ │ │ ├── _DTwsEvents_historicalDataEvent.vb │ │ │ ├── _DTwsEvents_orderStatusEvent.vb │ │ │ ├── _DTwsEvents_tickOptionComputationEvent.vb │ │ │ ├── _DTwsEvents_tickEFPEvent.vb │ │ │ ├── AssemblyInfo.vb │ │ │ ├── app.config │ │ │ └── dlgAdjustStop.vb │ ├── Excel │ │ ├── TwsDde.xls │ │ └── TwsActiveX.xls │ ├── Java │ │ ├── ApiDemo.jar │ │ ├── apidemo │ │ │ ├── OnOKPanel.java │ │ │ ├── TimeConditionPanel.java │ │ │ ├── MarginContidionPanel.java │ │ │ ├── util │ │ │ │ ├── TCombo.java │ │ │ │ └── IConnectionConfiguration.java │ │ │ ├── ContractConditionPanel.java │ │ │ ├── OptionsPanel.java │ │ │ ├── PercentConditionPanel.java │ │ │ ├── VolumeConditionPanel.java │ │ │ ├── OperatorConditionPanel.java │ │ │ ├── TradeConditionPanel.java │ │ │ ├── ContractLookupButton.java │ │ │ ├── TradingPanel.java │ │ │ └── OptParamsModel.java │ │ ├── samples │ │ │ ├── rfq │ │ │ │ └── RfqOrder.java │ │ │ └── dnhedge │ │ │ │ └── DNHedgeOrder.java │ │ └── TestJavaClient │ │ │ └── Main.java │ └── Cpp │ │ ├── TestCppClient │ │ ├── StdAfx.cpp │ │ ├── Makefile.linux │ │ ├── StdAfx.h │ │ ├── ScannerSubscriptionSamples.h │ │ ├── Makefile.win │ │ ├── AvailableAlgoParams.h │ │ ├── ContractSamples.h │ │ └── AccountSummaryTags.h │ │ └── TestCppClientSSL │ │ ├── StdAfx.cpp │ │ ├── StdAfx.h │ │ ├── Makefile.linux │ │ └── Makefile.win ├── source │ ├── CSharpClient │ │ ├── client │ │ │ ├── .gitignore │ │ │ ├── IDecoder.cs │ │ │ ├── ETransport.cs │ │ │ ├── EClientMsgSink.cs │ │ │ ├── EClientException.cs │ │ │ ├── EMessage.cs │ │ │ ├── VolumeCondition.cs │ │ │ ├── PercentChangeCondition.cs │ │ │ ├── MessageValidator.cs │ │ │ ├── Constants.cs │ │ │ ├── EReaderSignal.cs │ │ │ ├── ESocket.cs │ │ │ ├── CSharpAPI.sln │ │ │ ├── EReaderMonitorSignal.cs │ │ │ ├── EClientSocketSSL.cs │ │ │ ├── TimeCondition.cs │ │ │ ├── MarginCondition.cs │ │ │ └── UnderComp.cs │ │ └── activex │ │ │ ├── ComWrappers │ │ │ ├── ComWrapper.cs │ │ │ └── ComSoftDollarTier.cs │ │ │ └── ControlImpl │ │ │ ├── IOrderComboLeg.cs │ │ │ ├── ITagValue.cs │ │ │ ├── IUnderComp.cs │ │ │ ├── ICommissionReport.cs │ │ │ ├── IOrderState.cs │ │ │ ├── IExecutionFilter.cs │ │ │ └── IComboLeg.cs │ ├── CppClient │ │ ├── client │ │ │ ├── .gitignore │ │ │ ├── ETransport.h │ │ │ ├── IExternalizable.h │ │ │ ├── StdAfx.cpp │ │ │ ├── TwsSocketClient.def │ │ │ ├── EReaderSignal.h │ │ │ ├── SoftDollarTier.h │ │ │ ├── EClientMsgSink.h │ │ │ ├── EMessage.h │ │ │ ├── VolumeCondition.h │ │ │ ├── ContractCondition.h │ │ │ ├── TimeCondition.cpp │ │ │ ├── SoftDollarTier.cpp │ │ │ ├── EReaderWMSignal.h │ │ │ ├── OperatorCondition.h │ │ │ ├── ESocket.h │ │ │ ├── VolumeCondition.cpp │ │ │ ├── MarginCondition.h │ │ │ ├── TimeCondition.h │ │ │ ├── EMessage.cpp │ │ │ ├── EMutex.h │ │ │ ├── PercentChangeCondition.h │ │ │ ├── PercentChangeCondition.cpp │ │ │ ├── res │ │ │ │ └── TwsSocketClient.rc2 │ │ │ ├── Resource.h │ │ │ ├── MarginCondition.cpp │ │ │ ├── CommissionReport.h │ │ │ ├── EReaderWMSignal.cpp │ │ │ ├── TagValue.h │ │ │ ├── OrderCondition.h │ │ │ ├── OrderState.h │ │ │ ├── executioncondition.h │ │ │ ├── CommonDefs.h │ │ │ ├── OperatorCondition.cpp │ │ │ ├── EReaderOSSignal.h │ │ │ ├── PriceCondition.h │ │ │ ├── StdAfx.h │ │ │ ├── ContractCondition.cpp │ │ │ ├── Execution.h │ │ │ ├── TwsSocketClient.sln │ │ │ ├── executioncondition.cpp │ │ │ └── EMutex.cpp │ │ ├── lib │ │ │ └── TwsSocketClient.lib │ │ └── ssl │ │ │ ├── StdAfx.cpp │ │ │ ├── TwsSocketClientSSL.def │ │ │ ├── ESocketSSL.h │ │ │ ├── res │ │ │ └── TwsSocketClientSSL.rc2 │ │ │ └── StdAfx.h │ └── JavaClient │ │ ├── TwsApi.jar │ │ ├── com │ │ └── ib │ │ │ ├── client │ │ │ ├── EReaderSignal.java │ │ │ ├── EClientMsgSink.java │ │ │ ├── ETransport.java │ │ │ ├── ContractLookuper.java │ │ │ ├── IApiEnum.java │ │ │ ├── OrderConditionType.java │ │ │ ├── TimeCondition.java │ │ │ ├── EJavaSignal.java │ │ │ ├── MarginCondition.java │ │ │ ├── EMessage.java │ │ │ ├── ESocket.java │ │ │ ├── VolumeCondition.java │ │ │ ├── OrderStatus.java │ │ │ ├── PercentChangeCondition.java │ │ │ ├── TagValue.java │ │ │ ├── OrderComboLeg.java │ │ │ ├── OperatorCondition.java │ │ │ ├── CommissionReport.java │ │ │ └── MarketDataType.java │ │ │ ├── controller │ │ │ ├── PairPanel.java │ │ │ ├── TradeId.java │ │ │ ├── Instrument.java │ │ │ ├── Alias.java │ │ │ ├── MarketValueTag.java │ │ │ └── Group.java │ │ │ └── contracts │ │ │ ├── StkContract.java │ │ │ ├── ComboContract.java │ │ │ ├── FutContract.java │ │ │ └── OptContract.java │ │ └── pom.xml └── gitCommitSha1Checksum.txt ├── TradeBot ├── Libs │ ├── NLog │ │ └── NLog.dll │ ├── TWS │ │ └── CSharpAPI.dll │ └── JsonClassGenerator │ │ ├── Newtonsoft.Json.dll │ │ ├── Xamasoft.JsonClassGenerator.dll │ │ └── System.Data.Entity.Design.PluralizationServices.dll ├── Resources │ ├── state.json │ ├── preferences.json │ └── readme.txt ├── Icons │ └── uptrend_icon.ico ├── Events │ ├── TickUpdatedEvent.cs │ └── PositionUpdatedEvent.cs ├── MenuFramework │ ├── MenuItem.cs │ ├── MenuCommand.cs │ ├── MenuDivider.cs │ ├── MenuOption.cs │ └── MenuTitle.cs ├── App.config ├── Scripts │ ├── TradeBot.sh │ ├── remove_git_index_lock_file.sh │ └── readme.txt ├── Utils │ └── NumberGenerator.cs ├── FileIO │ ├── PropertyFiles.cs │ ├── PropertySerializer.cs │ └── CustomJsonClassGenerator.cs ├── AppProperties.cs ├── TwsAbstractions │ ├── ContractFactory.cs │ ├── OrderFactory.cs │ ├── Portfolio.cs │ └── TickData.cs ├── Generated │ ├── AppState.cs │ └── AppPreferences.cs ├── Extensions │ ├── TaskExtensions.cs │ └── CollectionExtensions.cs ├── Gui │ └── OS.cs └── Program.cs ├── .gitignore └── LICENSE /TWS API/API_VersionNum.txt: -------------------------------------------------------------------------------- 1 | API_Version=9.72.18 2 | -------------------------------------------------------------------------------- /TWS API/samples/CSharp/Testbed/.gitignore: -------------------------------------------------------------------------------- 1 | /bin/ 2 | /obj/ 3 | *.suo 4 | -------------------------------------------------------------------------------- /TWS API/samples/CSharp/IBSampleApp/.gitignore: -------------------------------------------------------------------------------- 1 | /bin/ 2 | /obj/ 3 | *.suo 4 | -------------------------------------------------------------------------------- /TWS API/samples/VB/Testbed/.gitignore: -------------------------------------------------------------------------------- 1 | /bin/ 2 | /obj/ 3 | *.suo 4 | *.exe 5 | -------------------------------------------------------------------------------- /TWS API/source/CSharpClient/client/.gitignore: -------------------------------------------------------------------------------- 1 | /bin/ 2 | /obj/ 3 | *.suo 4 | -------------------------------------------------------------------------------- /TWS API/source/CppClient/client/.gitignore: -------------------------------------------------------------------------------- 1 | Debug 2 | Release 3 | *.sdf 4 | *.opensdf 5 | -------------------------------------------------------------------------------- /TWS API/samples/VB/VB_API_Sample/.gitignore: -------------------------------------------------------------------------------- 1 | /bin/ 2 | /obj/ 3 | /My Project/ 4 | *.suo 5 | -------------------------------------------------------------------------------- /TradeBot/Libs/NLog/NLog.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mark-hennessy/tws-cli/HEAD/TradeBot/Libs/NLog/NLog.dll -------------------------------------------------------------------------------- /TradeBot/Resources/state.json: -------------------------------------------------------------------------------- 1 | { 2 | "tickerSymbol": "WDAY", 3 | "cash": 50000.00, 4 | "shares": 0.0 5 | } 6 | -------------------------------------------------------------------------------- /TWS API/samples/Excel/TwsDde.xls: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mark-hennessy/tws-cli/HEAD/TWS API/samples/Excel/TwsDde.xls -------------------------------------------------------------------------------- /TWS API/samples/Java/ApiDemo.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mark-hennessy/tws-cli/HEAD/TWS API/samples/Java/ApiDemo.jar -------------------------------------------------------------------------------- /TradeBot/Icons/uptrend_icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mark-hennessy/tws-cli/HEAD/TradeBot/Icons/uptrend_icon.ico -------------------------------------------------------------------------------- /TradeBot/Libs/TWS/CSharpAPI.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mark-hennessy/tws-cli/HEAD/TradeBot/Libs/TWS/CSharpAPI.dll -------------------------------------------------------------------------------- /TWS API/samples/Excel/TwsActiveX.xls: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mark-hennessy/tws-cli/HEAD/TWS API/samples/Excel/TwsActiveX.xls -------------------------------------------------------------------------------- /TWS API/source/JavaClient/TwsApi.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mark-hennessy/tws-cli/HEAD/TWS API/source/JavaClient/TwsApi.jar -------------------------------------------------------------------------------- /TWS API/samples/CSharp/IBSampleApp/LogoIcon.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mark-hennessy/tws-cli/HEAD/TWS API/samples/CSharp/IBSampleApp/LogoIcon.gif -------------------------------------------------------------------------------- /TWS API/source/CppClient/lib/TwsSocketClient.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mark-hennessy/tws-cli/HEAD/TWS API/source/CppClient/lib/TwsSocketClient.lib -------------------------------------------------------------------------------- /TWS API/samples/CSharp/IBSampleApp/ib_logo_2015.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mark-hennessy/tws-cli/HEAD/TWS API/samples/CSharp/IBSampleApp/ib_logo_2015.ico -------------------------------------------------------------------------------- /TradeBot/Events/TickUpdatedEvent.cs: -------------------------------------------------------------------------------- 1 | namespace TradeBot.Events 2 | { 3 | public delegate void TickUpdatedEventHandler(int tickType, double value); 4 | } 5 | -------------------------------------------------------------------------------- /TradeBot/Libs/JsonClassGenerator/Newtonsoft.Json.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mark-hennessy/tws-cli/HEAD/TradeBot/Libs/JsonClassGenerator/Newtonsoft.Json.dll -------------------------------------------------------------------------------- /TWS API/gitCommitSha1Checksum.txt: -------------------------------------------------------------------------------- 1 | https://github.com/InteractiveBrokers/tws-api 2 | SHA-1 checksum of current commit: 3 | 7c5cce9e347267351cf4efc420cb470d95982401 4 | -------------------------------------------------------------------------------- /TradeBot/MenuFramework/MenuItem.cs: -------------------------------------------------------------------------------- 1 | namespace TradeBot.MenuFramework 2 | { 3 | public interface MenuItem 4 | { 5 | string Render(); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /TradeBot/MenuFramework/MenuCommand.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | 3 | namespace TradeBot.MenuFramework 4 | { 5 | public delegate Task MenuCommand(string[] args); 6 | } 7 | -------------------------------------------------------------------------------- /TWS API/source/JavaClient/com/ib/client/EReaderSignal.java: -------------------------------------------------------------------------------- 1 | package com.ib.client; 2 | 3 | public interface EReaderSignal { 4 | void issueSignal(); 5 | void waitForSignal(); 6 | } 7 | -------------------------------------------------------------------------------- /TradeBot/Libs/JsonClassGenerator/Xamasoft.JsonClassGenerator.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mark-hennessy/tws-cli/HEAD/TradeBot/Libs/JsonClassGenerator/Xamasoft.JsonClassGenerator.dll -------------------------------------------------------------------------------- /TWS API/samples/CSharp/IBSampleApp/app.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /TradeBot/Events/PositionUpdatedEvent.cs: -------------------------------------------------------------------------------- 1 | using TradeBot.TwsAbstractions; 2 | 3 | namespace TradeBot.Events 4 | { 5 | public delegate void PositionUpdatedEventHandler(Position position); 6 | } 7 | -------------------------------------------------------------------------------- /TradeBot/Resources/preferences.json: -------------------------------------------------------------------------------- 1 | { 2 | "clientId": 0, 3 | "clientUrl": "127.0.0.1", 4 | "clientPort": 7496, 5 | "windowWidth": 900, 6 | "windowHeight": 600, 7 | "centerWindow": true 8 | } 9 | -------------------------------------------------------------------------------- /TWS API/samples/CSharp/Testbed/app.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /TWS API/source/JavaClient/com/ib/client/EClientMsgSink.java: -------------------------------------------------------------------------------- 1 | package com.ib.client; 2 | 3 | interface EClientMsgSink { 4 | void serverVersion(int version, String time); 5 | void redirect(String host); 6 | } 7 | -------------------------------------------------------------------------------- /TWS API/source/JavaClient/com/ib/client/ETransport.java: -------------------------------------------------------------------------------- 1 | package com.ib.client; 2 | 3 | import java.io.IOException; 4 | 5 | public interface ETransport { 6 | void send(EMessage msg) throws IOException; 7 | } 8 | -------------------------------------------------------------------------------- /TradeBot/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /TradeBot/Libs/JsonClassGenerator/System.Data.Entity.Design.PluralizationServices.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mark-hennessy/tws-cli/HEAD/TradeBot/Libs/JsonClassGenerator/System.Data.Entity.Design.PluralizationServices.dll -------------------------------------------------------------------------------- /TWS API/source/JavaClient/com/ib/client/ContractLookuper.java: -------------------------------------------------------------------------------- 1 | package com.ib.client; 2 | 3 | import java.util.ArrayList; 4 | 5 | public interface ContractLookuper { 6 | ArrayList lookupContract(Contract contract); 7 | } -------------------------------------------------------------------------------- /TWS API/samples/VB/VB_API_Sample/_DTwsEvents_securityDefinitionOptionParameterEnd.vb: -------------------------------------------------------------------------------- 1 | 2 | Namespace AxTWSLib 3 | Class _DTwsEvents_securityDefinitionOptionParameterEnd 4 | 5 | Property reqId As Integer 6 | 7 | End Class 8 | End Namespace 9 | -------------------------------------------------------------------------------- /TWS API/samples/Java/apidemo/OnOKPanel.java: -------------------------------------------------------------------------------- 1 | package apidemo; 2 | 3 | import com.ib.client.OrderCondition; 4 | 5 | import apidemo.util.VerticalPanel; 6 | 7 | public abstract class OnOKPanel extends VerticalPanel { 8 | public abstract OrderCondition onOK(); 9 | } -------------------------------------------------------------------------------- /TWS API/source/CppClient/client/ETransport.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class EMessage; 4 | 5 | struct ETransport 6 | { 7 | virtual int send(EMessage *pMsg) = 0; 8 | //virtual int sendBufferedData() = 0; 9 | //virtual bool isOutBufferEmpty() const = 0; 10 | }; 11 | 12 | -------------------------------------------------------------------------------- /TWS API/source/CppClient/client/IExternalizable.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | struct IExternalizable 5 | { 6 | virtual const char* readExternal(const char* ptr, const char* endPtr) = 0; 7 | virtual void writeExternal(std::ostream &out) const = 0; 8 | }; 9 | 10 | -------------------------------------------------------------------------------- /TWS API/source/CppClient/client/StdAfx.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | 4 | #include "StdAfx.h" 5 | -------------------------------------------------------------------------------- /TWS API/source/CppClient/ssl/StdAfx.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | 4 | #include "StdAfx.h" 5 | -------------------------------------------------------------------------------- /TWS API/samples/Cpp/TestCppClient/StdAfx.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | 4 | #include "StdAfx.h" 5 | -------------------------------------------------------------------------------- /TWS API/samples/Cpp/TestCppClientSSL/StdAfx.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | 4 | #include "StdAfx.h" 5 | -------------------------------------------------------------------------------- /TWS API/samples/Cpp/TestCppClientSSL/StdAfx.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | 4 | #pragma once 5 | 6 | #include "ssl/StdAfx.h" 7 | -------------------------------------------------------------------------------- /TWS API/source/JavaClient/com/ib/controller/PairPanel.java: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | 4 | package com.ib.controller; 5 | 6 | 7 | -------------------------------------------------------------------------------- /TWS API/samples/CSharp/IBSampleApp/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /TradeBot/Scripts/TradeBot.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # This script launches the TradeBot application on Mac/Unix operating systems 4 | 5 | # Change to the directory where the exe is stored no matter how the script is run 6 | SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) 7 | cd "${SCRIPT_DIR}"/.. 8 | 9 | mono ./TradeBot.exe -------------------------------------------------------------------------------- /TWS API/samples/VB/Testbed/My Project/Settings.settings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /TradeBot/Utils/NumberGenerator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace TradeBot.Utils 4 | { 5 | public static class NumberGenerator 6 | { 7 | private static readonly Random random = new Random(); 8 | 9 | public static int NextRandomInt() 10 | { 11 | return random.Next(); 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /TWS API/source/JavaClient/com/ib/client/IApiEnum.java: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | 4 | package com.ib.client; 5 | 6 | public interface IApiEnum { 7 | String getApiString(); 8 | } 9 | -------------------------------------------------------------------------------- /TWS API/source/CppClient/client/TwsSocketClient.def: -------------------------------------------------------------------------------- 1 | ; Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | ; and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. 3 | 4 | ; TwsSocketClient.def : Declares the module parameters for the DLL. 5 | 6 | LIBRARY "TwsSocketClient" 7 | 8 | EXPORTS 9 | -------------------------------------------------------------------------------- /TWS API/source/CppClient/ssl/TwsSocketClientSSL.def: -------------------------------------------------------------------------------- 1 | ; Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | ; and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. 3 | 4 | ; TwsSocketClientSSL.def : Declares the module parameters for the DLL. 5 | 6 | LIBRARY "TwsSocketClientSSL" 7 | 8 | EXPORTS 9 | -------------------------------------------------------------------------------- /TWS API/samples/Cpp/TestCppClient/Makefile.linux: -------------------------------------------------------------------------------- 1 | CXX=g++ 2 | CXXFLAGS=-pthread -Wall -Wno-switch -std=c++11 3 | ROOT_DIR=../../../source/cppclient 4 | BASE_SRC_DIR=${ROOT_DIR}/client 5 | INCLUDES=-I${BASE_SRC_DIR} -I${ROOT_DIR} 6 | TARGET=TestCppClient 7 | 8 | $(TARGET): 9 | $(CXX) $(CXXFLAGS) $(INCLUDES) $(BASE_SRC_DIR)/*.cpp ./*.cpp -o$(TARGET) 10 | 11 | clean: 12 | rm -f $(TARGET) *.o 13 | 14 | -------------------------------------------------------------------------------- /TWS API/source/CppClient/client/EReaderSignal.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | 4 | #pragma once 5 | struct EReaderSignal 6 | { 7 | virtual void issueSignal() = 0; 8 | virtual void waitForSignal() = 0; 9 | }; 10 | 11 | -------------------------------------------------------------------------------- /TWS API/source/CppClient/client/SoftDollarTier.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class TWSAPIDLLEXP SoftDollarTier 4 | { 5 | std::string m_name, m_val, m_displayName; 6 | 7 | public: 8 | SoftDollarTier(const std::string& name = "", const std::string& val = "", const std::string& displayName = ""); 9 | 10 | std::string name() const; 11 | std::string val() const; 12 | std::string displayName() const; 13 | }; 14 | 15 | -------------------------------------------------------------------------------- /TWS API/samples/VB/VB_API_Sample/_DTwsEvents_currentTimeEvent.vb: -------------------------------------------------------------------------------- 1 | ' Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | ' and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. 3 | 4 | Namespace AxTWSLib 5 | Class _DTwsEvents_currentTimeEvent 6 | 7 | Property time As Long 8 | 9 | End Class 10 | End Namespace 11 | -------------------------------------------------------------------------------- /TWS API/samples/VB/VB_API_Sample/_DTwsEvents_execDetailsEndEvent.vb: -------------------------------------------------------------------------------- 1 | ' Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | ' and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. 3 | 4 | Namespace AxTWSLib 5 | Class _DTwsEvents_execDetailsEndEvent 6 | 7 | Property reqId As Integer 8 | 9 | End Class 10 | End Namespace 11 | -------------------------------------------------------------------------------- /TWS API/samples/VB/VB_API_Sample/_DTwsEvents_nextValidIdEvent.vb: -------------------------------------------------------------------------------- 1 | ' Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | ' and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. 3 | 4 | Namespace AxTWSLib 5 | Public Class _DTwsEvents_nextValidIdEvent 6 | 7 | Property Id As Integer 8 | 9 | End Class 10 | End Namespace 11 | -------------------------------------------------------------------------------- /TWS API/samples/VB/VB_API_Sample/_DTwsEvents_scannerDataEndEvent.vb: -------------------------------------------------------------------------------- 1 | ' Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | ' and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. 3 | 4 | Namespace AxTWSLib 5 | Class _DTwsEvents_scannerDataEndEvent 6 | 7 | Property reqId As Integer 8 | 9 | End Class 10 | End Namespace 11 | -------------------------------------------------------------------------------- /TWS API/samples/Cpp/TestCppClient/StdAfx.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | 4 | #pragma once 5 | 6 | #include "client/StdAfx.h" 7 | 8 | #ifndef TWSAPIDLL 9 | #ifndef TWSAPIDLLEXP 10 | #define TWSAPIDLLEXP __declspec(dllimport) 11 | #endif 12 | #endif 13 | -------------------------------------------------------------------------------- /TWS API/samples/VB/VB_API_Sample/_DTwsEvents_positionMultiEndEvent.vb: -------------------------------------------------------------------------------- 1 | ' Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | ' and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. 3 | 4 | Namespace AxTWSLib 5 | Class _DTwsEvents_positionMultiEndEvent 6 | 7 | Property reqId As Integer 8 | 9 | End Class 10 | End Namespace 11 | -------------------------------------------------------------------------------- /TWS API/samples/VB/VB_API_Sample/_DTwsEvents_scannerParametersEvent.vb: -------------------------------------------------------------------------------- 1 | ' Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | ' and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. 3 | 4 | Namespace AxTWSLib 5 | Class _DTwsEvents_scannerParametersEvent 6 | 7 | Property xml As String 8 | 9 | End Class 10 | End Namespace 11 | -------------------------------------------------------------------------------- /TWS API/samples/VB/VB_API_Sample/_DTwsEvents_tickSnapshotEndEvent.vb: -------------------------------------------------------------------------------- 1 | ' Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | ' and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. 3 | 4 | Namespace AxTWSLib 5 | Class _DTwsEvents_tickSnapshotEndEvent 6 | 7 | Property tickerId As Integer 8 | 9 | End Class 10 | End Namespace 11 | -------------------------------------------------------------------------------- /TWS API/samples/VB/VB_API_Sample/_DTwsEvents_verifyMessageAPIEvent.vb: -------------------------------------------------------------------------------- 1 | ' Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | ' and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. 3 | 4 | Namespace AxTWSLib 5 | Class _DTwsEvents_verifyMessageAPIEvent 6 | 7 | Property apiData As String 8 | 9 | End Class 10 | End Namespace 11 | -------------------------------------------------------------------------------- /TWS API/samples/VB/VB_API_Sample/_DTwsEvents_contractDetailsEndEvent.vb: -------------------------------------------------------------------------------- 1 | ' Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | ' and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. 3 | 4 | Namespace AxTWSLib 5 | Class _DTwsEvents_contractDetailsEndEvent 6 | 7 | Property reqId As Integer 8 | 9 | End Class 10 | End Namespace 11 | -------------------------------------------------------------------------------- /TWS API/samples/VB/VB_API_Sample/_DTwsEvents_managedAccountsEvent.vb: -------------------------------------------------------------------------------- 1 | ' Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | ' and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. 3 | 4 | Namespace AxTWSLib 5 | Class _DTwsEvents_managedAccountsEvent 6 | 7 | Property accountsList As String 8 | 9 | End Class 10 | End Namespace 11 | -------------------------------------------------------------------------------- /TWS API/samples/VB/VB_API_Sample/_DTwsEvents_updateAccountTimeEvent.vb: -------------------------------------------------------------------------------- 1 | ' Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | ' and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. 3 | 4 | Namespace AxTWSLib 5 | Class _DTwsEvents_updateAccountTimeEvent 6 | 7 | Property timestamp As String 8 | 9 | End Class 10 | End Namespace 11 | -------------------------------------------------------------------------------- /TWS API/samples/VB/VB_API_Sample/_DTwsEvents_accountDownloadEndEvent.vb: -------------------------------------------------------------------------------- 1 | ' Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | ' and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. 3 | 4 | 5 | Namespace AxTWSLib 6 | Class _DTwsEvents_accountDownloadEndEvent 7 | 8 | Property account As String 9 | 10 | End Class 11 | End Namespace 12 | -------------------------------------------------------------------------------- /TWS API/samples/VB/VB_API_Sample/_DTwsEvents_accountSummaryEndEvent.vb: -------------------------------------------------------------------------------- 1 | ' Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | ' and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. 3 | 4 | 5 | Namespace AxTWSLib 6 | Class _DTwsEvents_accountSummaryEndEvent 7 | 8 | Property reqId As Integer 9 | 10 | End Class 11 | End Namespace 12 | -------------------------------------------------------------------------------- /TWS API/samples/VB/VB_API_Sample/_DTwsEvents_accountUpdateMultiEndEvent.vb: -------------------------------------------------------------------------------- 1 | ' Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | ' and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. 3 | 4 | Namespace AxTWSLib 5 | Class _DTwsEvents_accountUpdateMultiEndEvent 6 | 7 | Property reqId As Integer 8 | 9 | End Class 10 | End Namespace 11 | -------------------------------------------------------------------------------- /TradeBot/FileIO/PropertyFiles.cs: -------------------------------------------------------------------------------- 1 | namespace TradeBot.FileIO 2 | { 3 | public static class PropertyFiles 4 | { 5 | public const string RESOURCES_FOLDER = "Resources/"; 6 | 7 | public const string PREFERENCES_FILE = RESOURCES_FOLDER + "preferences.json"; 8 | public const string MESSAGES_FILE = RESOURCES_FOLDER + "messages.json"; 9 | public const string STATE_FILE = RESOURCES_FOLDER + "state.json"; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /TWS API/samples/VB/VB_API_Sample/_DTwsEvents_commissionReportEvent.vb: -------------------------------------------------------------------------------- 1 | ' Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | ' and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. 3 | 4 | Namespace AxTWSLib 5 | Class _DTwsEvents_commissionReportEvent 6 | 7 | Property commissionReport As IBApi.CommissionReport 8 | 9 | End Class 10 | End Namespace 11 | -------------------------------------------------------------------------------- /TWS API/source/CppClient/client/EClientMsgSink.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | 4 | #pragma once 5 | struct EClientMsgSink 6 | { 7 | virtual void serverVersion(int version, const char *time) = 0; 8 | virtual void redirect(const char *host, int port) = 0; 9 | }; 10 | 11 | -------------------------------------------------------------------------------- /TWS API/source/CSharpClient/client/IDecoder.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace IBApi 7 | { 8 | public interface IDecoder 9 | { 10 | double ReadDouble(); 11 | double ReadDoubleMax(); 12 | long ReadLong(); 13 | int ReadInt(); 14 | int ReadIntMax(); 15 | bool ReadBoolFromInt(); 16 | string ReadString(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /TWS API/samples/VB/VB_API_Sample/_DTwsEvents_fundamentalDataEvent.vb: -------------------------------------------------------------------------------- 1 | ' Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | ' and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. 3 | 4 | Namespace AxTWSLib 5 | Class _DTwsEvents_fundamentalDataEvent 6 | 7 | Property reqId As Integer 8 | 9 | Property data As String 10 | 11 | End Class 12 | End Namespace 13 | -------------------------------------------------------------------------------- /TWS API/samples/VB/VB_API_Sample/_DTwsEvents_receiveFAEvent.vb: -------------------------------------------------------------------------------- 1 | ' Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | ' and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. 3 | 4 | Namespace AxTWSLib 5 | Class _DTwsEvents_receiveFAEvent 6 | 7 | Property faDataType As Integer 8 | 9 | Property faXmlData As String 10 | 11 | End Class 12 | End Namespace 13 | -------------------------------------------------------------------------------- /TWS API/samples/VB/VB_API_Sample/_DTwsEvents_displayGroupListEvent.vb: -------------------------------------------------------------------------------- 1 | ' Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | ' and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. 3 | 4 | Namespace AxTWSLib 5 | Class _DTwsEvents_displayGroupListEvent 6 | 7 | Property reqId As Integer 8 | 9 | Property groups As String 10 | 11 | End Class 12 | End Namespace 13 | -------------------------------------------------------------------------------- /TWS API/samples/VB/VB_API_Sample/_DTwsEvents_marketDataTypeEvent.vb: -------------------------------------------------------------------------------- 1 | ' Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | ' and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. 3 | 4 | Namespace AxTWSLib 5 | Class _DTwsEvents_marketDataTypeEvent 6 | 7 | Property reqId As Integer 8 | 9 | Property marketDataType As Integer 10 | 11 | End Class 12 | End Namespace 13 | -------------------------------------------------------------------------------- /TWS API/samples/VB/VB_API_Sample/_DTwsEvents_verifyCompletedEvent.vb: -------------------------------------------------------------------------------- 1 | ' Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | ' and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. 3 | 4 | Namespace AxTWSLib 5 | Class _DTwsEvents_verifyCompletedEvent 6 | 7 | Property isSuccessful As Boolean 8 | 9 | Property errorText As String 10 | 11 | End Class 12 | End Namespace 13 | -------------------------------------------------------------------------------- /TradeBot/Resources/readme.txt: -------------------------------------------------------------------------------- 1 | This folder contains JSON resource files. The app reads user preferences, localized messages, and persisted application state from these files. 2 | 3 | state.json 4 | == 5 | The app persists its state to this file before closing. 6 | Modification by hand is allowed, but should be done with caution. 7 | 8 | messages.json 9 | == 10 | This file defines the messages used by the app. 11 | 12 | preferences.json 13 | == 14 | This file stores application preferences. -------------------------------------------------------------------------------- /TradeBot/Scripts/remove_git_index_lock_file.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # This script deletes the .git/index.lock file if it exists 4 | 5 | # Change to the directory where the script is stored no matter how the script is run 6 | SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) 7 | cd "${SCRIPT_DIR}" 8 | 9 | # Delete the executable 10 | rm -f ../../.git/index.lock 11 | 12 | # Prevent the terminal from auto-closing on Windows 13 | #read -rsp $'Press any key to continue...\n' -n1 14 | -------------------------------------------------------------------------------- /TWS API/samples/VB/VB_API_Sample/_DTwsEvents_displayGroupUpdatedEvent.vb: -------------------------------------------------------------------------------- 1 | ' Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | ' and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. 3 | 4 | Namespace AxTWSLib 5 | Class _DTwsEvents_displayGroupUpdatedEvent 6 | 7 | Property reqId As Integer 8 | 9 | Property contractInfo As String 10 | 11 | End Class 12 | End Namespace 13 | -------------------------------------------------------------------------------- /TWS API/samples/VB/VB_API_Sample/_DTwsEvents_verifyAndAuthMessageAPIEvent.vb: -------------------------------------------------------------------------------- 1 | ' Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | ' and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. 3 | 4 | Namespace AxTWSLib 5 | Class _DTwsEvents_verifyAndAuthMessageAPIEvent 6 | 7 | Property apiData As String 8 | Property xyzChallenge As String 9 | 10 | End Class 11 | End Namespace 12 | -------------------------------------------------------------------------------- /TWS API/source/CSharpClient/client/ETransport.cs: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2015 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | 8 | namespace IBApi 9 | { 10 | public interface ETransport 11 | { 12 | void Send(EMessage msg); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /TWS API/source/CppClient/client/EMessage.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | 4 | #pragma once 5 | class TWSAPIDLLEXP EMessage 6 | { 7 | std::vector data; 8 | public: 9 | EMessage(const std::vector &data); 10 | const char* begin(void) const; 11 | const char* end(void) const; 12 | }; 13 | 14 | -------------------------------------------------------------------------------- /TWS API/samples/VB/VB_API_Sample/_DTwsEvents_contractDetailsExEvent.vb: -------------------------------------------------------------------------------- 1 | ' Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | ' and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. 3 | 4 | Namespace AxTWSLib 5 | Class _DTwsEvents_contractDetailsExEvent 6 | 7 | Property reqId As Integer 8 | 9 | Property contractDetails As IBApi.ContractDetails 10 | 11 | End Class 12 | End Namespace 13 | -------------------------------------------------------------------------------- /TWS API/samples/VB/VB_API_Sample/_DTwsEvents_deltaNeutralValidationEvent.vb: -------------------------------------------------------------------------------- 1 | ' Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | ' and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. 3 | 4 | Namespace AxTWSLib 5 | Class _DTwsEvents_deltaNeutralValidationEvent 6 | 7 | Property reqId As Integer 8 | 9 | Property underComp As IBApi.UnderComp 10 | 11 | End Class 12 | End Namespace 13 | -------------------------------------------------------------------------------- /TWS API/samples/VB/VB_API_Sample/_DTwsEvents_verifyAndAuthCompletedEvent.vb: -------------------------------------------------------------------------------- 1 | ' Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | ' and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. 3 | 4 | Namespace AxTWSLib 5 | Class _DTwsEvents_verifyAndAuthCompletedEvent 6 | 7 | Property isSuccessful As Boolean 8 | 9 | Property errorText As String 10 | 11 | End Class 12 | End Namespace 13 | -------------------------------------------------------------------------------- /TWS API/samples/VB/VB_API_Sample/_DTwsEvents_errMsgEvent.vb: -------------------------------------------------------------------------------- 1 | ' Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | ' and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. 3 | 4 | Namespace AxTWSLib 5 | Public Class _DTwsEvents_errMsgEvent 6 | 7 | Property id As Integer 8 | 9 | Property errorCode As Integer 10 | 11 | Property errorMsg As String 12 | 13 | End Class 14 | End Namespace 15 | -------------------------------------------------------------------------------- /TWS API/samples/VB/VB_API_Sample/_DTwsEvents_historicalDataEnd.vb: -------------------------------------------------------------------------------- 1 | ' Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | ' and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. 3 | 4 | Namespace AxTWSLib 5 | Class _DTwsEvents_historicalDataEnd 6 | 7 | Property reqId As Integer 8 | 9 | Property start As String 10 | 11 | Property [end] As String 12 | 13 | End Class 14 | End Namespace 15 | -------------------------------------------------------------------------------- /TWS API/samples/Cpp/TestCppClient/ScannerSubscriptionSamples.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #ifndef SCANNERSUBSCRIPTIONSAMPLES 3 | #define SCANNERSUBSCRIPTIONSAMPLES 4 | 5 | #include 6 | 7 | struct ScannerSubscription; 8 | 9 | class ScannerSubscriptionSamples { 10 | public: 11 | static ScannerSubscription HotUSStkByVolume(); 12 | static ScannerSubscription TopPercentGainersIbis(); 13 | static ScannerSubscription MostActiveFutSoffex(); 14 | static ScannerSubscription HighOptVolumePCRatioUSIndexes(); 15 | }; 16 | 17 | #endif -------------------------------------------------------------------------------- /TWS API/samples/VB/VB_API_Sample/_DTwsEvents_tickSizeEvent.vb: -------------------------------------------------------------------------------- 1 | ' Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | ' and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. 3 | 4 | Namespace AxTWSLib 5 | Friend Class _DTwsEvents_tickSizeEvent 6 | 7 | Property id As Integer 8 | 9 | Property tickType As Utils.TickType 10 | 11 | Property size As Integer 12 | 13 | End Class 14 | End Namespace 15 | -------------------------------------------------------------------------------- /TWS API/samples/VB/VB_API_Sample/_DTwsEvents_tickStringEvent.vb: -------------------------------------------------------------------------------- 1 | ' Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | ' and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. 3 | 4 | Namespace AxTWSLib 5 | Friend Class _DTwsEvents_tickStringEvent 6 | 7 | Property id As Integer 8 | 9 | Property tickType As Utils.TickType 10 | 11 | Property value As String 12 | 13 | End Class 14 | End Namespace 15 | -------------------------------------------------------------------------------- /TWS API/samples/VB/VB_API_Sample/_DTwsEvents_tickGenericEvent.vb: -------------------------------------------------------------------------------- 1 | ' Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | ' and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. 3 | 4 | Namespace AxTWSLib 5 | Friend Class _DTwsEvents_tickGenericEvent 6 | 7 | Property id As Integer 8 | 9 | Property tickType As Utils.TickType 10 | 11 | Property value As Double 12 | 13 | End Class 14 | End Namespace 15 | -------------------------------------------------------------------------------- /TWS API/samples/VB/Testbed/My Project/Application.Designer.vb: -------------------------------------------------------------------------------- 1 | '------------------------------------------------------------------------------ 2 | ' 3 | ' This code was generated by a tool. 4 | ' Runtime Version:4.0.30319.42000 5 | ' 6 | ' Changes to this file may cause incorrect behavior and will be lost if 7 | ' the code is regenerated. 8 | ' 9 | '------------------------------------------------------------------------------ 10 | 11 | Option Strict On 12 | Option Explicit On 13 | 14 | -------------------------------------------------------------------------------- /TWS API/samples/VB/VB_API_Sample/_DTwsEvents_execDetailsExEvent.vb: -------------------------------------------------------------------------------- 1 | ' Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | ' and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. 3 | 4 | Namespace AxTWSLib 5 | Class _DTwsEvents_execDetailsExEvent 6 | 7 | Property reqId As Integer 8 | 9 | Property contract As IBApi.Contract 10 | 11 | Property execution As IBApi.Execution 12 | 13 | End Class 14 | End Namespace 15 | -------------------------------------------------------------------------------- /TWS API/source/CppClient/client/VolumeCondition.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "ContractCondition.h" 3 | 4 | class TWSAPIDLLEXP VolumeCondition : public ContractCondition { 5 | friend OrderCondition; 6 | 7 | int m_volume; 8 | 9 | protected: 10 | VolumeCondition() { } 11 | 12 | virtual std::string valueToString() const; 13 | virtual void valueFromString(const std::string &v); 14 | 15 | public: 16 | static const OrderConditionType conditionType = OrderConditionType::Volume; 17 | 18 | int volume(); 19 | void volume(int volume); 20 | }; -------------------------------------------------------------------------------- /TWS API/source/CppClient/client/ContractCondition.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "OperatorCondition.h" 3 | 4 | class TWSAPIDLLEXP ContractCondition : public OperatorCondition { 5 | int m_conId; 6 | std::string m_exchange; 7 | 8 | public: 9 | virtual std::string toString(); 10 | virtual const char* readExternal(const char* ptr, const char* endPtr); 11 | virtual void writeExternal(std::ostream &out) const; 12 | 13 | int conId(); 14 | void conId(int conId); 15 | std::string exchange(); 16 | void exchange(const std::string &exchange); 17 | }; 18 | -------------------------------------------------------------------------------- /TWS API/source/CppClient/client/TimeCondition.cpp: -------------------------------------------------------------------------------- 1 | #include "StdAfx.h" 2 | #include "TimeCondition.h" 3 | 4 | std::string TimeCondition::valueToString() const { 5 | return m_time; 6 | } 7 | 8 | void TimeCondition::valueFromString(const std::string & v) { 9 | m_time = v; 10 | } 11 | 12 | std::string TimeCondition::toString() { 13 | return "time" + OperatorCondition::toString(); 14 | } 15 | 16 | std::string TimeCondition::time() { 17 | return m_time; 18 | } 19 | 20 | void TimeCondition::time(const std::string & time) { 21 | m_time = time; 22 | } 23 | -------------------------------------------------------------------------------- /TWS API/samples/VB/Testbed/My Project/Application.myapp: -------------------------------------------------------------------------------- 1 | 2 | 3 | false 4 | false 5 | 0 6 | true 7 | 0 8 | 2 9 | true 10 | 11 | -------------------------------------------------------------------------------- /TWS API/source/CSharpClient/client/EClientMsgSink.cs: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2015 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | 8 | namespace IBApi 9 | { 10 | interface EClientMsgSink 11 | { 12 | void serverVersion(int version, string time); 13 | void redirect(string host); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /TWS API/source/CppClient/client/SoftDollarTier.cpp: -------------------------------------------------------------------------------- 1 | #include "StdAfx.h" 2 | #include "SoftDollarTier.h" 3 | 4 | SoftDollarTier::SoftDollarTier(const std::string& name, const std::string& val, const std::string& displayName) : 5 | m_name(name), m_val(val), m_displayName(displayName) 6 | { 7 | } 8 | 9 | std::string SoftDollarTier::name() const 10 | { 11 | return m_name; 12 | } 13 | 14 | std::string SoftDollarTier::val() const 15 | { 16 | return m_val; 17 | } 18 | 19 | std::string SoftDollarTier::displayName() const 20 | { 21 | return m_displayName; 22 | } -------------------------------------------------------------------------------- /TradeBot/FileIO/PropertySerializer.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using System.IO; 3 | 4 | namespace TradeBot.FileIO 5 | { 6 | public static class PropertySerializer 7 | { 8 | public static T Deserialize(string path) 9 | { 10 | return JsonConvert.DeserializeObject(File.ReadAllText(path)); 11 | } 12 | 13 | public static void Serialize(T propertyClass, string path) 14 | { 15 | File.WriteAllText(path, JsonConvert.SerializeObject(propertyClass)); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /TWS API/samples/VB/VB_API_Sample/_DTwsEvents_positionEvent.vb: -------------------------------------------------------------------------------- 1 | ' Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | ' and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. 3 | 4 | Namespace AxTWSLib 5 | Class _DTwsEvents_positionEvent 6 | 7 | Property account As String 8 | 9 | Property contract As IBApi.Contract 10 | 11 | Property pos As Integer 12 | 13 | Property avgCost As Double 14 | 15 | End Class 16 | End Namespace 17 | -------------------------------------------------------------------------------- /TWS API/source/CppClient/client/EReaderWMSignal.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | 4 | #pragma once 5 | #include "ereadersignal.h" 6 | 7 | class EReaderWMSignal : 8 | public EReaderSignal 9 | { 10 | HWND m_hWnd; 11 | int m_msg; 12 | 13 | public: 14 | EReaderWMSignal(HWND hWnd, int msg); 15 | 16 | virtual void issueSignal(); 17 | virtual void waitForSignal(); 18 | }; 19 | 20 | -------------------------------------------------------------------------------- /TWS API/source/CppClient/client/OperatorCondition.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "OrderCondition.h" 3 | 4 | class TWSAPIDLLEXP OperatorCondition : public OrderCondition { 5 | bool m_isMore; 6 | 7 | protected: 8 | virtual std::string valueToString() const = 0; 9 | virtual void valueFromString(const std::string &v) = 0; 10 | 11 | public: 12 | virtual const char* readExternal(const char* ptr, const char* endPtr); 13 | virtual std::string toString(); 14 | virtual void writeExternal(std::ostream &out) const; 15 | 16 | bool isMore(); 17 | void isMore(bool isMore); 18 | }; -------------------------------------------------------------------------------- /TWS API/samples/VB/VB_API_Sample/_DTwsEvents_tickPriceEvent.vb: -------------------------------------------------------------------------------- 1 | ' Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | ' and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. 3 | 4 | Namespace AxTWSLib 5 | Friend Class _DTwsEvents_tickPriceEvent 6 | 7 | Property id As Integer 8 | 9 | Property tickType As Utils.TickType 10 | 11 | Property price As Double 12 | 13 | Property canAutoExecute As Integer 14 | 15 | End Class 16 | End Namespace 17 | -------------------------------------------------------------------------------- /TWS API/samples/VB/VB_API_Sample/_DTwsEvents_updateAccountValueEvent.vb: -------------------------------------------------------------------------------- 1 | ' Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | ' and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. 3 | 4 | Namespace AxTWSLib 5 | Class _DTwsEvents_updateAccountValueEvent 6 | 7 | Property key As String 8 | 9 | Property value As String 10 | 11 | Property currency As String 12 | 13 | Property accountName As String 14 | 15 | End Class 16 | End Namespace 17 | -------------------------------------------------------------------------------- /TradeBot/MenuFramework/MenuDivider.cs: -------------------------------------------------------------------------------- 1 | namespace TradeBot.MenuFramework 2 | { 3 | public class MenuDivider : MenuItem 4 | { 5 | public MenuDivider(string dividerString = null) 6 | { 7 | DividerString = dividerString; 8 | } 9 | 10 | public string DividerString { get; set; } 11 | 12 | public string Render() 13 | { 14 | if (DividerString == null) 15 | { 16 | return string.Empty; 17 | } 18 | 19 | return DividerString; 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /TWS API/samples/CSharp/IBSampleApp/messages/SecurityDefinitionOptionParameterEndMessage.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace IBSampleApp.ui 7 | { 8 | class SecurityDefinitionOptionParameterEndMessage : IBMessage 9 | { 10 | private int reqId; 11 | 12 | public SecurityDefinitionOptionParameterEndMessage(int reqId) 13 | { 14 | this.Type = MessageType.SecurityDefinitionOptionParameterEnd; 15 | this.reqId = reqId; 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /TWS API/samples/VB/VB_API_Sample/_DTwsEvents_updateNewsBulletinEvent.vb: -------------------------------------------------------------------------------- 1 | ' Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | ' and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. 3 | 4 | Namespace AxTWSLib 5 | Class _DTwsEvents_updateNewsBulletinEvent 6 | 7 | Property msgId As Integer 8 | 9 | Property msgType As Integer 10 | 11 | Property message As String 12 | 13 | Property origExchange As String 14 | 15 | End Class 16 | End Namespace 17 | -------------------------------------------------------------------------------- /TWS API/source/CSharpClient/activex/ComWrappers/ComWrapper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace TWSLib 7 | { 8 | public abstract class ComWrapper where T : new() 9 | { 10 | protected T data = new T(); 11 | 12 | public T ConvertTo() 13 | { 14 | return this.data; 15 | } 16 | 17 | public ComWrapper ConvertFrom(T value) 18 | { 19 | this.data = value; 20 | 21 | return this; 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /TWS API/source/CppClient/client/ESocket.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "ETransport.h" 3 | 4 | class ESocket : 5 | public ETransport 6 | { 7 | int m_fd; 8 | std::vector m_outBuffer; 9 | 10 | int bufferedSend(const char* buf, size_t sz); 11 | int send(const char* buf, size_t sz); 12 | void CleanupBuffer(std::vector& buffer, int processed); 13 | 14 | public: 15 | ESocket(); 16 | ~ESocket(void); 17 | 18 | int send(EMessage *pMsg); 19 | bool isOutBufferEmpty() const; 20 | int sendBufferedData(); 21 | void fd(int fd); 22 | }; 23 | 24 | -------------------------------------------------------------------------------- /TradeBot/AppProperties.cs: -------------------------------------------------------------------------------- 1 | using TradeBot.FileIO; 2 | using TradeBot.Generated; 3 | 4 | namespace TradeBot 5 | { 6 | public static class AppProperties 7 | { 8 | public static AppPreferences Preferences { get; } 9 | public static AppMessages Messages { get; } 10 | 11 | static AppProperties() 12 | { 13 | Preferences = PropertySerializer.Deserialize(PropertyFiles.PREFERENCES_FILE); 14 | Messages = PropertySerializer.Deserialize(PropertyFiles.MESSAGES_FILE); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /TradeBot/TwsAbstractions/ContractFactory.cs: -------------------------------------------------------------------------------- 1 | using IBApi; 2 | 3 | namespace TradeBot.TwsAbstractions 4 | { 5 | public static class ContractFactory 6 | { 7 | public static Contract CreateStockContract(string tickerSymbol) 8 | { 9 | return new Contract() 10 | { 11 | Symbol = tickerSymbol.ToUpper(), 12 | SecType = SecurityTypes.STK.ToString(), 13 | Currency = Currencies.USD.ToString(), 14 | Exchange = Exchanges.SMART.ToString() 15 | }; 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /TWS API/samples/Cpp/TestCppClientSSL/Makefile.linux: -------------------------------------------------------------------------------- 1 | CXX=g++ 2 | CXXFLAGS=-pthread -Wall -Wno-switch -std=c++11 -Wfatal-errors 3 | LIBFLAGS=-L/usr/lib -lssl -lcrypto 4 | ROOT_DIR=../../../source/cppclient 5 | BASE_SRC_DIR=${ROOT_DIR}/client 6 | BASE_SRC_SSL_DIR=${ROOT_DIR}/ssl 7 | OPENSSL_DIR=/usr/include/openssl 8 | INCLUDES=-I${BASE_SRC_DIR} -I${ROOT_DIR} -I{OPENSSL_DIR} 9 | TARGET=TestCppClientSSL 10 | 11 | $(TARGET): 12 | $(CXX) $(CXXFLAGS) $(INCLUDES) $(BASE_SRC_DIR)/*.cpp $(BASE_SRC_SSL_DIR)/*.cpp ./*.cpp -o$(TARGET) $(LIBFLAGS) 13 | 14 | clean: 15 | rm -f $(TARGET) *.o 16 | 17 | -------------------------------------------------------------------------------- /TWS API/samples/VB/VB_API_Sample/_DTwsEvents_openOrderExEvent.vb: -------------------------------------------------------------------------------- 1 | ' Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | ' and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. 3 | 4 | Namespace AxTWSLib 5 | Class _DTwsEvents_openOrderExEvent 6 | 7 | Property orderId As Integer 8 | 9 | Property contract As IBApi.Contract 10 | 11 | Property order As IBApi.Order 12 | 13 | Property orderState As IBApi.OrderState 14 | 15 | End Class 16 | End Namespace 17 | -------------------------------------------------------------------------------- /TWS API/source/CppClient/client/VolumeCondition.cpp: -------------------------------------------------------------------------------- 1 | #include "StdAfx.h" 2 | #include "VolumeCondition.h" 3 | #include 4 | 5 | std::string VolumeCondition::valueToString() const { 6 | std::stringstream tmp; 7 | 8 | tmp << m_volume; 9 | 10 | return tmp.str(); 11 | } 12 | 13 | void VolumeCondition::valueFromString(const std::string & v) { 14 | std::stringstream tmp; 15 | 16 | tmp << v; 17 | tmp >> m_volume; 18 | } 19 | 20 | int VolumeCondition::volume() { 21 | return m_volume; 22 | } 23 | 24 | void VolumeCondition::volume(int volume) { 25 | m_volume = volume; 26 | } 27 | -------------------------------------------------------------------------------- /TWS API/source/CppClient/client/MarginCondition.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "OperatorCondition.h" 3 | 4 | class TWSAPIDLLEXP MarginCondition : public OperatorCondition { 5 | friend OrderCondition; 6 | 7 | int m_percent; 8 | 9 | public: 10 | static const OrderConditionType conditionType = OrderConditionType::Margin; 11 | 12 | protected: 13 | MarginCondition() { } 14 | 15 | virtual std::string valueToString() const; 16 | virtual void valueFromString(const std::string &v); 17 | 18 | public: 19 | virtual std::string toString(); 20 | 21 | int percent(); 22 | void percent(int percent); 23 | }; -------------------------------------------------------------------------------- /TWS API/source/CppClient/client/TimeCondition.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "OperatorCondition.h" 3 | 4 | class TWSAPIDLLEXP TimeCondition : public OperatorCondition { 5 | friend OrderCondition; 6 | 7 | std::string m_time; 8 | 9 | protected: 10 | TimeCondition() { } 11 | 12 | virtual std::string valueToString() const; 13 | virtual void valueFromString(const std::string &v); 14 | 15 | public: 16 | static const OrderConditionType conditionType = OrderConditionType::Time; 17 | 18 | virtual std::string toString(); 19 | 20 | std::string time(); 21 | void time(const std::string &time); 22 | }; -------------------------------------------------------------------------------- /TWS API/samples/VB/VB_API_Sample/_DTwsEvents_accountSummaryEvent.vb: -------------------------------------------------------------------------------- 1 | ' Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | ' and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. 3 | 4 | Namespace AxTWSLib 5 | Class _DTwsEvents_accountSummaryEvent 6 | 7 | Property reqId As Integer 8 | 9 | Property account As String 10 | 11 | Property tag As String 12 | 13 | Property value As String 14 | 15 | Property currency As String 16 | 17 | End Class 18 | End Namespace 19 | -------------------------------------------------------------------------------- /TWS API/source/CppClient/client/EMessage.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | 4 | #include "StdAfx.h" 5 | #include "EMessage.h" 6 | 7 | 8 | EMessage::EMessage(const std::vector &data) { 9 | this->data = data; 10 | } 11 | 12 | const char* EMessage::begin(void) const 13 | { 14 | return data.data(); 15 | } 16 | 17 | const char* EMessage::end(void) const 18 | { 19 | return data.data() + data.size(); 20 | } 21 | -------------------------------------------------------------------------------- /TWS API/source/CppClient/ssl/ESocketSSL.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "../client/ETransport.h" 3 | 4 | class ESocketSSL : 5 | public ETransport 6 | { 7 | SSL *m_fd; 8 | std::vector m_outBuffer; 9 | 10 | int bufferedSend(const char* buf, size_t sz); 11 | int send(const char* buf, size_t sz); 12 | void CleanupBuffer(std::vector& buffer, int processed); 13 | 14 | public: 15 | ESocketSSL(); 16 | ~ESocketSSL(void); 17 | 18 | int send(EMessage *pMsg); 19 | bool isOutBufferEmpty() const; 20 | int sendBufferedData(); 21 | void fd(SSL *fd); 22 | }; 23 | 24 | -------------------------------------------------------------------------------- /TWS API/samples/VB/VB_API_Sample/_DTWsEvents_securityDefinitionOptionParameterEvent.vb: -------------------------------------------------------------------------------- 1 | Imports System.Collections.Generic 2 | 3 | Namespace AxTWSLib 4 | Class _DTWsEvents_securityDefinitionOptionParameterEvent 5 | 6 | Property reqId As Integer 7 | 8 | Property exchange As String 9 | 10 | Property underlyingConId As Integer 11 | 12 | Property tradingClass As String 13 | 14 | Property multiplier As String 15 | 16 | Property expirations As HashSet(Of String) 17 | 18 | Property strikes As HashSet(Of Double) 19 | 20 | End Class 21 | End Namespace 22 | -------------------------------------------------------------------------------- /TWS API/source/JavaClient/com/ib/client/OrderConditionType.java: -------------------------------------------------------------------------------- 1 | package com.ib.client; 2 | 3 | public enum OrderConditionType { 4 | Price(1), 5 | Time(3), 6 | Margin(4), 7 | Execution(5), 8 | Volume(6), 9 | PercentChange(7); 10 | 11 | private int m_val; 12 | 13 | OrderConditionType(int v) { 14 | m_val = v; 15 | } 16 | 17 | public int val() { 18 | return m_val; 19 | } 20 | 21 | public static OrderConditionType fromInt(int n) { 22 | for (OrderConditionType i : OrderConditionType.values()) 23 | if (i.val() == n) 24 | return i; 25 | 26 | throw new NumberFormatException(); 27 | } 28 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | x64/ 19 | x86/ 20 | bld/ 21 | [Bb]in/ 22 | [Oo]bj/ 23 | [Ll]og/ 24 | 25 | # Visual Studio 2015 cache/options directory 26 | .vs/ 27 | 28 | # Mac specific files 29 | .DS_Store 30 | 31 | # Project specific 32 | tws_api/ 33 | *.exe 34 | -------------------------------------------------------------------------------- /TWS API/samples/CSharp/IBSampleApp/messages/OpenOrderEndMessage.cs: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | 8 | namespace IBSampleApp.messages 9 | { 10 | public class OpenOrderEndMessage : OrderMessage 11 | { 12 | public OpenOrderEndMessage() 13 | { 14 | Type = MessageType.OpenOrderEnd; 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /TWS API/samples/Java/apidemo/TimeConditionPanel.java: -------------------------------------------------------------------------------- 1 | package apidemo; 2 | 3 | import com.ib.client.OrderCondition; 4 | import com.ib.client.TimeCondition; 5 | 6 | public class TimeConditionPanel extends OperatorConditionPanel { 7 | 8 | public TimeConditionPanel(TimeCondition condition) { 9 | super(condition); 10 | 11 | m_value.setText(condition().time()); 12 | 13 | add("Operator", m_operator); 14 | add("Time", m_value); 15 | } 16 | 17 | @Override 18 | public OrderCondition onOK() { 19 | super.onOK(); 20 | condition().time(m_value.getText()); 21 | 22 | return condition(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /TWS API/source/JavaClient/com/ib/contracts/StkContract.java: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | 4 | package com.ib.contracts; 5 | 6 | import com.ib.client.Contract; 7 | import com.ib.client.Types.SecType; 8 | 9 | public class StkContract extends Contract { 10 | public StkContract(String symbol) { 11 | symbol(symbol); 12 | secType(SecType.STK.name()); 13 | exchange("SMART"); 14 | currency("USD"); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /TWS API/source/JavaClient/com/ib/controller/TradeId.java: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | 4 | package com.ib.controller; 5 | 6 | public class TradeId { 7 | private String m_key; 8 | private String m_full; 9 | 10 | public String key() { return m_key; } 11 | public String full() { return m_full; } 12 | 13 | public TradeId( String id) { 14 | m_full = id; 15 | int i = id.lastIndexOf( '.'); 16 | m_key = id.substring( i + 1); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /TWS API/samples/Java/apidemo/MarginContidionPanel.java: -------------------------------------------------------------------------------- 1 | package apidemo; 2 | 3 | import com.ib.client.MarginCondition; 4 | import com.ib.client.OrderCondition; 5 | 6 | public class MarginContidionPanel extends OperatorConditionPanel { 7 | 8 | public MarginContidionPanel(MarginCondition condition) { 9 | super(condition); 10 | 11 | m_value.setText(condition().percent()); 12 | 13 | add("Operator", m_operator); 14 | add("Cushion (%)", m_value); 15 | } 16 | 17 | public OrderCondition onOK() { 18 | super.onOK(); 19 | condition().percent(m_value.getInt()); 20 | 21 | return condition(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /TWS API/samples/CSharp/IBSampleApp/messages/ContractDetailsEndMessage.cs: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | 8 | namespace IBSampleApp.messages 9 | { 10 | public class ContractDetailsEndMessage : IBMessage 11 | { 12 | public ContractDetailsEndMessage() 13 | { 14 | Type = MessageType.ContractDataEnd; 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /TWS API/samples/CSharp/IBSampleApp/ui/SoftDollarTiersMessage.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace IBSampleApp.ui 7 | { 8 | class SoftDollarTiersMessage : IBMessage 9 | { 10 | public int ReqId { get; private set; } 11 | public IBApi.SoftDollarTier[] Tiers { get; private set; } 12 | 13 | public SoftDollarTiersMessage(int reqId, IBApi.SoftDollarTier[] tiers) 14 | { 15 | this.type = MessageType.SoftDollarTiers; 16 | this.ReqId = reqId; 17 | this.Tiers = tiers; 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /TradeBot/Generated/AppState.cs: -------------------------------------------------------------------------------- 1 | // Generated by Xamasoft JSON Class Generator 2 | // http://www.xamasoft.com/json-class-generator 3 | 4 | using System; 5 | using System.Collections.Generic; 6 | using Newtonsoft.Json; 7 | using Newtonsoft.Json.Linq; 8 | 9 | namespace TradeBot.Generated 10 | { 11 | 12 | public class AppState 13 | { 14 | 15 | [JsonProperty("tickerSymbol")] 16 | public string TickerSymbol { get; set; } 17 | 18 | [JsonProperty("cash")] 19 | public double? Cash { get; set; } 20 | 21 | [JsonProperty("shares")] 22 | public double? Shares { get; set; } 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /TWS API/source/CSharpClient/client/EClientException.cs: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2015 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | 8 | namespace IBApi 9 | { 10 | public class EClientException : Exception 11 | { 12 | public CodeMsgPair Err { get; private set; } 13 | 14 | public EClientException(CodeMsgPair err) 15 | { 16 | this.Err = err; 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /TWS API/samples/VB/VB_API_Sample/_DTwsEvents_accountUpdateMultiEvent.vb: -------------------------------------------------------------------------------- 1 | ' Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | ' and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. 3 | 4 | Namespace AxTWSLib 5 | Class _DTwsEvents_accountUpdateMultiEvent 6 | 7 | Property reqId As Integer 8 | 9 | Property account As String 10 | 11 | Property modelCode As String 12 | 13 | Property key As String 14 | 15 | Property value As String 16 | 17 | Property currency As String 18 | 19 | End Class 20 | End Namespace 21 | -------------------------------------------------------------------------------- /TWS API/samples/VB/VB_API_Sample/_DTwsEvents_positionMultiEvent.vb: -------------------------------------------------------------------------------- 1 | ' Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | ' and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. 3 | 4 | Namespace AxTWSLib 5 | Class _DTwsEvents_positionMultiEvent 6 | 7 | Property reqId As Integer 8 | 9 | Property account As String 10 | 11 | Property modelCode As String 12 | 13 | Property contract As IBApi.Contract 14 | 15 | Property pos As Integer 16 | 17 | Property avgCost As Double 18 | 19 | End Class 20 | End Namespace 21 | -------------------------------------------------------------------------------- /TWS API/samples/VB/VB_API_Sample/_DTwsEvents_updateMktDepthEvent.vb: -------------------------------------------------------------------------------- 1 | ' Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | ' and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. 3 | 4 | Namespace AxTWSLib 5 | Public Class _DTwsEvents_updateMktDepthEvent 6 | 7 | Property tickerId As Integer 8 | 9 | Property position As Integer 10 | 11 | Property operation As Integer 12 | 13 | Property side As Integer 14 | 15 | Property price As Double 16 | 17 | Property size As Integer 18 | 19 | End Class 20 | End Namespace 21 | -------------------------------------------------------------------------------- /TWS API/source/CSharpClient/activex/ControlImpl/IOrderComboLeg.cs: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Runtime.InteropServices; 8 | using System.Text; 9 | 10 | namespace TWSLib 11 | { 12 | [Guid("639C4479-D0B6-49a3-B524-AEA6A9574945"), ComVisible(true)] 13 | public interface IOrderComboLeg 14 | { 15 | [DispId(1)] 16 | double price { get; set; } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /TWS API/samples/Java/apidemo/util/TCombo.java: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | 4 | package apidemo.util; 5 | 6 | import javax.swing.JComboBox; 7 | 8 | public class TCombo extends JComboBox { 9 | public TCombo( T... strs) { 10 | super( strs); 11 | } 12 | 13 | public String getText() { 14 | return getSelectedItem() == null ? null : getSelectedItem().toString(); 15 | } 16 | 17 | @Override public T getSelectedItem() { 18 | return (T)super.getSelectedItem(); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /TWS API/source/CppClient/client/EMutex.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | 4 | #pragma once 5 | 6 | #include "StdAfx.h" 7 | 8 | class TWSAPIDLLEXP EMutex 9 | { 10 | #if defined(IB_POSIX) 11 | pthread_mutex_t cs; 12 | #elif defined(IB_WIN32) 13 | CRITICAL_SECTION cs; 14 | #else 15 | # error "Not implemented on this platform" 16 | #endif 17 | 18 | public: 19 | EMutex(); 20 | ~EMutex(); 21 | bool TryEnter(); 22 | void Enter(); 23 | void Leave(); 24 | }; 25 | 26 | -------------------------------------------------------------------------------- /TWS API/source/CppClient/client/PercentChangeCondition.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "ContractCondition.h" 3 | #include "Order.h" 4 | 5 | class TWSAPIDLLEXP PercentChangeCondition : public ContractCondition { 6 | friend OrderCondition; 7 | 8 | double m_changePercent; 9 | 10 | protected: 11 | PercentChangeCondition() 12 | : m_changePercent(UNSET_DOUBLE) 13 | { } 14 | 15 | virtual std::string valueToString() const; 16 | virtual void valueFromString(const std::string &v); 17 | 18 | public: 19 | static const OrderConditionType conditionType = OrderConditionType::PercentChange; 20 | 21 | double changePercent(); 22 | void changePercent(double changePercent); 23 | }; -------------------------------------------------------------------------------- /TWS API/samples/CSharp/IBSampleApp/messages/IBMessage.cs: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | using IBApi; 8 | 9 | namespace IBSampleApp 10 | { 11 | public abstract class IBMessage 12 | { 13 | protected MessageType type; 14 | 15 | public MessageType Type 16 | { 17 | get { return type; } 18 | set { type = value; } 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /TWS API/source/CSharpClient/client/EMessage.cs: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2015 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | 8 | namespace IBApi 9 | { 10 | public class EMessage 11 | { 12 | byte[] buf; 13 | 14 | public EMessage(byte[] buf) 15 | { 16 | this.buf = buf; 17 | } 18 | 19 | public byte[] GetBuf() 20 | { 21 | return buf; 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /TWS API/samples/CSharp/IBSampleApp/messages/OrderMessage.cs: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | 8 | namespace IBSampleApp.messages 9 | { 10 | public abstract class OrderMessage : IBMessage 11 | { 12 | protected int orderId; 13 | 14 | public int OrderId 15 | { 16 | get { return orderId; } 17 | set { orderId = value; } 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /TWS API/source/CppClient/client/PercentChangeCondition.cpp: -------------------------------------------------------------------------------- 1 | #include "StdAfx.h" 2 | #include "PercentChangeCondition.h" 3 | #include 4 | 5 | std::string PercentChangeCondition::valueToString() const { 6 | std::stringstream tmp; 7 | 8 | tmp << m_changePercent; 9 | 10 | return tmp.str(); 11 | } 12 | 13 | void PercentChangeCondition::valueFromString(const std::string & v) { 14 | std::stringstream tmp; 15 | 16 | tmp << v; 17 | tmp >> m_changePercent; 18 | } 19 | 20 | double PercentChangeCondition::changePercent() { 21 | return m_changePercent; 22 | } 23 | 24 | void PercentChangeCondition::changePercent(double changePercent) { 25 | m_changePercent = changePercent; 26 | } 27 | -------------------------------------------------------------------------------- /TWS API/source/JavaClient/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | 4 | com.interactivebrokers 5 | tws-api 6 | 9.72.17-SNAPSHOT 7 | 8 | 9 | UTF-8 10 | 11 | 12 | 13 | . 14 | build 15 | 16 | 17 | -------------------------------------------------------------------------------- /TWS API/source/JavaClient/com/ib/controller/Instrument.java: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | 4 | package com.ib.controller; 5 | 6 | public enum Instrument { 7 | STK, 8 | BOND, 9 | EFP, 10 | FUT_EU, 11 | FUT_HK, 12 | FUT_NA, 13 | FUT_US, 14 | IND_EU, 15 | IND_HK, 16 | IND_US, 17 | PMONITOR, 18 | PMONITORM, 19 | SLB_US, 20 | STOCK_EU, 21 | STOCK_HK, 22 | STOCK_NA, 23 | WAR_EU; 24 | 25 | @Override 26 | public String toString() { 27 | return super.toString().replace( '_', '.'); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /TWS API/samples/Java/apidemo/util/IConnectionConfiguration.java: -------------------------------------------------------------------------------- 1 | package apidemo.util; 2 | 3 | 4 | /** Delegate for connection parameters */ 5 | public interface IConnectionConfiguration { 6 | 7 | public String getDefaultHost(); 8 | public String getDefaultPort(); 9 | public String getDefaultConnectOptions(); 10 | 11 | /** Standard ApiDemo configuration for pre-v100 connection */ 12 | public static class DefaultConnectionConfiguration implements IConnectionConfiguration { 13 | @Override public String getDefaultHost() { return ""; } 14 | @Override public String getDefaultPort() { return "7496"; } 15 | @Override public String getDefaultConnectOptions() { return null; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /TradeBot/TwsAbstractions/OrderFactory.cs: -------------------------------------------------------------------------------- 1 | using IBApi; 2 | 3 | namespace TradeBot.TwsAbstractions 4 | { 5 | public static class OrderFactory 6 | { 7 | public static Order CreateLimitOrder(OrderActions action, double quantity, double limitPrice) 8 | { 9 | return new Order() 10 | { 11 | Action = action.ToString(), 12 | TotalQuantity = quantity, 13 | LmtPrice = limitPrice, 14 | OrderType = OrderTypes.LMT.ToString(), 15 | Tif = TimeInForce.GTC.ToString(), 16 | Transmit = true, 17 | OutsideRth = true 18 | }; 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /TWS API/samples/VB/VB_API_Sample/_DTwsEvents_updateMktDepthL2Event.vb: -------------------------------------------------------------------------------- 1 | ' Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | ' and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. 3 | 4 | Namespace AxTWSLib 5 | Class _DTwsEvents_updateMktDepthL2Event 6 | 7 | Property tickerId As Integer 8 | 9 | Property position As Integer 10 | 11 | Property marketMaker As String 12 | 13 | Property operation As Integer 14 | 15 | Property side As Integer 16 | 17 | Property price As Double 18 | 19 | Property size As Integer 20 | 21 | End Class 22 | End Namespace 23 | -------------------------------------------------------------------------------- /TWS API/source/JavaClient/com/ib/controller/Alias.java: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | 4 | package com.ib.controller; 5 | 6 | public class Alias { 7 | private String m_account; 8 | private String m_alias; 9 | 10 | public String alias() { return m_alias; } 11 | public String account() { return m_account; } 12 | 13 | public void alias( String v) { m_alias = v; } 14 | public void account( String v) { m_account = v; } 15 | 16 | @Override public String toString() { 17 | return m_account + " / " + m_alias; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /TWS API/samples/Java/apidemo/ContractConditionPanel.java: -------------------------------------------------------------------------------- 1 | package apidemo; 2 | 3 | import com.ib.client.ContractCondition; 4 | import com.ib.client.ContractLookuper; 5 | 6 | public class ContractConditionPanel extends OperatorConditionPanel { 7 | public ContractConditionPanel(ContractCondition c, ContractLookuper lookuper) { 8 | super(c); 9 | 10 | final ContractCondition condition = (ContractCondition)m_condition; 11 | 12 | add(new ContractLookupButton(condition.conId(), condition.exchange(), lookuper) { 13 | protected void actionPerformed(int refConId, String refExchId) { 14 | condition.conId(refConId); 15 | condition.exchange(refExchId); 16 | } 17 | }); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /TWS API/source/CppClient/client/res/TwsSocketClient.rc2: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | 4 | // 5 | // TWSSOCKETCLIENT.RC2 - resources Microsoft Visual C++ does not edit directly 6 | // 7 | 8 | #ifdef APSTUDIO_INVOKED 9 | #error this file is not editable by Microsoft Visual C++ 10 | #endif //APSTUDIO_INVOKED 11 | 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | // Add manually edited resources here... 15 | 16 | ///////////////////////////////////////////////////////////////////////////// 17 | -------------------------------------------------------------------------------- /TWS API/source/CppClient/ssl/res/TwsSocketClientSSL.rc2: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | 4 | // 5 | // TWSSOCKETCLIENT.RC2 - resources Microsoft Visual C++ does not edit directly 6 | // 7 | 8 | #ifdef APSTUDIO_INVOKED 9 | #error this file is not editable by Microsoft Visual C++ 10 | #endif //APSTUDIO_INVOKED 11 | 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | // Add manually edited resources here... 15 | 16 | ///////////////////////////////////////////////////////////////////////////// 17 | -------------------------------------------------------------------------------- /TWS API/samples/Java/apidemo/OptionsPanel.java: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | 4 | package apidemo; 5 | 6 | import apidemo.util.NewTabbedPanel; 7 | 8 | public class OptionsPanel extends NewTabbedPanel { 9 | private final OptionChainsPanel m_optionChains = new OptionChainsPanel(); 10 | private final ExercisePanel m_exercisePanel = new ExercisePanel(); 11 | 12 | OptionsPanel() { 13 | NewTabbedPanel tabs = this; 14 | tabs.addTab( "Option Chains", m_optionChains); 15 | tabs.addTab( "Option Exercise", m_exercisePanel); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /TWS API/source/CSharpClient/activex/ControlImpl/ITagValue.cs: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Runtime.InteropServices; 8 | using System.Text; 9 | 10 | namespace TWSLib 11 | { 12 | [ComVisible(true)] 13 | [Guid("06FF1D3F-F12F-47D1-9443-A74D3CD58723")] 14 | public interface ITagValue 15 | { 16 | [DispId(1)] 17 | string tag { get; set; } 18 | [DispId(2)] 19 | string value { get; set; } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /TWS API/source/CppClient/client/Resource.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | 4 | //{{NO_DEPENDENCIES}} 5 | // Microsoft Visual C++ generated include file. 6 | // Used by TWSSOCKETCLIENT.RC 7 | // 8 | 9 | // Next default values for new objects 10 | // 11 | #ifdef APSTUDIO_INVOKED 12 | #ifndef APSTUDIO_READONLY_SYMBOLS 13 | 14 | #define _APS_NEXT_RESOURCE_VALUE 129 15 | #define _APS_NEXT_COMMAND_VALUE 32771 16 | #define _APS_NEXT_CONTROL_VALUE 1000 17 | #define _APS_NEXT_SYMED_VALUE 101 18 | #endif 19 | #endif 20 | -------------------------------------------------------------------------------- /TWS API/samples/VB/VB_API_Sample/_DTwsEvents_scannerDataExEvent.vb: -------------------------------------------------------------------------------- 1 | ' Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | ' and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. 3 | 4 | Namespace AxTWSLib 5 | Class _DTwsEvents_scannerDataExEvent 6 | 7 | Property reqId As Integer 8 | 9 | Property rank As Integer 10 | 11 | Property contractDetails As IBApi.ContractDetails 12 | 13 | Property distance As String 14 | 15 | Property benchmark As String 16 | 17 | Property projection As String 18 | 19 | Property legsStr As String 20 | 21 | End Class 22 | End Namespace 23 | -------------------------------------------------------------------------------- /TWS API/source/CppClient/client/MarginCondition.cpp: -------------------------------------------------------------------------------- 1 | #include "StdAfx.h" 2 | #include "MarginCondition.h" 3 | #include 4 | 5 | std::string MarginCondition::valueToString() const { 6 | std::stringstream tmp; 7 | 8 | tmp << m_percent; 9 | 10 | return tmp.str(); 11 | } 12 | 13 | void MarginCondition::valueFromString(const std::string & v) { 14 | std::stringstream tmp; 15 | 16 | tmp << v; 17 | tmp >> m_percent; 18 | } 19 | 20 | std::string MarginCondition::toString() { 21 | return "the margin cushion percent" + OperatorCondition::toString(); 22 | } 23 | 24 | int MarginCondition::percent() { 25 | return m_percent; 26 | } 27 | 28 | void MarginCondition::percent(int percent) { 29 | m_percent = percent; 30 | } 31 | -------------------------------------------------------------------------------- /TWS API/source/CSharpClient/client/VolumeCondition.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace IBApi 7 | { 8 | /** 9 | * @brief Used with conditional orders to submit or cancel an order based on a specified volume change in a security. 10 | */ 11 | public class VolumeCondition : ContractCondition 12 | { 13 | protected override string Value 14 | { 15 | get 16 | { 17 | return Volume.ToString(); 18 | } 19 | set 20 | { 21 | Volume = int.Parse(value); 22 | } 23 | } 24 | 25 | public int Volume { get; set; } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /TWS API/source/JavaClient/com/ib/client/TimeCondition.java: -------------------------------------------------------------------------------- 1 | package com.ib.client; 2 | 3 | public class TimeCondition extends OperatorCondition { 4 | 5 | public static final OrderConditionType conditionType = OrderConditionType.Time; 6 | 7 | protected TimeCondition() { } 8 | 9 | @Override 10 | public String toString() { 11 | return "time" + super.toString(); 12 | } 13 | 14 | private String m_time; 15 | 16 | public String time() { 17 | return m_time; 18 | } 19 | 20 | public void time(String m_time) { 21 | this.m_time = m_time; 22 | } 23 | 24 | @Override 25 | protected String valueToString() { 26 | return m_time; 27 | } 28 | 29 | @Override 30 | protected void valueFromString(String v) { 31 | m_time = v; 32 | } 33 | 34 | } -------------------------------------------------------------------------------- /TWS API/source/CSharpClient/activex/ControlImpl/IUnderComp.cs: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Runtime.InteropServices; 7 | using System.Text; 8 | 9 | namespace TWSLib 10 | { 11 | [ComVisible(true), Guid("E5EE73C4-7D45-428E-A347-821CBF918AA6")] 12 | public interface IUnderComp 13 | { 14 | [DispId(1)] 15 | int conId { get; set; } 16 | [DispId(2)] 17 | double delta { get; set; } 18 | [DispId(3)] 19 | double price { get; set; } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /TradeBot/Scripts/readme.txt: -------------------------------------------------------------------------------- 1 | Windows Setup Instructions 2 | == 3 | 1. Install the NuGet package manager and add it to your PATH 4 | 2. Run the following command to install the latest C# compiler: 5 | nuget install Microsoft.Net.Compilers 6 | 3. Add the folder containing csc.exe to your PATH 7 | 8 | Mac/Unix Setup Instructions 9 | == 10 | 1. Install MonoDevelop. This should install the mcs and mono commands 11 | 2. Give the script execute permission 12 | chmod +x script_name 13 | 14 | Notes 15 | == 16 | Windows and Mac/Unix use parallel but different commands to compile 17 | and executable a C# application. This script will always run both versions 18 | of the commands for robustness and simplicity. The "Command not found" 19 | warnings can be ignored. 20 | -------------------------------------------------------------------------------- /TWS API/samples/VB/VB_API_Sample/_DTwsEvents_realtimeBarEvent.vb: -------------------------------------------------------------------------------- 1 | ' Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | ' and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. 3 | 4 | Namespace AxTWSLib 5 | Class _DTwsEvents_realtimeBarEvent 6 | 7 | Property reqId As Integer 8 | 9 | Property time As Long 10 | 11 | Property open As Double 12 | 13 | Property high As Double 14 | 15 | Property low As Double 16 | 17 | Property close As Double 18 | 19 | Property volume As Long 20 | 21 | Property WAP As Double 22 | 23 | Property count As Integer 24 | 25 | End Class 26 | End Namespace 27 | -------------------------------------------------------------------------------- /TWS API/source/JavaClient/com/ib/client/EJavaSignal.java: -------------------------------------------------------------------------------- 1 | package com.ib.client; 2 | 3 | 4 | public class EJavaSignal implements EReaderSignal { 5 | Object monitor = new Object(); 6 | Boolean open = false; 7 | 8 | @Override 9 | public void issueSignal() { 10 | synchronized (monitor) { 11 | open = true; 12 | monitor.notifyAll(); 13 | } 14 | } 15 | 16 | @Override 17 | public void waitForSignal() { 18 | synchronized (monitor) { 19 | while (!open) { 20 | try { 21 | monitor.wait(); 22 | } catch (InterruptedException e) { 23 | // TODO Auto-generated catch block 24 | e.printStackTrace(); 25 | } 26 | } 27 | 28 | open = false; 29 | } 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /TWS API/samples/Java/apidemo/PercentConditionPanel.java: -------------------------------------------------------------------------------- 1 | package apidemo; 2 | 3 | import com.ib.client.ContractLookuper; 4 | import com.ib.client.OrderCondition; 5 | import com.ib.client.PercentChangeCondition; 6 | 7 | public class PercentConditionPanel extends ContractConditionPanel { 8 | 9 | public PercentConditionPanel(PercentChangeCondition condition, ContractLookuper lookuper) { 10 | super(condition, lookuper); 11 | 12 | m_value.setText(condition().changePercent()); 13 | 14 | add("Operator", m_operator); 15 | add("Percentage Change", m_value); 16 | } 17 | 18 | 19 | public OrderCondition onOK() { 20 | super.onOK(); 21 | condition().changePercent(m_value.getDouble()); 22 | 23 | return condition(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /TWS API/samples/Java/apidemo/VolumeConditionPanel.java: -------------------------------------------------------------------------------- 1 | package apidemo; 2 | 3 | import com.ib.client.ContractCondition; 4 | import com.ib.client.ContractLookuper; 5 | import com.ib.client.OrderCondition; 6 | import com.ib.client.VolumeCondition; 7 | 8 | public class VolumeConditionPanel extends ContractConditionPanel { 9 | 10 | public VolumeConditionPanel(ContractCondition condition, ContractLookuper lookuper) { 11 | super(condition, lookuper); 12 | 13 | m_value.setText(condition().volume()); 14 | 15 | add("Operator", m_operator); 16 | add("Volume", m_value); 17 | } 18 | 19 | @Override 20 | public OrderCondition onOK() { 21 | super.onOK(); 22 | 23 | condition().volume(m_value.getInt()); 24 | 25 | return condition(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /TWS API/source/CppClient/client/CommissionReport.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | 4 | #pragma once 5 | #ifndef commissionreport_def 6 | #define commissionreport_def 7 | 8 | struct CommissionReport 9 | { 10 | CommissionReport() 11 | { 12 | commission = 0; 13 | realizedPNL = 0; 14 | yield = 0; 15 | yieldRedemptionDate = 0; 16 | } 17 | 18 | // commission report fields 19 | std::string execId; 20 | double commission; 21 | std::string currency; 22 | double realizedPNL; 23 | double yield; 24 | int yieldRedemptionDate; // YYYYMMDD format 25 | }; 26 | 27 | #endif // commissionreport_def 28 | -------------------------------------------------------------------------------- /TWS API/source/CppClient/client/EReaderWMSignal.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | 4 | #include "StdAfx.h" 5 | #if defined(IB_WIN32) 6 | #include "EReaderWMSignal.h" 7 | 8 | 9 | EReaderWMSignal::EReaderWMSignal(HWND hWnd, int wmUserOffset) { 10 | m_hWnd = hWnd; 11 | m_msg = WM_USER + wmUserOffset; 12 | } 13 | 14 | void EReaderWMSignal::issueSignal() { 15 | if (IsWindow(m_hWnd)) 16 | PostMessage(m_hWnd, m_msg, 0, 0); 17 | } 18 | 19 | void EReaderWMSignal::waitForSignal() { 20 | MSG msg; 21 | 22 | if (GetMessage(&msg, 0, m_msg, m_msg)) 23 | DispatchMessage(&msg); 24 | } 25 | #endif 26 | -------------------------------------------------------------------------------- /TWS API/samples/Cpp/TestCppClient/Makefile.win: -------------------------------------------------------------------------------- 1 | CXX=cl 2 | LINK=link 3 | CXXFLAGS=/D _CRT_SECURE_NO_DEPRECATE /EHsc /wd4355 /wd4800 4 | ROOT_DIR=../../../source/cppclient 5 | BASE_SRC_DIR=$(ROOT_DIR)/src 6 | INCLUDES=/I $(ROOT_DIR) /I $(ROOT_DIR)/Shared/ /I $(ROOT_DIR)/src/ 7 | OUTPUT=TestCppClient.exe 8 | 9 | all: 10 | $(CXX) /c $(BASE_SRC_DIR)/EClientSocketBase.cpp $(INCLUDES) $(CXXFLAGS) 11 | $(CXX) /c $(BASE_SRC_DIR)/EPosixClientSocket.cpp $(INCLUDES) $(CXXFLAGS) 12 | $(CXX) /c TestCppClient.cpp $(INCLUDES) $(CXXFLAGS) 13 | $(CXX) /c Main.cpp $(INCLUDES) $(CXXFLAGS) 14 | $(LINK) EClientSocketBase.obj EPosixClientSocket.obj TestCppClient.obj Main.obj /OUT:$(OUTPUT) 15 | 16 | clean: 17 | del EClientSocketBase.obj EPosixClientSocket.obj TestCppClient.obj Main.obj $(OUTPUT) 18 | 19 | 20 | -------------------------------------------------------------------------------- /TWS API/samples/VB/VB_API_Sample/_DTwsEvents_updatePortfolioExEvent.vb: -------------------------------------------------------------------------------- 1 | ' Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | ' and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. 3 | 4 | Namespace AxTWSLib 5 | Class _DTwsEvents_updatePortfolioExEvent 6 | 7 | Property contract As IBApi.Contract 8 | 9 | Property position As Integer 10 | 11 | Property marketPrice As Double 12 | 13 | Property marketValue As Double 14 | 15 | Property averageCost As Double 16 | 17 | Property unrealisedPNL As Double 18 | 19 | Property realisedPNL As Double 20 | 21 | Property accountName As String 22 | 23 | End Class 24 | End Namespace 25 | -------------------------------------------------------------------------------- /TWS API/samples/Cpp/TestCppClientSSL/Makefile.win: -------------------------------------------------------------------------------- 1 | CXX=cl 2 | LINK=link 3 | CXXFLAGS=/D _CRT_SECURE_NO_DEPRECATE /EHsc /wd4355 /wd4800 4 | ROOT_DIR=../../../source/cppclient 5 | BASE_SRC_DIR=$(ROOT_DIR)/src 6 | INCLUDES=/I $(ROOT_DIR) /I $(ROOT_DIR)/Shared/ /I $(ROOT_DIR)/src/ 7 | OUTPUT=TestCppClient.exe 8 | 9 | all: 10 | $(CXX) /c $(BASE_SRC_DIR)/EClientSocketBase.cpp $(INCLUDES) $(CXXFLAGS) 11 | $(CXX) /c $(BASE_SRC_DIR)/EPosixClientSocket.cpp $(INCLUDES) $(CXXFLAGS) 12 | $(CXX) /c TestCppClient.cpp $(INCLUDES) $(CXXFLAGS) 13 | $(CXX) /c Main.cpp $(INCLUDES) $(CXXFLAGS) 14 | $(LINK) EClientSocketBase.obj EPosixClientSocket.obj TestCppClient.obj Main.obj /OUT:$(OUTPUT) 15 | 16 | clean: 17 | del EClientSocketBase.obj EPosixClientSocket.obj TestCppClient.obj Main.obj $(OUTPUT) 18 | 19 | 20 | -------------------------------------------------------------------------------- /TradeBot/MenuFramework/MenuOption.cs: -------------------------------------------------------------------------------- 1 | using static TradeBot.AppProperties; 2 | 3 | namespace TradeBot.MenuFramework 4 | { 5 | public class MenuOption : MenuItem 6 | { 7 | public MenuOption(string key, string description, MenuCommand command) 8 | { 9 | Key = key; 10 | Description = description; 11 | Command = command; 12 | } 13 | 14 | public string Key { get; } 15 | public string Description { get; set; } 16 | public MenuCommand Command { get; set; } 17 | 18 | public string Render() 19 | { 20 | string paddedKey = Key.PadRight(Messages.LongestMenuOptionKey.Length); 21 | return string.Format(Messages.MenuOptionFormat, paddedKey, Description); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /TWS API/samples/VB/VB_API_Sample/_DTwsEvents_historicalDataEvent.vb: -------------------------------------------------------------------------------- 1 | ' Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | ' and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. 3 | 4 | Namespace AxTWSLib 5 | Class _DTwsEvents_historicalDataEvent 6 | 7 | Property reqId As Integer 8 | 9 | Property [date] As String 10 | 11 | Property open As Double 12 | 13 | Property high As Double 14 | 15 | Property low As Double 16 | 17 | Property close As Double 18 | 19 | Property volume As Integer 20 | 21 | Property count As Integer 22 | 23 | Property WAP As Double 24 | 25 | Property hasGaps As Boolean 26 | 27 | End Class 28 | End Namespace 29 | -------------------------------------------------------------------------------- /TWS API/source/JavaClient/com/ib/client/MarginCondition.java: -------------------------------------------------------------------------------- 1 | package com.ib.client; 2 | 3 | public class MarginCondition extends OperatorCondition { 4 | 5 | public static final OrderConditionType conditionType = OrderConditionType.Margin; 6 | 7 | protected MarginCondition() { } 8 | 9 | @Override 10 | public String toString() { 11 | return "the margin cushion percent" + super.toString(); 12 | } 13 | 14 | private int m_percent; 15 | 16 | public int percent() { 17 | return m_percent; 18 | } 19 | 20 | public void percent(int m_percent) { 21 | this.m_percent = m_percent; 22 | } 23 | 24 | @Override 25 | protected String valueToString() { 26 | return "" + m_percent; 27 | } 28 | 29 | @Override 30 | protected void valueFromString(String v) { 31 | m_percent = Integer.parseInt(v); 32 | } 33 | 34 | } -------------------------------------------------------------------------------- /TWS API/source/CSharpClient/activex/ComWrappers/ComSoftDollarTier.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Runtime.InteropServices; 5 | using System.Text; 6 | 7 | namespace TWSLib 8 | { 9 | [ComVisible(true)] 10 | public class ComSoftDollarTier 11 | { 12 | private IBApi.Order order; 13 | 14 | public ComSoftDollarTier(IBApi.Order order) 15 | { 16 | this.order = order; 17 | } 18 | 19 | public string Name { get { return order.Tier.Name; } set { order.Tier = new IBApi.SoftDollarTier(value, order.Tier.Value, order.Tier.DisplayName); } } 20 | public string Value { get { return order.Tier.Value; } set { order.Tier = new IBApi.SoftDollarTier(order.Tier.Name, value, order.Tier.DisplayName); } } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /TWS API/source/CppClient/client/TagValue.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | 4 | #pragma once 5 | #ifndef tagvalue_def 6 | #define tagvalue_def 7 | 8 | #include "shared_ptr.h" 9 | 10 | #include 11 | #include 12 | 13 | struct TagValue 14 | { 15 | TagValue() {} 16 | TagValue(const std::string& p_tag, const std::string& p_value) 17 | : tag(p_tag), value(p_value) 18 | {} 19 | 20 | std::string tag; 21 | std::string value; 22 | }; 23 | 24 | typedef ibapi::shared_ptr TagValueSPtr; 25 | typedef std::vector TagValueList; 26 | typedef ibapi::shared_ptr TagValueListSPtr; 27 | 28 | #endif 29 | 30 | -------------------------------------------------------------------------------- /TWS API/source/CppClient/client/OrderCondition.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "IExternalizable.h" 3 | #include "shared_ptr.h" 4 | 5 | class TWSAPIDLLEXP OrderCondition : public IExternalizable { 6 | public: 7 | enum OrderConditionType { 8 | Price = 1, 9 | Time = 3, 10 | Margin = 4, 11 | Execution = 5, 12 | Volume = 6, 13 | PercentChange = 7 14 | }; 15 | 16 | private: 17 | OrderConditionType m_type; 18 | bool m_isConjunctionConnection; 19 | 20 | public: 21 | virtual const char* readExternal(const char* ptr, const char* endPtr); 22 | virtual void writeExternal(std::ostream &out) const; 23 | 24 | std::string toString(); 25 | bool conjunctionConnection() const; 26 | void conjunctionConnection(bool isConjunctionConnection); 27 | OrderConditionType type(); 28 | 29 | static OrderCondition *create(OrderConditionType type); 30 | }; -------------------------------------------------------------------------------- /TWS API/samples/VB/VB_API_Sample/_DTwsEvents_orderStatusEvent.vb: -------------------------------------------------------------------------------- 1 | ' Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | ' and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. 3 | 4 | Namespace AxTWSLib 5 | Class _DTwsEvents_orderStatusEvent 6 | 7 | Property orderId As Integer 8 | 9 | Property status As String 10 | 11 | Property filled As Integer 12 | 13 | Property remaining As Integer 14 | 15 | Property avgFillPrice As Double 16 | 17 | Property permId As Integer 18 | 19 | Property parentId As Integer 20 | 21 | Property lastFillPrice As Double 22 | 23 | Property clientId As Integer 24 | 25 | Property whyHeld As String 26 | 27 | End Class 28 | End Namespace 29 | -------------------------------------------------------------------------------- /TWS API/samples/CSharp/IBSampleApp/messages/TickSizeMessage.cs: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | 8 | namespace IBSampleApp.messages 9 | { 10 | public class TickSizeMessage : MarketDataMessage 11 | { 12 | private int size; 13 | 14 | public TickSizeMessage(int requestId, int field, int size) : base(MessageType.TickSize, requestId, field) 15 | { 16 | Size = size; 17 | } 18 | 19 | public int Size 20 | { 21 | get { return size; } 22 | set { size = value; } 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /TWS API/samples/CSharp/IBSampleApp/messages/FundamentalsMessage.cs: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | 8 | namespace IBSampleApp.messages 9 | { 10 | public class FundamentalsMessage : IBMessage 11 | { 12 | private string data; 13 | 14 | public FundamentalsMessage(string data) 15 | { 16 | Type = MessageType.FundamentalData; 17 | Data = data; 18 | } 19 | 20 | public string Data 21 | { 22 | get { return data; } 23 | set { data = value; } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /TWS API/source/JavaClient/com/ib/client/EMessage.java: -------------------------------------------------------------------------------- 1 | package com.ib.client; 2 | 3 | import java.io.ByteArrayInputStream; 4 | import java.io.ByteArrayOutputStream; 5 | import java.io.DataOutputStream; 6 | import java.io.IOException; 7 | import java.io.InputStream; 8 | 9 | public class EMessage { 10 | ByteArrayOutputStream m_buf; 11 | 12 | public EMessage(byte[] buf, int len) throws IOException { 13 | m_buf = new ByteArrayOutputStream(); 14 | 15 | m_buf.write(buf, 0, len); 16 | } 17 | 18 | public EMessage(Builder buf) throws IOException { 19 | m_buf = new ByteArrayOutputStream(); 20 | 21 | buf.writeTo(new DataOutputStream(m_buf)); 22 | } 23 | 24 | public InputStream getStream() { 25 | return new ByteArrayInputStream(m_buf.toByteArray()); 26 | } 27 | 28 | public byte[] getRawData() { 29 | return m_buf.toByteArray(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /TWS API/source/JavaClient/com/ib/client/ESocket.java: -------------------------------------------------------------------------------- 1 | package com.ib.client; 2 | 3 | import java.io.DataOutputStream; 4 | import java.io.IOException; 5 | import java.net.Socket; 6 | 7 | public class ESocket implements ETransport { 8 | 9 | protected DataOutputStream m_dos; // the socket output stream 10 | 11 | @Override 12 | public void send(EMessage msg) throws IOException { 13 | byte[] buf = msg.getRawData(); 14 | 15 | m_dos.write(buf, 0, buf.length); 16 | } 17 | 18 | ESocket(Socket s) throws IOException { 19 | m_dos = new DataOutputStream(s.getOutputStream()); 20 | } 21 | 22 | // Sends String without length prefix (pre-V100 style) 23 | protected void send( String str) throws IOException { 24 | // Write string to data buffer 25 | Builder b = new Builder( 1024 ); 26 | 27 | b.send(str); 28 | b.writeTo( m_dos ); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /TWS API/samples/CSharp/IBSampleApp/messages/ScannerEndMessage.cs: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | 8 | namespace IBSampleApp.messages 9 | { 10 | public class ScannerEndMessage : IBMessage 11 | { 12 | private int requestId; 13 | 14 | public ScannerEndMessage(int requestId) 15 | { 16 | Type = MessageType.ScannerDataEnd; 17 | RequestId = requestId; 18 | } 19 | 20 | public int RequestId 21 | { 22 | get { return requestId; } 23 | set { requestId = value; } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /TWS API/samples/VB/VB_API_Sample/_DTwsEvents_tickOptionComputationEvent.vb: -------------------------------------------------------------------------------- 1 | ' Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | ' and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. 3 | 4 | Namespace AxTWSLib 5 | Public Class _DTwsEvents_tickOptionComputationEvent 6 | 7 | Property tickType As Integer 8 | 9 | Property tickerId As Integer 10 | 11 | Property impliedVolatility As Double 12 | 13 | Property delta As Double 14 | 15 | Property optPrice As Double 16 | 17 | Property pvDividend As Double 18 | 19 | Property gamma As Double 20 | 21 | Property vega As Double 22 | 23 | Property theta As Double 24 | 25 | Property undPrice As Double 26 | 27 | End Class 28 | End Namespace 29 | -------------------------------------------------------------------------------- /TWS API/samples/Java/apidemo/OperatorConditionPanel.java: -------------------------------------------------------------------------------- 1 | package apidemo; 2 | 3 | import com.ib.client.OperatorCondition; 4 | import com.ib.client.OrderCondition; 5 | 6 | import apidemo.util.TCombo; 7 | import apidemo.util.UpperField; 8 | 9 | public class OperatorConditionPanel extends OnOKPanel { 10 | OperatorCondition m_condition; 11 | final TCombo m_operator = new TCombo("<=", ">="); 12 | final UpperField m_value = new UpperField(); 13 | 14 | public OperatorConditionPanel(OperatorCondition condition) { 15 | m_condition = condition; 16 | 17 | m_operator.setSelectedIndex(m_condition.isMore() ? 1 : 0); 18 | } 19 | 20 | public OrderCondition onOK() { 21 | m_condition.isMore(m_operator.getSelectedIndex() == 1); 22 | 23 | return m_condition; 24 | } 25 | 26 | protected T condition() { 27 | return (T)m_condition; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /TWS API/samples/Java/samples/rfq/RfqOrder.java: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | 4 | package samples.rfq; 5 | 6 | import com.ib.client.Order; 7 | import com.ib.client.OrderType; 8 | 9 | public class RfqOrder extends Order { 10 | 11 | public RfqOrder(int clientId, int id, int size) { 12 | 13 | clientId(clientId); 14 | orderId(id); 15 | permId(id); 16 | totalQuantity(size); 17 | orderType(OrderType.QUOTE); 18 | 19 | /* 20 | * Note: this will be overridden by the backend 21 | * because it could not keep such order 22 | * (and it does not make too much sense) 23 | */ 24 | transmit(false); 25 | } 26 | } 27 | 28 | -------------------------------------------------------------------------------- /TWS API/source/CppClient/client/OrderState.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | 4 | #pragma once 5 | #ifndef ORDER_STATE_H__INCLUDED 6 | #define ORDER_STATE_H__INCLUDED 7 | 8 | #include "Order.h" 9 | 10 | struct OrderState { 11 | 12 | explicit OrderState() 13 | : 14 | commission(UNSET_DOUBLE), 15 | minCommission(UNSET_DOUBLE), 16 | maxCommission(UNSET_DOUBLE) 17 | {} 18 | 19 | std::string status; 20 | 21 | std::string initMargin; 22 | std::string maintMargin; 23 | std::string equityWithLoan; 24 | 25 | double commission; 26 | double minCommission; 27 | double maxCommission; 28 | std::string commissionCurrency; 29 | 30 | std::string warningText; 31 | }; 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /TWS API/samples/CSharp/IBSampleApp/messages/ConnectionStatusMessage.cs: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | 8 | namespace IBSampleApp.messages 9 | { 10 | public class ConnectionStatusMessage : IBMessage 11 | { 12 | private bool isConnected; 13 | 14 | public bool IsConnected 15 | { 16 | get { return isConnected; } 17 | } 18 | 19 | public ConnectionStatusMessage(bool isConnected) 20 | { 21 | Type = MessageType.ConnectionStatus; 22 | this.isConnected = isConnected; 23 | } 24 | 25 | 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /TWS API/source/CppClient/client/executioncondition.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "OrderCondition.h" 4 | 5 | class TWSAPIDLLEXP ExecutionCondition : public OrderCondition { 6 | friend OrderCondition; 7 | 8 | std::string m_exchange; 9 | std::string m_secType; 10 | std::string m_symbol; 11 | 12 | public: 13 | static const OrderConditionType conditionType = OrderConditionType::Execution; 14 | 15 | protected: 16 | ExecutionCondition() { } 17 | 18 | public: 19 | virtual const char* readExternal(const char* ptr, const char* endPtr); 20 | virtual std::string toString(); 21 | virtual void writeExternal(std::ostream &out) const; 22 | 23 | std::string exchange(); 24 | void exchange(const std::string &exchange); 25 | std::string secType(); 26 | void secType(const std::string &secType); 27 | std::string symbol(); 28 | void symbol(const std::string &symbol); 29 | }; -------------------------------------------------------------------------------- /TWS API/samples/CSharp/IBSampleApp/messages/PositionMultiEndMessage.cs: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | using IBApi; 8 | 9 | namespace IBSampleApp.messages 10 | { 11 | public class PositionMultiEndMessage : IBMessage 12 | { 13 | private int reqId; 14 | 15 | public PositionMultiEndMessage(int reqId) 16 | { 17 | Type = MessageType.PositionMultiEnd; 18 | ReqId = reqId; 19 | } 20 | 21 | public int ReqId 22 | { 23 | get { return reqId; } 24 | set { reqId = value; } 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /TWS API/samples/CSharp/IBSampleApp/messages/ScannerParametersMessage.cs: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | 8 | namespace IBSampleApp.messages 9 | { 10 | public class ScannerParametersMessage : IBMessage 11 | { 12 | private string xmlData; 13 | 14 | public ScannerParametersMessage(string data) 15 | { 16 | Type = MessageType.ScannerParameters; 17 | XmlData = data; 18 | } 19 | 20 | public string XmlData 21 | { 22 | get { return xmlData; } 23 | set { xmlData = value; } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /TWS API/samples/CSharp/IBSampleApp/messages/AccountSummaryEndMessage.cs: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | 8 | namespace IBSampleApp.messages 9 | { 10 | public class AccountSummaryEndMessage : IBMessage 11 | { 12 | private int requestId; 13 | 14 | public AccountSummaryEndMessage(int requestId) 15 | { 16 | Type = MessageType.AccountSummaryEnd; 17 | RequestId = requestId; 18 | } 19 | 20 | public int RequestId 21 | { 22 | get { return requestId; } 23 | set { requestId = value; } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /TWS API/source/CSharpClient/client/PercentChangeCondition.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Globalization; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | namespace IBApi 8 | { 9 | /** 10 | * @brief Used with conditional orders to place or submit an order based on a percentage change of an instrument to the last close price. 11 | */ 12 | public class PercentChangeCondition : ContractCondition 13 | { 14 | 15 | protected override string Value 16 | { 17 | get 18 | { 19 | return ChangePercent.ToString(); 20 | } 21 | set 22 | { 23 | ChangePercent = double.Parse(value, NumberFormatInfo.InvariantInfo); 24 | } 25 | } 26 | 27 | public double ChangePercent { get; set; } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /TWS API/samples/CSharp/IBSampleApp/messages/AccountDownloadEndMessage.cs: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | 8 | namespace IBSampleApp.messages 9 | { 10 | public class AccountDownloadEndMessage : IBMessage 11 | { 12 | private string account; 13 | 14 | public AccountDownloadEndMessage(string account) 15 | { 16 | Type = MessageType.AccountDownloadEnd; 17 | Account = account; 18 | } 19 | 20 | public string Account 21 | { 22 | get { return account; } 23 | set { account = value; } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /TWS API/source/CSharpClient/client/MessageValidator.cs: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Text; 8 | 9 | //Hint. we could separate the message validation from the Socket client class... 10 | namespace IBApi 11 | { 12 | public class MessageValidator 13 | { 14 | private int serverVersion; 15 | 16 | public int ServerVersion 17 | { 18 | get { return serverVersion; } 19 | set { serverVersion = value; } 20 | } 21 | 22 | public MessageValidator(int serverVersion) 23 | { 24 | ServerVersion = serverVersion; 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /TWS API/samples/VB/VB_API_Sample/_DTwsEvents_tickEFPEvent.vb: -------------------------------------------------------------------------------- 1 | ' Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | ' and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. 3 | 4 | Namespace AxTWSLib 5 | Friend Class _DTwsEvents_tickEFPEvent 6 | 7 | Property tickerId As Integer 8 | 9 | Property field As Utils.TickType 10 | 11 | Property basisPoints As Double 12 | 13 | Property totalDividends As Object 14 | 15 | Property holdDays As Integer 16 | 17 | Property futureLastTradeDate As String 18 | 19 | Property dividendImpact As Double 20 | 21 | Property dividendsToLastTradeDate As Double 22 | 23 | Property formattedBasisPoints As String 24 | 25 | Property impliedFuture As Double 26 | 27 | End Class 28 | End Namespace 29 | -------------------------------------------------------------------------------- /TWS API/source/JavaClient/com/ib/contracts/ComboContract.java: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | 4 | package com.ib.contracts; 5 | 6 | import com.ib.client.Contract; 7 | import com.ib.client.Types.SecType; 8 | 9 | public class ComboContract extends Contract { 10 | public ComboContract(String symbol) { 11 | this(symbol, "USD", "SMART"); 12 | } 13 | 14 | public ComboContract(String symbol, String currency) { 15 | this(symbol, currency, "SMART"); 16 | } 17 | 18 | public ComboContract(String symbol, String currency, String exchange) { 19 | symbol(symbol); 20 | secType(SecType.BAG.name()); 21 | currency(currency); 22 | exchange(exchange); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /TWS API/samples/CSharp/IBSampleApp/messages/UpdateAccountTimeMessage.cs: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | 8 | namespace IBSampleApp.messages 9 | { 10 | public class UpdateAccountTimeMessage : IBMessage 11 | { 12 | private string timestamp; 13 | 14 | public UpdateAccountTimeMessage(string timestamp) 15 | { 16 | Type = MessageType.AccountUpdateTime; 17 | Timestamp = timestamp; 18 | } 19 | 20 | public string Timestamp 21 | { 22 | get { return timestamp; } 23 | set { timestamp = value; } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /TWS API/source/CppClient/client/CommonDefs.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | 4 | #pragma once 5 | #ifndef common_defs_h_INCLUDED 6 | #define common_defs_h_INCLUDED 7 | 8 | typedef long TickerId; 9 | typedef long OrderId; 10 | 11 | enum faDataType { GROUPS=1, PROFILES, ALIASES } ; 12 | 13 | inline const char* faDataTypeStr ( faDataType pFaDataType ) 14 | { 15 | switch (pFaDataType) { 16 | case GROUPS: 17 | return "GROUPS"; 18 | case PROFILES: 19 | return "PROFILES"; 20 | case ALIASES: 21 | return "ALIASES"; 22 | } 23 | return 0 ; 24 | } 25 | 26 | enum MarketDataType { 27 | REALTIME = 1, 28 | FROZEN = 2, 29 | DELAYED = 3, 30 | DELAYED_FROZEN = 4 31 | }; 32 | 33 | #endif /* common_defs_h_INCLUDED */ 34 | -------------------------------------------------------------------------------- /TWS API/source/JavaClient/com/ib/client/VolumeCondition.java: -------------------------------------------------------------------------------- 1 | package com.ib.client; 2 | 3 | public class VolumeCondition extends ContractCondition { 4 | 5 | public static final OrderConditionType conditionType = OrderConditionType.Volume; 6 | 7 | protected VolumeCondition() { } 8 | 9 | @Override 10 | public String toString() { 11 | return toString(null); 12 | } 13 | 14 | @Override 15 | public String toString(ContractLookuper lookuper) { 16 | return super.toString(lookuper); 17 | } 18 | 19 | private int m_volume; 20 | 21 | public int volume() { 22 | return m_volume; 23 | } 24 | 25 | public void volume(int m_volume) { 26 | this.m_volume = m_volume; 27 | } 28 | 29 | @Override 30 | protected String valueToString() { 31 | return "" + m_volume; 32 | } 33 | 34 | @Override 35 | protected void valueFromString(String v) { 36 | m_volume = Integer.parseInt(v); 37 | } 38 | 39 | } -------------------------------------------------------------------------------- /TWS API/samples/CSharp/IBSampleApp/messages/AccountUpdateMultiEndMessage.cs: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | using IBApi; 8 | 9 | namespace IBSampleApp.messages 10 | { 11 | public class AccountUpdateMultiEndMessage : IBMessage 12 | { 13 | private int reqId; 14 | 15 | public AccountUpdateMultiEndMessage(int reqId) 16 | { 17 | Type = MessageType.AccountUpdateMultiEnd; 18 | ReqId = ReqId; 19 | } 20 | 21 | public int ReqId 22 | { 23 | get { return reqId; } 24 | set { reqId = value; } 25 | } 26 | 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /TradeBot/Extensions/TaskExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading.Tasks; 3 | 4 | namespace TradeBot.Extensions 5 | { 6 | public static class TaskExtensions 7 | { 8 | public static async Task TimeoutAfter(this Task workerTask, int timeoutInMilliseconds) 9 | { 10 | Task timerTask = Task.Delay(timeoutInMilliseconds); 11 | Task firstCompletedTask = await Task.WhenAny(workerTask, timerTask); 12 | 13 | if (workerTask == firstCompletedTask) 14 | { 15 | // Re-await the task so that any exceptions/cancellations are rethrown. 16 | // No need to ConfigureAwait here since the task has already completed. 17 | await workerTask; 18 | } 19 | else 20 | { 21 | throw new TimeoutException(); 22 | } 23 | } 24 | 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /TWS API/source/CSharpClient/client/Constants.cs: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Text; 8 | 9 | namespace IBApi 10 | { 11 | public static class Constants 12 | { 13 | public const int ClientVersion = 66;//API v. 9.71 14 | public const byte EOL = 0; 15 | public const string BagSecType = "BAG"; 16 | 17 | public const int FaGroups = 1; 18 | public const int FaProfiles = 2; 19 | public const int FaAliases = 3; 20 | public const int MinVersion = 100; 21 | public const int MaxVersion = MinServerVer.SOFT_DOLLAR_TIER; 22 | public const int MaxMsgSize = 0x00FFFFFF; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /TWS API/source/CSharpClient/client/EReaderSignal.cs: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2015 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | 8 | namespace IBApi 9 | { 10 | /** 11 | * @brief Notifies the thread reading information from the TWS whenever there are messages ready to be consumed. 12 | */ 13 | public interface EReaderSignal 14 | { 15 | /** 16 | * @brief Issues a signal to the consuming thread when there are things to be consumed. 17 | */ 18 | void issueSignal(); 19 | 20 | /** 21 | * @brief Makes the consuming thread waiting until a signal is issued. 22 | */ 23 | void waitForSignal(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /TWS API/source/CSharpClient/client/ESocket.cs: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2015 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | using System; 4 | using System.Collections.Generic; 5 | using System.IO; 6 | using System.Linq; 7 | using System.Net.Sockets; 8 | using System.Text; 9 | 10 | namespace IBApi 11 | { 12 | class ESocket : ETransport, IDisposable 13 | { 14 | BinaryWriter tcpWriter; 15 | 16 | public ESocket(Stream socketStream) 17 | { 18 | tcpWriter = new BinaryWriter(socketStream); 19 | } 20 | 21 | public void Send(EMessage msg) 22 | { 23 | tcpWriter.Write(msg.GetBuf()); 24 | } 25 | 26 | public void Dispose() 27 | { 28 | tcpWriter.Dispose(); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /TradeBot/Gui/OS.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace TradeBot 3 | { 4 | public static class OS 5 | { 6 | public static bool IsWindows() 7 | { 8 | switch (Environment.OSVersion.Platform) 9 | { 10 | case PlatformID.Win32NT: 11 | case PlatformID.Win32S: 12 | case PlatformID.Win32Windows: 13 | case PlatformID.WinCE: 14 | return true; 15 | default: 16 | return false; 17 | } 18 | } 19 | 20 | public static bool IsUnix() 21 | { 22 | switch (Environment.OSVersion.Platform) 23 | { 24 | case PlatformID.Unix: 25 | case PlatformID.MacOSX: 26 | return true; 27 | default: 28 | return false; 29 | } 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /TradeBot/Program.cs: -------------------------------------------------------------------------------- 1 | using NLog; 2 | using System; 3 | using System.Threading.Tasks; 4 | using TradeBot.Gui; 5 | using static TradeBot.AppProperties; 6 | 7 | namespace TradeBot 8 | { 9 | public class Program 10 | { 11 | public static void Main() 12 | { 13 | MainAsync().Wait(); 14 | } 15 | 16 | public static async Task MainAsync() 17 | { 18 | var controller = new TradeController(); 19 | try 20 | { 21 | await controller.Run(); 22 | } 23 | catch (Exception e) 24 | { 25 | IO.ShowMessage(LogLevel.Fatal, e.ToString()); 26 | } 27 | finally 28 | { 29 | if (OS.IsWindows()) 30 | { 31 | IO.PromptForChar(Messages.PressAnyKeyToExit); 32 | } 33 | } 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /TradeBot/Generated/AppPreferences.cs: -------------------------------------------------------------------------------- 1 | // Generated by Xamasoft JSON Class Generator 2 | // http://www.xamasoft.com/json-class-generator 3 | 4 | using System; 5 | using System.Collections.Generic; 6 | using Newtonsoft.Json; 7 | using Newtonsoft.Json.Linq; 8 | 9 | namespace TradeBot.Generated 10 | { 11 | 12 | public class AppPreferences 13 | { 14 | 15 | [JsonProperty("clientId")] 16 | public int ClientId { get; set; } 17 | 18 | [JsonProperty("clientUrl")] 19 | public string ClientUrl { get; set; } 20 | 21 | [JsonProperty("clientPort")] 22 | public int ClientPort { get; set; } 23 | 24 | [JsonProperty("windowWidth")] 25 | public int WindowWidth { get; set; } 26 | 27 | [JsonProperty("windowHeight")] 28 | public int WindowHeight { get; set; } 29 | 30 | [JsonProperty("centerWindow")] 31 | public bool CenterWindow { get; set; } 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /TWS API/source/CSharpClient/activex/ControlImpl/ICommissionReport.cs: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Runtime.InteropServices; 7 | using System.Text; 8 | 9 | namespace TWSLib 10 | { 11 | [ComVisible(true), Guid("51AE469F-D859-4537-A0BA-A93992F395BB")] 12 | public interface ICommissionReport 13 | { 14 | [DispId(1)] 15 | string execId { get; } 16 | [DispId(2)] 17 | double commission { get; } 18 | [DispId(3)] 19 | string currency { get; } 20 | [DispId(4)] 21 | double realizedPNL { get; } 22 | [DispId(5)] 23 | double yield { get; } 24 | [DispId(6)] 25 | int yieldRedemptionDate { get; } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /TWS API/source/JavaClient/com/ib/client/OrderStatus.java: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | 4 | package com.ib.client; 5 | 6 | 7 | public enum OrderStatus { 8 | ApiPending, 9 | ApiCancelled, 10 | PreSubmitted, 11 | PendingCancel, 12 | Cancelled, 13 | Submitted, 14 | Filled, 15 | Inactive, 16 | PendingSubmit, 17 | Unknown; 18 | 19 | public static OrderStatus get(String apiString) { 20 | for( OrderStatus type : values() ) { 21 | if( type.name().equalsIgnoreCase(apiString) ) { 22 | return type; 23 | } 24 | } 25 | return Unknown; 26 | } 27 | 28 | public boolean isActive() { 29 | return this == PreSubmitted || this == PendingCancel || this == Submitted || this == PendingSubmit; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /TWS API/samples/CSharp/IBSampleApp/messages/ManagedAccountsMessage.cs: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | 8 | namespace IBSampleApp.messages 9 | { 10 | public class ManagedAccountsMessage : IBMessage 11 | { 12 | List managedAccounts; 13 | 14 | public ManagedAccountsMessage(string managedAccounts) 15 | { 16 | this.managedAccounts = new List(managedAccounts.Split(',')); 17 | Type = MessageType.ManagedAccounts; 18 | } 19 | 20 | public List ManagedAccounts 21 | { 22 | get { return managedAccounts; } 23 | set { managedAccounts = value; } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /TWS API/samples/CSharp/IBSampleApp/messages/CommissionMessage.cs: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | using IBApi; 8 | 9 | namespace IBSampleApp.messages 10 | { 11 | public class CommissionMessage : IBMessage 12 | { 13 | private CommissionReport commissionReport; 14 | 15 | public CommissionMessage(CommissionReport commissionReport) 16 | { 17 | Type = MessageType.CommissionsReport; 18 | CommissionReport = commissionReport; 19 | } 20 | 21 | public CommissionReport CommissionReport 22 | { 23 | get { return commissionReport; } 24 | set { commissionReport = value; } 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /TWS API/source/CppClient/client/OperatorCondition.cpp: -------------------------------------------------------------------------------- 1 | #include "StdAfx.h" 2 | #include "OperatorCondition.h" 3 | #include "EDecoder.h" 4 | #include "EClient.h" 5 | 6 | const char* OperatorCondition::readExternal(const char* ptr, const char* endPtr) { 7 | if (!(ptr = OrderCondition::readExternal(ptr, endPtr))) 8 | return 0; 9 | 10 | DECODE_FIELD(m_isMore); 11 | 12 | std::string str; 13 | 14 | DECODE_FIELD(str); 15 | 16 | valueFromString(str); 17 | 18 | return ptr; 19 | } 20 | 21 | std::string OperatorCondition::toString() { 22 | return " is " + std::string(isMore() ? ">= " : "<= ") + valueToString(); 23 | } 24 | 25 | void OperatorCondition::writeExternal(std::ostream & msg) const { 26 | OrderCondition::writeExternal(msg); 27 | 28 | ENCODE_FIELD(m_isMore); 29 | ENCODE_FIELD(valueToString()); 30 | } 31 | 32 | bool OperatorCondition::isMore() { 33 | return m_isMore; 34 | } 35 | 36 | void OperatorCondition::isMore(bool isMore) { 37 | m_isMore = isMore; 38 | } 39 | -------------------------------------------------------------------------------- /TWS API/source/CSharpClient/activex/ControlImpl/IOrderState.cs: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Runtime.InteropServices; 7 | using System.Text; 8 | 9 | namespace TWSLib 10 | { 11 | [ComVisible(true), Guid("7B33AE1F-99B0-4BCB-A024-42335897A6AF")] 12 | public interface IOrderState 13 | { 14 | [DispId(1)] string status{ get; } 15 | [DispId(2)] string initMargin{ get; } 16 | [DispId(3)] string maintMargin{ get; } 17 | [DispId(4)] string equityWithLoan{ get; } 18 | [DispId(5)] double commission{ get; } 19 | [DispId(6)] double minCommission{ get; } 20 | [DispId(7)] double maxCommission{ get; } 21 | [DispId(8)] string commissionCurrency{ get; } 22 | [DispId(9)] string warningText{ get; } 23 | }; 24 | } 25 | -------------------------------------------------------------------------------- /TradeBot/Extensions/CollectionExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | 4 | namespace TradeBot.Extensions 5 | { 6 | public static class CollectionExtensions 7 | { 8 | public static bool IsNullOrEmpty(this IEnumerable enumerable) 9 | { 10 | return enumerable?.IsEmpty() ?? true; 11 | } 12 | 13 | public static bool IsEmpty(this IEnumerable enumerable) 14 | { 15 | return enumerable.Size() == 0; 16 | } 17 | 18 | public static int LastIndex(this IEnumerable enumerable) 19 | { 20 | return enumerable.Size() - 1; 21 | } 22 | 23 | private static int Size(this IEnumerable enumerable) 24 | { 25 | // The Count property is O(1) while IEnumerable.Count() is O(N) 26 | var collection = enumerable as ICollection; 27 | return collection?.Count ?? enumerable.Count(); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /TWS API/source/JavaClient/com/ib/contracts/FutContract.java: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | 4 | package com.ib.contracts; 5 | 6 | import com.ib.client.Contract; 7 | import com.ib.client.Types.SecType; 8 | 9 | public class FutContract extends Contract { 10 | public FutContract(String symbol, String lastTradeDateOrContractMonth) { 11 | symbol(symbol); 12 | secType(SecType.FUT); 13 | exchange("ONE"); 14 | currency("USD"); 15 | lastTradeDateOrContractMonth(lastTradeDateOrContractMonth); 16 | } 17 | 18 | public FutContract(String symbol, String lastTradeDateOrContractMonth, String currency) { 19 | symbol(symbol); 20 | secType(SecType.FUT.name()); 21 | currency(currency); 22 | lastTradeDateOrContractMonth(lastTradeDateOrContractMonth); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /TWS API/source/CppClient/client/EReaderOSSignal.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | 4 | #pragma once 5 | #include "EReaderSignal.h" 6 | #include "StdAfx.h" 7 | #include 8 | 9 | #if !defined(INFINITE) 10 | #define INFINITE ((unsigned long)-1) 11 | #endif 12 | 13 | class TWSAPIDLLEXP EReaderOSSignal : 14 | public EReaderSignal 15 | { 16 | #if defined(IB_POSIX) 17 | pthread_cond_t m_evMsgs; 18 | pthread_mutex_t m_mutex; 19 | #elif defined(IB_WIN32) 20 | HANDLE m_evMsgs; 21 | #else 22 | # error "Not implemented on this platform" 23 | #endif 24 | unsigned long m_waitTimeout; // in milliseconds 25 | 26 | public: 27 | EReaderOSSignal(unsigned long waitTimeout = INFINITE) throw (std::runtime_error); 28 | ~EReaderOSSignal(void); 29 | 30 | virtual void issueSignal(); 31 | virtual void waitForSignal(); 32 | }; 33 | 34 | -------------------------------------------------------------------------------- /TWS API/samples/CSharp/IBSampleApp/Program.cs: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Windows.Forms; 8 | using System.Globalization; 9 | 10 | namespace IBSampleApp 11 | { 12 | static class Program 13 | { 14 | /// 15 | /// The main entry point for the application. 16 | /// 17 | [STAThread] 18 | static void Main() 19 | { 20 | //Watch out for any language formatting issues! 21 | Application.CurrentCulture = CultureInfo.CreateSpecificCulture("en-US"); 22 | Application.EnableVisualStyles(); 23 | Application.SetCompatibleTextRenderingDefault(false); 24 | Application.Run(new IBSampleAppDialog()); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /TWS API/source/CSharpClient/client/CSharpAPI.sln: -------------------------------------------------------------------------------- 1 | Microsoft Visual Studio Solution File, Format Version 12.00 2 | # Visual Studio Express 2012 for Windows Desktop 3 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CSharpAPI", "CSharpAPI.csproj", "{8EDE0744-96C2-40B0-A8DC-37DF79370203}" 4 | EndProject 5 | Global 6 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 7 | Debug|Any CPU = Debug|Any CPU 8 | Release|Any CPU = Release|Any CPU 9 | EndGlobalSection 10 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 11 | {8EDE0744-96C2-40B0-A8DC-37DF79370203}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 12 | {8EDE0744-96C2-40B0-A8DC-37DF79370203}.Debug|Any CPU.Build.0 = Debug|Any CPU 13 | {8EDE0744-96C2-40B0-A8DC-37DF79370203}.Release|Any CPU.ActiveCfg = Release|Any CPU 14 | {8EDE0744-96C2-40B0-A8DC-37DF79370203}.Release|Any CPU.Build.0 = Release|Any CPU 15 | EndGlobalSection 16 | GlobalSection(SolutionProperties) = preSolution 17 | HideSolutionNode = FALSE 18 | EndGlobalSection 19 | EndGlobal 20 | -------------------------------------------------------------------------------- /TWS API/source/JavaClient/com/ib/client/PercentChangeCondition.java: -------------------------------------------------------------------------------- 1 | package com.ib.client; 2 | 3 | public class PercentChangeCondition extends ContractCondition { 4 | 5 | public static final OrderConditionType conditionType = OrderConditionType.PercentChange; 6 | 7 | protected PercentChangeCondition() { } 8 | 9 | @Override 10 | public String toString(ContractLookuper lookuper) { 11 | return super.toString(lookuper); 12 | } 13 | 14 | @Override 15 | public String toString() { 16 | return toString(null); 17 | } 18 | 19 | private double m_changePercent = Double.MAX_VALUE; 20 | 21 | public double changePercent() { 22 | return m_changePercent; 23 | } 24 | 25 | public void changePercent(double m_changePercent) { 26 | this.m_changePercent = m_changePercent; 27 | } 28 | 29 | @Override 30 | protected String valueToString() { 31 | return "" + m_changePercent; 32 | } 33 | 34 | @Override 35 | protected void valueFromString(String v) { 36 | m_changePercent = Double.parseDouble(v); 37 | } 38 | 39 | } -------------------------------------------------------------------------------- /TWS API/source/JavaClient/com/ib/client/TagValue.java: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | 4 | package com.ib.client; 5 | 6 | public final class TagValue { 7 | public String m_tag; 8 | public String m_value; 9 | 10 | public TagValue() { 11 | } 12 | 13 | public TagValue(String p_tag, String p_value) { 14 | m_tag = p_tag; 15 | m_value = p_value; 16 | } 17 | 18 | @Override 19 | public boolean equals(Object p_other) { 20 | 21 | if( this == p_other) 22 | return true; 23 | 24 | if( p_other == null) 25 | return false; 26 | 27 | TagValue l_theOther = (TagValue)p_other; 28 | 29 | if( Util.StringCompare(m_tag, l_theOther.m_tag) != 0 || 30 | Util.StringCompare(m_value, l_theOther.m_value) != 0) { 31 | return false; 32 | } 33 | 34 | return true; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /TWS API/source/CSharpClient/activex/ControlImpl/IExecutionFilter.cs: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Runtime.InteropServices; 7 | using System.Text; 8 | 9 | namespace TWSLib 10 | { 11 | [ComVisible(true), Guid("3553EA07-F281-433D-B2A4-4CB722A9859B")] 12 | public interface IExecutionFilter 13 | { 14 | [DispId(1)] 15 | int clientId { get; set; } 16 | [DispId(2)] 17 | string acctCode { get; set; } 18 | [DispId(3)] 19 | string time { get; set; } 20 | [DispId(4)] 21 | string symbol { get; set; } 22 | [DispId(5)] 23 | string secType { get; set; } 24 | [DispId(6)] 25 | string exchange { get; set; } 26 | [DispId(7)] 27 | string side { get; set; } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /TWS API/source/CppClient/client/PriceCondition.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "ContractCondition.h" 3 | 4 | class TWSAPIDLLEXP PriceCondition : public ContractCondition { 5 | friend OrderCondition; 6 | 7 | double m_price; 8 | int m_triggerMethod; 9 | 10 | virtual std::string valueToString() const; 11 | virtual void valueFromString(const std::string &v); 12 | 13 | protected: 14 | PriceCondition() { }; 15 | 16 | public: 17 | static const OrderConditionType conditionType = OrderConditionType::Price; 18 | enum Method { 19 | Default = 0, 20 | DoubleBidAsk = 1, 21 | Last = 2, 22 | DoubleLast = 3, 23 | BidAsk = 4, 24 | LastBidAsk = 7, 25 | MidPoint = 8 26 | }; 27 | 28 | double price(); 29 | void price(double price); 30 | 31 | virtual std::string toString(); 32 | virtual const char* readExternal(const char* ptr, const char* endPtr); 33 | virtual void writeExternal(std::ostream & out) const; 34 | 35 | Method triggerMethod(); 36 | std::string strTriggerMethod(); 37 | void triggerMethod(Method triggerMethod); 38 | }; -------------------------------------------------------------------------------- /TWS API/source/JavaClient/com/ib/contracts/OptContract.java: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | 4 | package com.ib.contracts; 5 | 6 | import com.ib.client.Contract; 7 | import com.ib.client.Types.SecType; 8 | 9 | public class OptContract extends Contract { 10 | public OptContract(String symbol, String lastTradeDateOrContractMonth, double strike, String right) { 11 | this(symbol, "SMART", lastTradeDateOrContractMonth, strike, right); 12 | } 13 | 14 | public OptContract(String symbol, String exchange, String lastTradeDateOrContractMonth, double strike, String right) { 15 | symbol(symbol); 16 | secType(SecType.OPT.name()); 17 | exchange(exchange); 18 | currency("USD"); 19 | lastTradeDateOrContractMonth(lastTradeDateOrContractMonth); 20 | strike(strike); 21 | right(right); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /TradeBot/MenuFramework/MenuTitle.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace TradeBot.MenuFramework 4 | { 5 | public class MenuTitle : MenuItem 6 | { 7 | public MenuTitle(string title, MenuDivider divider = null) 8 | { 9 | Title = title; 10 | Divider = divider; 11 | } 12 | 13 | public string Title { get; set; } 14 | public MenuDivider Divider { get; set; } 15 | 16 | public string Render() 17 | { 18 | if (string.IsNullOrEmpty(Title)) 19 | { 20 | return string.Empty; 21 | } 22 | 23 | string div = Divider?.Render(); 24 | if (string.IsNullOrEmpty(div)) 25 | { 26 | return Title; 27 | } 28 | 29 | int titlePadding = div.Length / 2 + Title.Length / 2; 30 | return string.Join(Environment.NewLine, 31 | div, 32 | Title.PadLeft(titlePadding), 33 | div); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /TWS API/source/CppClient/client/StdAfx.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | 4 | #ifdef _MSC_VER 5 | 6 | #ifdef TWSAPIDLL 7 | #ifndef TWSAPIDLLEXP 8 | #define TWSAPIDLLEXP __declspec(dllexport) 9 | #endif 10 | #endif 11 | 12 | #define assert ASSERT 13 | #define snprintf _snprintf 14 | #include 15 | #include 16 | #define IB_WIN32 17 | 18 | #else 19 | 20 | #include // defines _POSIX_THREADS, @see http://bit.ly/1pWJ8KQ#tag_13_80_03_02 21 | 22 | #if defined(_POSIX_THREADS) && (_POSIX_THREADS > 0) 23 | #include 24 | #define IB_POSIX 25 | #else 26 | #error "Not supported on this platform" 27 | #endif 28 | 29 | #endif // #ifdef _MSC_VER 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | #ifndef TWSAPIDLLEXP 37 | #define TWSAPIDLLEXP 38 | #endif 39 | 40 | -------------------------------------------------------------------------------- /TWS API/source/CSharpClient/client/EReaderMonitorSignal.cs: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2015 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading; 8 | 9 | namespace IBApi 10 | { 11 | public class EReaderMonitorSignal : EReaderSignal 12 | { 13 | object cs = new object(); 14 | bool open = false; 15 | 16 | public void issueSignal() 17 | { 18 | lock (cs) 19 | { 20 | open = true; 21 | 22 | Monitor.PulseAll(cs); 23 | } 24 | } 25 | 26 | public void waitForSignal() 27 | { 28 | lock (cs) 29 | { 30 | while (!open) 31 | Monitor.Wait(cs); 32 | 33 | open = false; 34 | } 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /TWS API/samples/CSharp/IBSampleApp/messages/MarketDataMessage.cs: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | 8 | namespace IBSampleApp.messages 9 | { 10 | public abstract class MarketDataMessage : IBMessage 11 | { 12 | protected int requestId; 13 | protected int field; 14 | 15 | public MarketDataMessage(MessageType type, int requestId, int field) 16 | { 17 | Type = type; 18 | RequestId = requestId; 19 | Field = field; 20 | } 21 | 22 | public int RequestId 23 | { 24 | get { return requestId; } 25 | set { requestId = value; } 26 | } 27 | 28 | public int Field 29 | { 30 | get { return field; } 31 | set { field = value; } 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /TWS API/samples/Java/apidemo/TradeConditionPanel.java: -------------------------------------------------------------------------------- 1 | package apidemo; 2 | 3 | import com.ib.client.ExecutionCondition; 4 | import com.ib.client.OrderCondition; 5 | 6 | import apidemo.util.UpperField; 7 | 8 | public class TradeConditionPanel extends OnOKPanel { 9 | private ExecutionCondition m_condition; 10 | private final UpperField m_secType = new UpperField(); 11 | private final UpperField m_exchange = new UpperField(); 12 | private final UpperField m_symbol = new UpperField(); 13 | 14 | public TradeConditionPanel(ExecutionCondition condition) { 15 | m_condition = condition; 16 | 17 | m_secType.setText(m_condition.secType());; 18 | m_exchange.setText(m_condition.exchange()); 19 | m_symbol.setText(m_condition.symbol());; 20 | 21 | add("Underlying", m_symbol); 22 | add("Exchange", m_exchange); 23 | add("Type", m_secType); 24 | } 25 | 26 | public OrderCondition onOK() { 27 | m_condition.symbol(m_symbol.getText()); 28 | m_condition.exchange(m_exchange.getText()); 29 | m_condition.secType(m_secType.getText()); 30 | 31 | return m_condition; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /TWS API/samples/CSharp/IBSampleApp/messages/AdvisorDataMessage.cs: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | 8 | namespace IBSampleApp.messages 9 | { 10 | public class AdvisorDataMessage : IBMessage 11 | { 12 | private int faDataType; 13 | private string data; 14 | 15 | public AdvisorDataMessage(int faDataType, string data) 16 | { 17 | Type = MessageType.ReceiveFA; 18 | FaDataType = faDataType; 19 | Data = data; 20 | } 21 | 22 | public int FaDataType 23 | { 24 | get { return faDataType; } 25 | set { faDataType = value; } 26 | } 27 | 28 | public string Data 29 | { 30 | get { return data; } 31 | set { data = value; } 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /TWS API/samples/CSharp/IBSampleApp/ui/DataManager.cs: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Windows.Forms; 8 | using IBApi; 9 | 10 | namespace IBSampleApp.ui 11 | { 12 | public abstract class DataManager 13 | { 14 | protected Control uiControl; 15 | protected IBClient ibClient; 16 | protected int currentTicker = 1; 17 | 18 | protected delegate void UpdateUICallback(IBMessage msg); 19 | 20 | public DataManager(IBClient client, Control dataGrid) 21 | { 22 | ibClient = client; 23 | uiControl = dataGrid; 24 | } 25 | 26 | public abstract void NotifyError(int requestId); 27 | 28 | public abstract void Clear(); 29 | 30 | public abstract void UpdateUI(IBMessage message); 31 | 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /TWS API/source/CSharpClient/activex/ControlImpl/IComboLeg.cs: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Runtime.InteropServices; 8 | using System.Text; 9 | 10 | namespace TWSLib 11 | { 12 | [Guid("573E95CF-F67C-4367-A95B-CB7599BD0673"), ComVisible(true)] 13 | public interface IComboLeg 14 | { 15 | [DispId(1)] 16 | int conId { get; set; } 17 | [DispId(2)] 18 | int ratio { get; set; } 19 | [DispId(3)] 20 | string action { get; set; } 21 | [DispId(4)] 22 | string exchange { get; set; } 23 | [DispId(5)] 24 | int openClose { get; set; } 25 | [DispId(6)] 26 | int shortSaleSlot { get; set; } 27 | [DispId(7)] 28 | string designatedLocation { get; set; } 29 | [DispId(8)] 30 | int exemptCode { get; set; } 31 | }; 32 | } 33 | -------------------------------------------------------------------------------- /TWS API/source/CSharpClient/client/EClientSocketSSL.cs: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2015 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | using System; 4 | using System.Collections.Generic; 5 | using System.IO; 6 | using System.Linq; 7 | using System.Net.Security; 8 | using System.Security.Authentication; 9 | using System.Text; 10 | 11 | namespace IBApi 12 | { 13 | /** 14 | * @brief Implements a Secure Socket Layer (SSL) on top of the EClientSocket class. 15 | */ 16 | public class EClientSocketSSL : EClientSocket 17 | { 18 | public EClientSocketSSL(EWrapper wrapper, EReaderSignal signal) : 19 | base(wrapper, signal) { } 20 | 21 | protected override Stream createClientStream(string host, int port) 22 | { 23 | var rval = new SslStream(base.createClientStream(host, port), false, (o, cert, chain, errors) => true); 24 | 25 | rval.AuthenticateAsClient(host); 26 | 27 | return rval; 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /TradeBot/TwsAbstractions/Portfolio.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace TradeBot.TwsAbstractions 4 | { 5 | public class Portfolio : Dictionary 6 | { 7 | public Position Get(string tickerSymbol) 8 | { 9 | if (tickerSymbol == null) 10 | { 11 | return null; 12 | } 13 | 14 | Position position; 15 | TryGetValue(tickerSymbol, out position); 16 | return position; 17 | } 18 | 19 | public void Update(Position position) 20 | { 21 | string tickerSymbol = position.Symbol; 22 | if (position.PositionSize == 0) 23 | { 24 | Remove(tickerSymbol); 25 | } 26 | else 27 | { 28 | if (ContainsKey(tickerSymbol)) 29 | { 30 | this[tickerSymbol] = position; 31 | } 32 | else 33 | { 34 | Add(tickerSymbol, position); 35 | } 36 | } 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /TWS API/source/JavaClient/com/ib/client/OrderComboLeg.java: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | 4 | package com.ib.client; 5 | 6 | 7 | public class OrderComboLeg { 8 | private double m_price; // price per leg 9 | 10 | public double price() { return m_price; } 11 | public void price(double v) { m_price = v; } 12 | 13 | public OrderComboLeg() { 14 | m_price = Double.MAX_VALUE; 15 | } 16 | 17 | public OrderComboLeg(double p_price) { 18 | m_price = p_price; 19 | } 20 | 21 | @Override 22 | public boolean equals(Object p_other) { 23 | if ( this == p_other ) { 24 | return true; 25 | } 26 | else if ( p_other == null ) { 27 | return false; 28 | } 29 | 30 | OrderComboLeg l_theOther = (OrderComboLeg)p_other; 31 | 32 | if (m_price != l_theOther.m_price) { 33 | return false; 34 | } 35 | return true; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Mark Hennessy 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /TWS API/source/CppClient/client/ContractCondition.cpp: -------------------------------------------------------------------------------- 1 | #include "StdAfx.h" 2 | #include "ContractCondition.h" 3 | #include "EDecoder.h" 4 | #include "EClient.h" 5 | 6 | std::string ContractCondition::toString() { 7 | std::string strContract = conId() + ""; 8 | 9 | return type() + " of " + strContract + OperatorCondition::toString(); 10 | } 11 | 12 | const char* ContractCondition::readExternal(const char* ptr, const char* endPtr) { 13 | if (!(ptr = OperatorCondition::readExternal(ptr, endPtr))) 14 | return 0; 15 | 16 | DECODE_FIELD(m_conId); 17 | DECODE_FIELD(m_exchange); 18 | 19 | return ptr; 20 | } 21 | 22 | void ContractCondition::writeExternal(std::ostream & msg) const { 23 | OperatorCondition::writeExternal(msg); 24 | 25 | ENCODE_FIELD(m_conId); 26 | ENCODE_FIELD(m_exchange); 27 | } 28 | 29 | int ContractCondition::conId() { 30 | return m_conId; 31 | } 32 | 33 | void ContractCondition::conId(int conId) { 34 | m_conId = conId; 35 | } 36 | 37 | std::string ContractCondition::exchange() { 38 | return m_exchange; 39 | } 40 | 41 | void ContractCondition::exchange(const std::string & exchange) { 42 | m_exchange = exchange; 43 | } 44 | -------------------------------------------------------------------------------- /TWS API/samples/CSharp/IBSampleApp/messages/TickPriceMessage.cs: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | 8 | namespace IBSampleApp.messages 9 | { 10 | public class TickPriceMessage : MarketDataMessage 11 | { 12 | private double price; 13 | private int canAutoExecute; 14 | 15 | public TickPriceMessage(int requestId, int field, double price, int canAutoExecute) : base(MessageType.TickPrice, requestId, field) 16 | { 17 | this.price = price; 18 | this.canAutoExecute = canAutoExecute; 19 | } 20 | 21 | public int CanAutoExecute 22 | { 23 | get { return canAutoExecute; } 24 | set { canAutoExecute = value; } 25 | } 26 | public double Price 27 | { 28 | get { return price; } 29 | set { price = value; } 30 | } 31 | 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /TWS API/samples/Java/apidemo/ContractLookupButton.java: -------------------------------------------------------------------------------- 1 | package apidemo; 2 | 3 | import java.awt.event.MouseEvent; 4 | 5 | import com.ib.client.ContractLookuper; 6 | 7 | import apidemo.util.HtmlButton; 8 | 9 | public abstract class ContractLookupButton extends HtmlButton { 10 | 11 | final ContractSearchDlg m_contractSearchdlg; 12 | 13 | public ContractLookupButton(int conId, String exchange, ContractLookuper lookuper) { 14 | super(""); 15 | 16 | m_contractSearchdlg = new ContractSearchDlg(conId, exchange, lookuper); 17 | 18 | setText(m_contractSearchdlg.refContract() == null ? "search..." : m_contractSearchdlg.refContract()); 19 | } 20 | 21 | @Override 22 | protected void onClicked(MouseEvent e) { 23 | m_contractSearchdlg.setLocationRelativeTo(this.getParent()); 24 | m_contractSearchdlg.setVisible(true); 25 | 26 | setText(m_contractSearchdlg.refContract() == null ? "search..." : m_contractSearchdlg.refContract()); 27 | actionPerformed(); 28 | actionPerformed(m_contractSearchdlg.refConId(), m_contractSearchdlg.refExchId()); 29 | } 30 | 31 | protected abstract void actionPerformed(int refConId, String refExchId); 32 | } 33 | -------------------------------------------------------------------------------- /TWS API/source/JavaClient/com/ib/client/OperatorCondition.java: -------------------------------------------------------------------------------- 1 | package com.ib.client; 2 | 3 | import java.io.IOException; 4 | import java.io.ObjectInput; 5 | import java.io.ObjectOutput; 6 | 7 | 8 | public abstract class OperatorCondition extends OrderCondition { 9 | 10 | private boolean m_isMore; 11 | 12 | protected abstract String valueToString(); 13 | protected abstract void valueFromString(String v); 14 | 15 | 16 | @Override 17 | public void readExternal(ObjectInput in) throws IOException, 18 | ClassNotFoundException { 19 | super.readExternal(in); 20 | 21 | m_isMore = in.readBoolean(); 22 | 23 | valueFromString(in.readUTF()); 24 | } 25 | 26 | @Override 27 | public String toString() { 28 | return " is " + (isMore() ? ">= " : "<= ") + valueToString(); 29 | } 30 | 31 | @Override 32 | public void writeExternal(ObjectOutput out) throws IOException { 33 | super.writeExternal(out); 34 | out.writeBoolean(m_isMore); 35 | out.writeUTF(valueToString()); 36 | } 37 | 38 | public boolean isMore() { 39 | return m_isMore; 40 | } 41 | 42 | public void isMore(boolean m_isMore) { 43 | this.m_isMore = m_isMore; 44 | } 45 | } -------------------------------------------------------------------------------- /TWS API/samples/Java/apidemo/TradingPanel.java: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | 4 | package apidemo; 5 | 6 | import java.awt.Dimension; 7 | 8 | import javax.swing.BoxLayout; 9 | 10 | import apidemo.util.NewTabbedPanel.NewTabPanel; 11 | 12 | 13 | public class TradingPanel extends NewTabPanel { 14 | private final OrdersPanel m_ordersPanel = new OrdersPanel(); 15 | private final TradesPanel m_tradesPanel = new TradesPanel(); 16 | 17 | TradingPanel() { 18 | m_ordersPanel.setPreferredSize( new Dimension( 1, 10000)); 19 | m_tradesPanel.setPreferredSize( new Dimension( 1, 10000)); 20 | 21 | setLayout( new BoxLayout( this, BoxLayout.Y_AXIS)); 22 | add( m_ordersPanel); 23 | add( m_tradesPanel); 24 | } 25 | 26 | /** Called when the tab is first visited. */ 27 | @Override public void activated() { 28 | m_ordersPanel.activated(); 29 | m_tradesPanel.activated(); 30 | } 31 | 32 | /** Called when the tab is closed by clicking the X. */ 33 | @Override public void closed() { 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /TWS API/source/CppClient/ssl/StdAfx.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | 4 | #ifdef _MSC_VER 5 | 6 | #ifdef TWSAPISSLDLL 7 | # define TWSAPISSLDLLEXP __declspec(dllexport) 8 | #endif 9 | 10 | #define assert ASSERT 11 | #define snprintf _snprintf 12 | #include 13 | #include 14 | #define IB_WIN32 15 | 16 | #else 17 | 18 | #include // defines _POSIX_THREADS, @see http://bit.ly/1pWJ8KQ#tag_13_80_03_02 19 | #include 20 | #include 21 | 22 | #if defined(_POSIX_THREADS) && (_POSIX_THREADS > 0) 23 | #include 24 | #define IB_POSIX 25 | #else 26 | #error "Not supported on this platform" 27 | #endif 28 | 29 | #endif // #ifdef _MSC_VER 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | 39 | #ifndef TWSAPISSLDLLEXP 40 | #define TWSAPISSLDLLEXP 41 | #endif 42 | #ifndef TWSAPIDLLEXP 43 | #define TWSAPIDLLEXP 44 | #endif 45 | -------------------------------------------------------------------------------- /TWS API/samples/CSharp/IBSampleApp/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.34209 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace IBSampleApp.Properties { 12 | 13 | 14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] 16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { 17 | 18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 19 | 20 | public static Settings Default { 21 | get { 22 | return defaultInstance; 23 | } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /TWS API/samples/CSharp/IBSampleApp/messages/ContractDetailsMessage.cs: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | using IBApi; 8 | 9 | namespace IBSampleApp.messages 10 | { 11 | public class ContractDetailsMessage : IBMessage 12 | { 13 | private int requestId; 14 | private ContractDetails contractDetails; 15 | 16 | public ContractDetailsMessage(int requestId, ContractDetails contractDetails) 17 | { 18 | Type = MessageType.ContractData; 19 | RequestId = requestId; 20 | ContractDetails = contractDetails; 21 | } 22 | 23 | public ContractDetails ContractDetails 24 | { 25 | get { return contractDetails; } 26 | set { contractDetails = value; } 27 | } 28 | 29 | public int RequestId 30 | { 31 | get { return requestId; } 32 | set { requestId = value; } 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /TWS API/source/JavaClient/com/ib/controller/MarketValueTag.java: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | 4 | package com.ib.controller; 5 | 6 | import com.ib.client.Types; 7 | 8 | public enum MarketValueTag { 9 | NetLiquidationByCurrency, 10 | CashBalance, 11 | TotalCashBalance, 12 | AccruedCash, 13 | StockMarketValue, 14 | OptionMarketValue, 15 | FutureOptionValue, 16 | FuturesPNL, 17 | UnrealizedPnL, 18 | RealizedPnL, 19 | ExchangeRate, 20 | FundValue, 21 | NetDividend, 22 | MutualFundValue, 23 | MoneyMarketFundValue, 24 | CorporateBondValue, 25 | TBondValue, 26 | TBillValue, 27 | WarrantValue, 28 | FxCashBalance; 29 | 30 | public static MarketValueTag get( int i) { 31 | return Types.getEnum( i, values() ); 32 | } 33 | 34 | @Override public String toString() { 35 | switch( this) { 36 | case NetLiquidationByCurrency: return "Net Liq"; 37 | case StockMarketValue: return "Stocks"; 38 | case OptionMarketValue: return "Options"; 39 | case FutureOptionValue: return "Futures"; 40 | } 41 | return super.toString().replaceAll("Value", ""); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /TWS API/source/JavaClient/com/ib/client/CommissionReport.java: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | 4 | package com.ib.client; 5 | 6 | public class CommissionReport { 7 | 8 | public String m_execId; 9 | public double m_commission; 10 | public String m_currency; 11 | public double m_realizedPNL; 12 | public double m_yield; 13 | public int m_yieldRedemptionDate; // YYYYMMDD format 14 | 15 | public CommissionReport() { 16 | m_commission = 0; 17 | m_realizedPNL = 0; 18 | m_yield = 0; 19 | m_yieldRedemptionDate = 0; 20 | } 21 | 22 | @Override 23 | public boolean equals(Object p_other) { 24 | boolean l_bRetVal = false; 25 | 26 | if ( p_other == null ) { 27 | l_bRetVal = false; 28 | } 29 | else if ( this == p_other ) { 30 | l_bRetVal = true; 31 | } 32 | else { 33 | CommissionReport l_theOther = (CommissionReport)p_other; 34 | l_bRetVal = m_execId.equals( l_theOther.m_execId); 35 | } 36 | return l_bRetVal; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /TWS API/source/JavaClient/com/ib/controller/Group.java: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | 4 | package com.ib.controller; 5 | 6 | import java.util.ArrayList; 7 | import java.util.StringTokenizer; 8 | 9 | import com.ib.client.Types.Method; 10 | 11 | public class Group { 12 | private String m_name; 13 | private Method m_defaultMethod; 14 | private ArrayList m_accounts = new ArrayList(); 15 | 16 | public String name() { return m_name; } 17 | public Method defaultMethod() { return m_defaultMethod; } 18 | public ArrayList accounts() { return m_accounts; } 19 | 20 | public void name( String v) { m_name = v; } 21 | public void defaultMethod( Method v) { m_defaultMethod = v; } 22 | public void addAccount( String acct) { m_accounts.add( acct); } 23 | 24 | /** @param val is a comma or space delimited string of accounts */ 25 | public void setAllAccounts(String val) { 26 | m_accounts.clear(); 27 | 28 | StringTokenizer st = new StringTokenizer( val, " ,"); 29 | while( st.hasMoreTokens() ) { 30 | m_accounts.add( st.nextToken() ); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /TWS API/source/CSharpClient/client/TimeCondition.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace IBApi 7 | { 8 | /** 9 | * @brief Time condition used in conditional orders to submit or cancel orders at specified time. 10 | */ 11 | public class TimeCondition : OperatorCondition 12 | { 13 | const string header = "time"; 14 | 15 | protected override string Value 16 | { 17 | get 18 | { 19 | return Time; 20 | } 21 | set 22 | { 23 | Time = value; 24 | } 25 | } 26 | 27 | public override string ToString() 28 | { 29 | return header + base.ToString(); 30 | } 31 | 32 | /** 33 | * @brief Time field used in conditional order logic. Valid format: YYYYMMDD HH:MM:SS 34 | */ 35 | 36 | public string Time { get; set; } 37 | 38 | protected override bool TryParse(string cond) 39 | { 40 | if (!cond.StartsWith(header)) 41 | return false; 42 | 43 | cond = cond.Replace(header, ""); 44 | return base.TryParse(cond); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /TradeBot/TwsAbstractions/TickData.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | namespace TradeBot.TwsAbstractions 6 | { 7 | public class TickData : Dictionary 8 | { 9 | public double? Get(int tickType) 10 | { 11 | double result; 12 | bool success = TryGetValue(tickType, out result); 13 | return success ? (double?)result : null; 14 | } 15 | 16 | public bool HasTicks(params int[] tickTypes) 17 | { 18 | return HasTicks(null, tickTypes); 19 | } 20 | 21 | public bool HasTicks(Func criteria, params int[] tickTypes) 22 | { 23 | return tickTypes.All(key => 24 | { 25 | double value; 26 | bool success = TryGetValue(key, out value); 27 | return success && (criteria == null || criteria.Invoke(key, value)); 28 | }); 29 | } 30 | 31 | public void Update(int tickType, double value) 32 | { 33 | if (ContainsKey(tickType)) 34 | { 35 | this[tickType] = value; 36 | } 37 | else 38 | { 39 | Add(tickType, value); 40 | } 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /TWS API/samples/Java/apidemo/OptParamsModel.java: -------------------------------------------------------------------------------- 1 | package apidemo; 2 | 3 | import java.util.Set; 4 | 5 | import javax.swing.table.AbstractTableModel; 6 | 7 | public class OptParamsModel extends AbstractTableModel { 8 | 9 | String[] m_expirations; 10 | Double[] m_strikes; 11 | 12 | public OptParamsModel(Set expirations, Set strikes) { 13 | expirations.toArray(m_expirations = new String[expirations.size()]); 14 | strikes.toArray(m_strikes = new Double[strikes.size()]); 15 | } 16 | 17 | @Override 18 | public int getRowCount() { 19 | return Math.max(m_expirations.length, m_strikes.length); 20 | } 21 | 22 | @Override 23 | public int getColumnCount() { 24 | return 2; 25 | } 26 | 27 | @Override 28 | public String getColumnName(int column) { 29 | switch (column) { 30 | case 0: 31 | return "Expirations"; 32 | 33 | case 1: 34 | return "Strikes"; 35 | } 36 | 37 | return super.getColumnName(column); 38 | } 39 | 40 | @Override 41 | public Object getValueAt(int rowIndex, int columnIndex) { 42 | switch (columnIndex) { 43 | case 0: 44 | return rowIndex < m_expirations.length ? m_expirations[rowIndex] : null; 45 | 46 | case 1: 47 | return rowIndex < m_strikes.length ? m_strikes[rowIndex] : null; 48 | 49 | default: 50 | return null; 51 | } 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /TWS API/samples/VB/VB_API_Sample/AssemblyInfo.vb: -------------------------------------------------------------------------------- 1 | ' Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | ' and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. 3 | 4 | Imports System.Reflection 5 | Imports System.Runtime.CompilerServices 6 | Imports System.Runtime.InteropServices 7 | 8 | ' General Information about an assembly is controlled through the following 9 | ' set of attributes. Change these attribute values to modify the information 10 | ' associated with an assembly 11 | 12 | 13 | ' TODO: Review the values of the assembly attributes 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | ' Version information for an assembly consists of the following four values: 25 | 26 | ' Major version 27 | ' Minor Version 28 | ' Revision 29 | ' Build Number 30 | 31 | ' You can specify all the values or you can default the Revision and Build Numbers 32 | ' by using the '*' as shown below 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /TWS API/source/CppClient/client/Execution.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | 4 | #pragma once 5 | #ifndef execution_def 6 | #define execution_def 7 | 8 | 9 | struct Execution 10 | { 11 | Execution() 12 | { 13 | shares = 0; 14 | price = 0; 15 | permId = 0; 16 | clientId = 0; 17 | orderId = 0; 18 | cumQty = 0; 19 | avgPrice = 0; 20 | evMultiplier = 0; 21 | } 22 | 23 | std::string execId; 24 | std::string time; 25 | std::string acctNumber; 26 | std::string exchange; 27 | std::string side; 28 | double shares; 29 | double price; 30 | int permId; 31 | long clientId; 32 | long orderId; 33 | int liquidation; 34 | int cumQty; 35 | double avgPrice; 36 | std::string orderRef; 37 | std::string evRule; 38 | double evMultiplier; 39 | std::string modelCode; 40 | }; 41 | 42 | struct ExecutionFilter 43 | { 44 | ExecutionFilter() 45 | : m_clientId(0) 46 | { 47 | } 48 | 49 | // Filter fields 50 | long m_clientId; 51 | std::string m_acctCode; 52 | std::string m_time; 53 | std::string m_symbol; 54 | std::string m_secType; 55 | std::string m_exchange; 56 | std::string m_side; 57 | }; 58 | 59 | #endif // execution_def 60 | -------------------------------------------------------------------------------- /TWS API/samples/VB/Testbed/My Project/AssemblyInfo.vb: -------------------------------------------------------------------------------- 1 | ' Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | ' and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. 3 | 4 | Imports System.Reflection 5 | Imports System.Runtime.CompilerServices 6 | Imports System.Runtime.InteropServices 7 | 8 | ' General Information about an assembly is controlled through the following 9 | ' set of attributes. Change these attribute values to modify the information 10 | ' associated with an assembly 11 | 12 | 13 | ' TODO: Review the values of the assembly attributes 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | ' Version information for an assembly consists of the following four values: 25 | 26 | ' Major version 27 | ' Minor Version 28 | ' Revision 29 | ' Build Number 30 | 31 | ' You can specify all the values or you can default the Revision and Build Numbers 32 | ' by using the '*' as shown below 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /TWS API/samples/Java/TestJavaClient/Main.java: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | 4 | package TestJavaClient; 5 | 6 | import java.awt.Component; 7 | 8 | import javax.swing.JOptionPane; 9 | import javax.swing.SwingUtilities; 10 | 11 | public class Main { 12 | 13 | // This method is called to start the application 14 | public static void main (String args[]) { 15 | SampleFrame sampleFrame = new SampleFrame(); 16 | sampleFrame.setVisible(true); 17 | } 18 | 19 | static public void inform( final Component parent, final String str) { 20 | if( SwingUtilities.isEventDispatchThread() ) { 21 | showMsg( parent, str, JOptionPane.INFORMATION_MESSAGE); 22 | } 23 | else { 24 | SwingUtilities.invokeLater( new Runnable() { 25 | public void run() { 26 | showMsg( parent, str, JOptionPane.INFORMATION_MESSAGE); 27 | } 28 | }); 29 | } 30 | } 31 | 32 | static private void showMsg( Component parent, String str, int type) { 33 | // this function pops up a dlg box displaying a message 34 | JOptionPane.showMessageDialog( parent, str, "IB Java Test Client", type); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /TWS API/samples/CSharp/IBSampleApp/messages/SecurityDefinitionOptionParameterMessage.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace IBSampleApp.ui 7 | { 8 | class SecurityDefinitionOptionParameterMessage : IBMessage 9 | { 10 | public int ReqId { get; private set; } 11 | public string Exchange { get; private set; } 12 | public int UnderlyingConId { get; private set; } 13 | public string TradingClass { get; private set; } 14 | public string Multiplier { get; private set; } 15 | public HashSet Expirations { get; private set; } 16 | public HashSet Strikes { get; private set; } 17 | 18 | public SecurityDefinitionOptionParameterMessage(int reqId, string exchange, int underlyingConId, string tradingClass, string multiplier, HashSet expirations, HashSet strikes) 19 | { 20 | this.Type = MessageType.SecurityDefinitionOptionParameter; 21 | this.ReqId = reqId; 22 | this.Exchange = exchange; 23 | this.UnderlyingConId = underlyingConId; 24 | this.TradingClass = tradingClass; 25 | this.Multiplier = multiplier; 26 | this.Expirations = expirations; 27 | this.Strikes = strikes; 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /TWS API/samples/CSharp/IBSampleApp/messages/ExecutionMessage.cs: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | using IBApi; 8 | 9 | namespace IBSampleApp.messages 10 | { 11 | public class ExecutionMessage : IBMessage 12 | { 13 | private int reqId; 14 | private Contract contract; 15 | private Execution execution; 16 | 17 | public ExecutionMessage(int reqId, Contract contract, Execution execution) 18 | { 19 | Type = MessageType.ExecutionData; 20 | ReqId = reqId; 21 | Contract = contract; 22 | Execution = execution; 23 | } 24 | 25 | public Contract Contract 26 | { 27 | get { return contract; } 28 | set { contract = value; } 29 | } 30 | 31 | public Execution Execution 32 | { 33 | get { return execution; } 34 | set { execution = value; } 35 | } 36 | 37 | public int ReqId 38 | { 39 | get { return reqId; } 40 | set { reqId = value; } 41 | } 42 | 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /TWS API/source/JavaClient/com/ib/client/MarketDataType.java: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | 4 | package com.ib.client; 5 | 6 | public class MarketDataType { 7 | // constants - market data types 8 | public static final int REALTIME = 1; 9 | public static final int FROZEN = 2; 10 | public static final int DELAYED = 3; 11 | public static final int DELAYED_FROZEN = 4; 12 | 13 | public static String getField( int marketDataType) { 14 | switch( marketDataType) { 15 | case REALTIME: return "Real-Time"; 16 | case FROZEN: return "Frozen"; 17 | case DELAYED: return "Delayed"; 18 | case DELAYED_FROZEN: return "Delayed-Frozen"; 19 | 20 | default: return "Unknown"; 21 | } 22 | } 23 | 24 | public static String[] getFields(){ 25 | int totalFields = MarketDataType.class.getFields().length; 26 | String [] fields = new String[totalFields]; 27 | for (int i = 0; i < totalFields; i++){ 28 | fields[i] = MarketDataType.getField(i + 1); 29 | } 30 | return fields; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /TWS API/samples/CSharp/IBSampleApp/messages/HistoricalDataEndMessage.cs: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | 8 | namespace IBSampleApp.messages 9 | { 10 | public class HistoricalDataEndMessage : IBMessage 11 | { 12 | private int requestId; 13 | private string startDate; 14 | private string endDate; 15 | 16 | public string StartDate 17 | { 18 | get { return startDate; } 19 | set { startDate = value; } 20 | } 21 | 22 | public int RequestId 23 | { 24 | get { return requestId; } 25 | set { requestId = value; } 26 | } 27 | 28 | public string EndDate 29 | { 30 | get { return endDate; } 31 | set { endDate = value; } 32 | } 33 | 34 | public HistoricalDataEndMessage(int requestId, string startDate, string endDate) 35 | { 36 | Type = MessageType.HistoricalDataEnd; 37 | RequestId = requestId; 38 | StartDate = startDate; 39 | EndDate = endDate; 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /TWS API/source/CppClient/client/TwsSocketClient.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Express 2012 for Windows Desktop 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TwsSocketClient", "TwsSocketClient.vcxproj", "{E9C3126E-CEA8-41A8-A714-7644B016DB3C}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Win32 = Debug|Win32 9 | Debug|x64 = Debug|x64 10 | Release|Win32 = Release|Win32 11 | Release|x64 = Release|x64 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {E9C3126E-CEA8-41A8-A714-7644B016DB3C}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {E9C3126E-CEA8-41A8-A714-7644B016DB3C}.Debug|Win32.Build.0 = Debug|Win32 16 | {E9C3126E-CEA8-41A8-A714-7644B016DB3C}.Debug|x64.ActiveCfg = Debug|Win32 17 | {E9C3126E-CEA8-41A8-A714-7644B016DB3C}.Debug|x64.Build.0 = Debug|Win32 18 | {E9C3126E-CEA8-41A8-A714-7644B016DB3C}.Release|Win32.ActiveCfg = Release|Win32 19 | {E9C3126E-CEA8-41A8-A714-7644B016DB3C}.Release|Win32.Build.0 = Release|Win32 20 | {E9C3126E-CEA8-41A8-A714-7644B016DB3C}.Release|x64.ActiveCfg = Release|x64 21 | {E9C3126E-CEA8-41A8-A714-7644B016DB3C}.Release|x64.Build.0 = Release|x64 22 | EndGlobalSection 23 | GlobalSection(SolutionProperties) = preSolution 24 | HideSolutionNode = FALSE 25 | EndGlobalSection 26 | EndGlobal 27 | -------------------------------------------------------------------------------- /TWS API/samples/Java/samples/dnhedge/DNHedgeOrder.java: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | 4 | package samples.dnhedge; 5 | 6 | import com.ib.client.Order; 7 | import com.ib.client.OrderType; 8 | import com.ib.client.Types.Action; 9 | import com.ib.client.Types.VolatilityType; 10 | 11 | public class DNHedgeOrder extends Order { 12 | public DNHedgeOrder(int clientId, int id, int size, String account, 13 | String settlingFirm, int underConId, String designatedLocation) { 14 | clientId(clientId); 15 | orderId(id); 16 | permId(id); 17 | 18 | account(account); 19 | clearingIntent("AWAY"); 20 | settlingFirm(settlingFirm); 21 | 22 | orderType(OrderType.VOL); 23 | action(Action.BUY); 24 | totalQuantity(size); 25 | 26 | volatility(0.1); 27 | volatilityType(VolatilityType.Daily); 28 | continuousUpdate(1); 29 | deltaNeutralOrderType(OrderType.LMT); 30 | 31 | deltaNeutralConId(underConId); 32 | deltaNeutralOpenClose("O"); 33 | deltaNeutralShortSale(true); 34 | 35 | deltaNeutralDesignatedLocation(designatedLocation); 36 | deltaNeutralShortSaleSlot(deltaNeutralDesignatedLocation().length() == 0 ? 1 : 2); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /TWS API/source/CppClient/client/executioncondition.cpp: -------------------------------------------------------------------------------- 1 | #include "StdAfx.h" 2 | #include "executioncondition.h" 3 | #include "EDecoder.h" 4 | #include "EClient.h" 5 | 6 | const char* ExecutionCondition::readExternal(const char* ptr, const char* endPtr) { 7 | if (!(ptr = OrderCondition::readExternal(ptr, endPtr))) 8 | return 0; 9 | 10 | DECODE_FIELD(m_secType) 11 | DECODE_FIELD(m_exchange); 12 | DECODE_FIELD(m_symbol); 13 | 14 | return ptr; 15 | } 16 | 17 | std::string ExecutionCondition::toString() { 18 | return "trade occurs for " + m_symbol + " symbol on " + m_exchange + " exchange for " + m_secType + " security type"; 19 | } 20 | 21 | void ExecutionCondition::writeExternal(std::ostream & msg) const { 22 | OrderCondition::writeExternal(msg); 23 | 24 | ENCODE_FIELD(m_secType); 25 | ENCODE_FIELD(m_exchange); 26 | ENCODE_FIELD(m_symbol); 27 | } 28 | 29 | std::string ExecutionCondition::exchange() { 30 | return m_exchange; 31 | } 32 | 33 | void ExecutionCondition::exchange(const std::string &exchange) { 34 | m_exchange = exchange; 35 | } 36 | 37 | std::string ExecutionCondition::secType() { 38 | return m_secType; 39 | } 40 | 41 | void ExecutionCondition::secType(const std::string &secType) { 42 | m_secType = secType; 43 | } 44 | 45 | std::string ExecutionCondition::symbol() { 46 | return m_symbol; 47 | } 48 | 49 | void ExecutionCondition::symbol(const std::string &symbol) { 50 | m_symbol = symbol; 51 | } 52 | -------------------------------------------------------------------------------- /TWS API/samples/VB/VB_API_Sample/app.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /TWS API/samples/VB/Testbed/app.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /TWS API/samples/CSharp/IBSampleApp/messages/OpenOrderMessage.cs: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | using IBApi; 8 | 9 | namespace IBSampleApp.messages 10 | { 11 | public class OpenOrderMessage : OrderMessage 12 | { 13 | private Contract contract; 14 | private Order order; 15 | private OrderState orderState; 16 | 17 | public OpenOrderMessage(int orderId, Contract contract, Order order, OrderState orderState) 18 | { 19 | Type = MessageType.OpenOrder; 20 | OrderId = orderId; 21 | Contract = contract; 22 | Order = order; 23 | OrderState = orderState; 24 | } 25 | 26 | public Contract Contract 27 | { 28 | get { return contract; } 29 | set { contract = value; } 30 | } 31 | 32 | public Order Order 33 | { 34 | get { return order; } 35 | set { order = value; } 36 | } 37 | 38 | public OrderState OrderState 39 | { 40 | get { return orderState; } 41 | set { orderState = value; } 42 | } 43 | 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /TradeBot/FileIO/CustomJsonClassGenerator.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | using Xamasoft.JsonClassGenerator; 3 | 4 | namespace TradeBot.FileIO 5 | { 6 | public class CustomJsonClassGenerator 7 | { 8 | public static void Main(string[] args) 9 | { 10 | string pathToJson = args[0]; 11 | string pathToClass = args[1]; 12 | string namespaceName = args[2]; 13 | bool useNullableValues = false; 14 | if (args.Length > 3) 15 | { 16 | useNullableValues = bool.Parse(args[3]); 17 | } 18 | 19 | string json = File.ReadAllText(pathToJson); 20 | string folderPath = Path.GetDirectoryName(pathToClass); 21 | string className = Path.GetFileNameWithoutExtension(pathToClass); 22 | 23 | JsonClassGenerator generator = new JsonClassGenerator(); 24 | generator.Example = json; 25 | generator.TargetFolder = folderPath; 26 | generator.MainClass = className; 27 | generator.Namespace = namespaceName; 28 | generator.AlwaysUseNullableValues = useNullableValues; 29 | generator.SingleFile = true; 30 | // Set UseNestedClasses to false because it doesn't work... 31 | generator.UseNestedClasses = false; 32 | generator.UseProperties = true; 33 | generator.UsePascalCase = true; 34 | generator.GenerateClasses(); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /TWS API/source/CSharpClient/client/MarginCondition.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace IBApi 7 | { 8 | /** 9 | * @class MarginCondition 10 | * @brief This class represents a condition requiring the margin cushion reaching a given percent to be fulfilled. 11 | * Orders can be activated or canceled if a set of given conditions is met. A MarginCondition is met whenever the margin penetrates the given percent. 12 | */ 13 | public class MarginCondition : OperatorCondition 14 | { 15 | const string header = "the margin cushion percent"; 16 | 17 | protected override string Value 18 | { 19 | get 20 | { 21 | return Percent.ToString(); 22 | } 23 | set 24 | { 25 | Percent = int.Parse(value); 26 | } 27 | } 28 | 29 | public override string ToString() 30 | { 31 | return header + base.ToString(); 32 | } 33 | 34 | /** 35 | * @brief Margin percent to trigger condition. 36 | */ 37 | public int Percent { get; set; } 38 | 39 | protected override bool TryParse(string cond) 40 | { 41 | if (!cond.StartsWith(header)) 42 | return false; 43 | 44 | cond = cond.Replace(header, ""); 45 | 46 | return base.TryParse(cond); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /TWS API/source/CSharpClient/client/UnderComp.cs: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Runtime.InteropServices; 8 | using System.Text; 9 | 10 | namespace IBApi 11 | { 12 | /** 13 | * @brief Delta-Neutral Underlying Component. 14 | */ 15 | public class UnderComp 16 | { 17 | private int conId; 18 | private double delta; 19 | private double price; 20 | 21 | /** 22 | * @brief The unique contract identifier specifying the security. Used for Delta-Neutral Combo contracts. 23 | */ 24 | public int ConId 25 | { 26 | get { return conId; } 27 | set { conId = value; } 28 | } 29 | 30 | /** 31 | * @brief The underlying stock or future delta. Used for Delta-Neutral Combo contracts. 32 | */ 33 | public double Delta 34 | { 35 | get { return delta; } 36 | set { delta = value; } 37 | } 38 | 39 | /** 40 | * @brief The price of the underlying. Used for Delta-Neutral Combo contracts. 41 | */ 42 | public double Price 43 | { 44 | get { return price; } 45 | set { price = value; } 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /TWS API/samples/CSharp/IBSampleApp/messages/ErrorMessage.cs: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | 8 | namespace IBSampleApp 9 | { 10 | public class ErrorMessage : IBMessage 11 | { 12 | private string message; 13 | private int errorCode; 14 | private int requestId; 15 | 16 | public ErrorMessage(int requestId, int errorCode, string message) 17 | { 18 | Type = MessageType.Error; 19 | Message = message; 20 | RequestId = requestId; 21 | ErrorCode = errorCode; 22 | } 23 | 24 | public string Message 25 | { 26 | get { return message; } 27 | set { message = value; } 28 | } 29 | 30 | public int ErrorCode 31 | { 32 | get { return errorCode; } 33 | set { errorCode = value; } 34 | } 35 | 36 | 37 | public int RequestId 38 | { 39 | get { return requestId; } 40 | set { requestId = value; } 41 | } 42 | 43 | public override string ToString() 44 | { 45 | return "Error. Request: "+RequestId+", Code: "+ErrorCode+" - "+Message; 46 | } 47 | 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /TWS API/samples/VB/VB_API_Sample/dlgAdjustStop.vb: -------------------------------------------------------------------------------- 1 | Imports IBApi 2 | 3 | Public Class dlgAdjustStop 4 | 5 | Dim order As IBApi.Order 6 | 7 | Sub New(order As Order) 8 | InitializeComponent() 9 | 10 | Me.order = order 11 | cbAdjustedOrderType.Text = order.AdjustedOrderType 12 | tbTriggerPrice.Text = Util.DoubleMaxString(order.TriggerPrice) 13 | tbAdjustedStopPrice.Text = Util.DoubleMaxString(order.AdjustedStopPrice) 14 | tbAdjustedStopLimitPrice.Text = Util.DoubleMaxString(order.AdjustedStopLimitPrice) 15 | tbAdjustedTrailingAmnt.Text = Util.DoubleMaxString(order.AdjustedTrailingAmount) 16 | cbAdjustedTrailingAmntUnit.SelectedIndex = order.AdjustableTrailingUnit 17 | End Sub 18 | 19 | Private Sub btnOK_Click(sender As Object, e As EventArgs) Handles btnOK.Click 20 | order.AdjustedOrderType = cbAdjustedOrderType.Text 21 | order.TriggerPrice = Utils.StringToDouble(tbTriggerPrice.Text) 22 | order.AdjustedStopPrice = Utils.StringToDouble(tbAdjustedStopPrice.Text) 23 | order.AdjustedStopLimitPrice = Utils.StringToDouble(tbAdjustedStopLimitPrice.Text) 24 | order.AdjustedTrailingAmount = Utils.StringToDouble(tbAdjustedTrailingAmnt.Text) 25 | order.AdjustableTrailingUnit = cbAdjustedTrailingAmntUnit.SelectedIndex 26 | 27 | Close() 28 | End Sub 29 | 30 | Private Sub btnCancel_Click(sender As Object, e As EventArgs) Handles btnCancel.Click 31 | Close() 32 | End Sub 33 | End Class -------------------------------------------------------------------------------- /TWS API/source/CppClient/client/EMutex.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms 2 | * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */ 3 | 4 | #include "StdAfx.h" 5 | #include "EMutex.h" 6 | 7 | EMutex::EMutex() 8 | { 9 | #if defined(IB_POSIX) 10 | pthread_mutex_init(&cs, NULL); 11 | #elif defined(IB_WIN32) 12 | InitializeCriticalSection(&cs); 13 | #else 14 | # error "Not implemented on this platform" 15 | #endif 16 | } 17 | 18 | EMutex::~EMutex(void) 19 | { 20 | Leave(); 21 | #if defined(IB_POSIX) 22 | pthread_mutex_destroy(&cs); 23 | #elif defined(IB_WIN32) 24 | DeleteCriticalSection(&cs); 25 | #else 26 | # error "Not implemented on this platform" 27 | #endif 28 | } 29 | 30 | bool EMutex::TryEnter() 31 | { 32 | #if defined(IB_POSIX) 33 | return pthread_mutex_trylock(&cs) == 0; 34 | #elif defined(IB_WIN32) 35 | return TryEnterCriticalSection(&cs); 36 | #else 37 | # error "Not implemented on this platform" 38 | #endif 39 | } 40 | 41 | void EMutex::Enter() { 42 | #if defined(IB_POSIX) 43 | pthread_mutex_lock(&cs); 44 | #elif defined(IB_WIN32) 45 | EnterCriticalSection(&cs); 46 | #else 47 | # error "Not implemented on this platform" 48 | #endif 49 | } 50 | 51 | void EMutex::Leave() { 52 | #if defined(IB_POSIX) 53 | pthread_mutex_unlock(&cs); 54 | #elif defined(IB_WIN32) 55 | LeaveCriticalSection(&cs); 56 | #else 57 | # error "Not implemented on this platform" 58 | #endif 59 | } 60 | -------------------------------------------------------------------------------- /TWS API/samples/Cpp/TestCppClient/AvailableAlgoParams.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #ifndef AVAILABLEALGOPARAMS 3 | #define AVAILABLEALGOPARAMS 4 | 5 | #include 6 | 7 | class Order; 8 | 9 | class AvailableAlgoParams { 10 | public: 11 | static void FillArrivalPriceParams(Order& baseOrder, double maxPctVol, std::string riskAversion, std::string startTime, std::string endTime, 12 | bool forceCompletion, bool allowPastTime); 13 | static void FillDarkIceParams(Order& baseOrder, int displaySize, std::string startTime, std::string endTime, bool allowPastEndTime); 14 | static void FillPctVolParams(Order& baseOrder, double pctVol, std::string startTime, std::string endTime, bool noTakeLiq); 15 | static void FillTwapParams(Order& baseOrder, std::string strategyType, std::string startTime, std::string endTime, bool allowPastEndTime); 16 | static void FillVwapParams(Order& baseOrder, double maxPctVol, std::string startTime, std::string endTime, bool allowPastEndTime, bool noTakeLiq); 17 | static void FillAccumulateDistributeParams(Order& baseOrder, int componentSize, int timeBetweenOrders, bool randomizeTime20, bool randomizeSize55, 18 | int giveUp, bool catchUp, bool waitOrFill, std::string startTime, std::string endTime); 19 | static void FillBalanceImpactRiskParams(Order& baseOrder, double maxPctVol, std::string riskAversion, bool forceCompletion); 20 | static void FillMinImpactParams(Order& baseOrder, double maxPctVol); 21 | static void FillAdaptiveParams(Order& baseOrder, std::string priority); 22 | }; 23 | 24 | #endif -------------------------------------------------------------------------------- /TWS API/samples/CSharp/IBSampleApp/util/Utils.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using IBApi; 6 | 7 | namespace IBSampleApp.util 8 | { 9 | public class Utils 10 | { 11 | public static string ContractToString(Contract contract) 12 | { 13 | return contract.Symbol + " " + contract.SecType + " " + contract.Currency + " @ " + contract.Exchange; 14 | } 15 | 16 | public static bool ContractsAreEqual(Contract contractA, Contract contractB) 17 | { 18 | if (contractA.Symbol.Equals(contractB.Symbol) && contractA.SecType.Equals(contractB.SecType) && contractA.Currency.Equals(contractB.Currency)) 19 | { 20 | if (contractA.LastTradeDateOrContractMonth != null && contractB.LastTradeDateOrContractMonth != null) 21 | { 22 | if (contractA.LastTradeDateOrContractMonth.Equals(contractB.LastTradeDateOrContractMonth)) 23 | { 24 | if (contractA.Multiplier != null && contractB.Multiplier != null) 25 | { 26 | return contractA.Multiplier.Equals(contractB.Multiplier); 27 | } 28 | else 29 | return true; 30 | } 31 | } 32 | else 33 | return true; 34 | } 35 | 36 | return false; 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /TWS API/samples/Cpp/TestCppClient/ContractSamples.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #ifndef CONTRACTSAMPLE 3 | #define CONTRACTSAMPLE 4 | 5 | class Contract; 6 | 7 | class ContractSamples { 8 | public: 9 | static Contract EurGbpFx(); 10 | static Contract Index(); 11 | static Contract CFD(); 12 | static Contract EuropeanStock(); 13 | static Contract OptionAtIse(); 14 | static Contract USStock(); 15 | static Contract USStockAtSmart(); 16 | static Contract USStockWithPrimaryExch(); 17 | static Contract BondWithCusip(); 18 | static Contract Bond(); 19 | static Contract MutualFund(); 20 | static Contract Commodity(); 21 | static Contract USOptionContract(); 22 | static Contract OptionAtBox(); 23 | static Contract NormalOption(); 24 | static Contract OptionWithTradingClass(); 25 | static Contract OptionWithLoacalSymbol(); 26 | static Contract SimpleFuture(); 27 | static Contract FutureWithLocalSymbol(); 28 | static Contract FutureWithMultiplier(); 29 | static Contract WrongContract(); 30 | static Contract FuturesOnOptions(); 31 | static Contract ByISIN(); 32 | static Contract ByConId(); 33 | static Contract OptionForQuery(); 34 | static Contract StockComboContract(); 35 | static Contract FutureComboContract(); 36 | static Contract OptionComboContract(); 37 | static Contract InterCmdtyFuturesContract(); 38 | static Contract NewsFeedForQuery(); 39 | static Contract BTbroadtapeNewsFeed(); 40 | static Contract BZbroadtapeNewsFeed(); 41 | static Contract FLYbroadtapeNewsFeed(); 42 | static Contract MTbroadtapeNewsFeed(); 43 | }; 44 | 45 | #endif -------------------------------------------------------------------------------- /TWS API/samples/Cpp/TestCppClient/AccountSummaryTags.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #ifndef ACCOUNTSUMMARYTAGS 3 | #define ACCOUNTSUMMARYTAGS 4 | 5 | #include 6 | 7 | class AccountSummaryTags{ 8 | public: 9 | static std::string AccountType; 10 | static std::string NetLiquidation; 11 | static std::string TotalCashValue; 12 | static std::string SettledCash; 13 | static std::string AccruedCash; 14 | static std::string BuyingPower; 15 | static std::string EquityWithLoanValue; 16 | static std::string PreviousEquityWithLoanValue; 17 | static std::string GrossPositionValue; 18 | static std::string ReqTEquity; 19 | static std::string ReqTMargin; 20 | static std::string SMA; 21 | static std::string InitMarginReq; 22 | static std::string MaintMarginReq; 23 | static std::string AvailableFunds; 24 | static std::string ExcessLiquidity; 25 | static std::string Cushion; 26 | static std::string FullInitMarginReq; 27 | static std::string FullMaintMarginReq; 28 | static std::string FullAvailableFunds; 29 | static std::string FullExcessLiquidity; 30 | static std::string LookAheadNextChange; 31 | static std::string LookAheadInitMarginReq; 32 | static std::string LookAheadMaintMarginReq; 33 | static std::string LookAheadAvailableFunds; 34 | static std::string LookAheadExcessLiquidity; 35 | static std::string HighestSeverity; 36 | static std::string DayTradesRemaining; 37 | static std::string Leverage; 38 | 39 | static std::string getAllTags(); 40 | }; 41 | 42 | #endif --------------------------------------------------------------------------------