Beispiel #1
0
        public IBSampleApp()
        {
            InitializeComponent();
            ibClient              = new IBClient(this);
            marketDataManager     = new MarketDataManager(ibClient, marketDataGrid_MDT);
            deepBookManager       = new DeepBookManager(ibClient, deepBookGrid);
            historicalDataManager = new HistoricalDataManager(ibClient, historicalChart, barsGrid);
            realTimeBarManager    = new RealTimeBarsManager(ibClient, rtBarsChart, rtBarsGrid);
            scannerManager        = new ScannerManager(ibClient, scannerGrid);
            orderManager          = new OrderManager(ibClient, liveOrdersGrid, tradeLogGrid);
            accountManager        = new AccountManager(ibClient, accountSelector, accSummaryGrid, accountValuesGrid, accountPortfolioGrid, positionsGrid);
            contractManager       = new ContractManager(ibClient, fundamentalsOutput, contractDetailsGrid);
            advisorManager        = new AdvisorManager(ibClient, advisorAliasesGrid, advisorGroupsGrid, advisorProfilesGrid);
            optionsManager        = new OptionsManager(ibClient, optionChainCallGrid, optionChainPutGrid, optionPositionsGrid);

            mdContractRight.Items.AddRange(ContractRight.GetAll());
            mdContractRight.SelectedIndex = 0;

            conDetRight.Items.AddRange(ContractRight.GetAll());
            conDetRight.SelectedIndex = 0;

            fundamentalsReportType.Items.AddRange(FundamentalsReport.GetAll());
            fundamentalsReportType.SelectedIndex = 0;

            this.groupMethod.DataSource    = AllocationGroupMethod.GetAsData();
            this.groupMethod.ValueMember   = "Value";
            this.groupMethod.DisplayMember = "Name";

            this.profileType.DataSource    = AllocationProfileType.GetAsData();
            this.profileType.ValueMember   = "Value";
            this.profileType.DisplayMember = "Name";
        }
Beispiel #2
0
 public RealtimeCommand(ILogger <RealtimeCommand> log,
                        IClientWrapper client,
                        RealTimeBarsManager realTimeBarsManager,
                        RealtimeConfig config,
                        ICsvSerializer serializer)
 {
     this.log    = log ?? throw new ArgumentNullException(nameof(log));
     this.client = client ?? throw new ArgumentNullException(nameof(client));
     this.realTimeBarsManager =
         realTimeBarsManager ?? throw new ArgumentNullException(nameof(realTimeBarsManager));
     this.config     = config ?? throw new ArgumentNullException(nameof(config));
     this.serializer = serializer ?? throw new ArgumentNullException(nameof(serializer));
 }
Beispiel #3
0
        public IBSampleAppDialog()
        {
            InitializeComponent();
            ibClient = new IBClient(signal);

            marketDataManager     = new MarketDataManager(ibClient, marketDataGrid_MDT);
            deepBookManager       = new DeepBookManager(ibClient, deepBookGrid);
            historicalDataManager = new HistoricalDataManager(ibClient, historicalChart, barsGrid);
            realTimeBarManager    = new RealTimeBarsManager(ibClient, rtBarsChart, rtBarsGrid);
            scannerManager        = new ScannerManager(ibClient, scannerGrid, scannerParamsOutput);
            orderManager          = new OrderManager(ibClient, liveOrdersGrid, tradeLogGrid);
            accountManager        = new AccountManager(ibClient, accountSelector, accSummaryGrid, accountValuesGrid, accountPortfolioGrid, positionsGrid);
            contractManager       = new ContractManager(ibClient, fundamentalsOutput, contractDetailsGrid); //ibClient, form tab, form tab. https://interactivebrokers.github.io/tws-api/contract_details.html#gsc.tab=0
            advisorManager        = new AdvisorManager(ibClient, advisorAliasesGrid, advisorGroupsGrid, advisorProfilesGrid);
            optionsManager        = new OptionsManager(ibClient, optionChainCallGrid, optionChainPutGrid, optionPositionsGrid, listViewOptionParams);
            acctPosMultiManager   = new AcctPosMultiManager(ibClient, positionsMultiGrid, accountUpdatesMultiGrid);
            mdContractRight.Items.AddRange(ContractRight.GetAll());
            mdContractRight.SelectedIndex = 0;

            conDetRight.Items.AddRange(ContractRight.GetAll());
            conDetRight.SelectedIndex = 0;

            fundamentalsReportType.Items.AddRange(FundamentalsReport.GetAll());
            fundamentalsReportType.SelectedIndex = 0;

            this.groupMethod.DataSource    = AllocationGroupMethod.GetAsData();
            this.groupMethod.ValueMember   = "Value";
            this.groupMethod.DisplayMember = "Name";

            this.profileType.DataSource    = AllocationProfileType.GetAsData();
            this.profileType.ValueMember   = "Value";
            this.profileType.DisplayMember = "Name";

            hdRequest_EndTime.Text = DateTime.Now.ToString("yyyyMMdd HH:mm:ss");

            DateTime execFilterDefault = DateTime.Now.AddHours(-1);

            execFilterTime.Text = execFilterDefault.ToString("yyyyMMdd HH:mm:ss");


            // Events liniking
            // All events belong to EWrapper interface and called Public member functions
            ibClient.Error                  += ibClient_Error;
            ibClient.ConnectionClosed       += ibClient_ConnectionClosed;
            ibClient.CurrentTime            += time => addTextToBox("Current Time: " + time + "\n");
            ibClient.TickPrice              += ibClient_TickPrice;
            ibClient.TickSize               += ibClient_TickSize;
            ibClient.TickString             += (tickerId, tickType, value) => addTextToBox("Tick string. Ticker Id:" + tickerId + ", Type: " + TickType.getField(tickType) + ", Value: " + value + "\n");
            ibClient.TickGeneric            += (tickerId, field, value) => addTextToBox("Tick Generic. Ticker Id:" + tickerId + ", Field: " + TickType.getField(field) + ", Value: " + value + "\n");
            ibClient.TickEFP                += (tickerId, tickType, basisPoints, formattedBasisPoints, impliedFuture, holdDays, futureLastTradeDate, dividendImpact, dividendsToLastTradeDate) => addTextToBox("TickEFP. " + tickerId + ", Type: " + tickType + ", BasisPoints: " + basisPoints + ", FormattedBasisPoints: " + formattedBasisPoints + ", ImpliedFuture: " + impliedFuture + ", HoldDays: " + holdDays + ", FutureLastTradeDate: " + futureLastTradeDate + ", DividendImpact: " + dividendImpact + ", DividendsToLastTradeDate: " + dividendsToLastTradeDate + "\n");
            ibClient.TickSnapshotEnd        += tickerId => addTextToBox("TickSnapshotEnd: " + tickerId + "\n");
            ibClient.NextValidId            += ibClient_NextValidId; // Receives next valid order id. Will be invoked automatically upon successfull API client connection. Used for sending connection status
            ibClient.DeltaNeutralValidation += (reqId, underComp) =>
                                               addTextToBox("DeltaNeutralValidation. " + reqId + ", ConId: " + underComp.ConId + ", Delta: " + underComp.Delta + ", Price: " + underComp.Price + "\n");

            ibClient.ManagedAccounts         += accountsList => HandleMessage(new ManagedAccountsMessage(accountsList));
            ibClient.TickOptionCommunication += (tickerId, field, impliedVolatility, delta, optPrice, pvDividend, gamma, vega, theta, undPrice) =>
                                                HandleMessage(new TickOptionMessage(tickerId, field, impliedVolatility, delta, optPrice, pvDividend, gamma, vega, theta, undPrice));

            ibClient.AccountSummary     += (reqId, account, tag, value, currency) => HandleMessage(new AccountSummaryMessage(reqId, account, tag, value, currency));
            ibClient.AccountSummaryEnd  += reqId => HandleMessage(new AccountSummaryEndMessage(reqId));
            ibClient.UpdateAccountValue += (key, value, currency, accountName) => HandleMessage(new AccountValueMessage(key, value, currency, accountName));
            ibClient.UpdatePortfolio    += (contract, position, marketPrice, marketValue, averageCost, unrealisedPNL, realisedPNL, accountName) =>
                                           HandleMessage(new UpdatePortfolioMessage(contract, position, marketPrice, marketValue, averageCost, unrealisedPNL, realisedPNL, accountName));

            ibClient.UpdateAccountTime  += timestamp => HandleMessage(new UpdateAccountTimeMessage(timestamp));
            ibClient.AccountDownloadEnd += account => HandleMessage(new AccountDownloadEndMessage(account));
            ibClient.OrderStatus        += (orderId, status, filled, remaining, avgFillPrice, permId, parentId, lastFillPrice, clientId, whyHeld) =>
                                           HandleMessage(new OrderStatusMessage(orderId, status, filled, remaining, avgFillPrice, permId, parentId, lastFillPrice, clientId, whyHeld));

            ibClient.OpenOrder          += (orderId, contract, order, orderState) => HandleMessage(new OpenOrderMessage(orderId, contract, order, orderState));
            ibClient.OpenOrderEnd       += () => HandleMessage(new OpenOrderEndMessage());
            ibClient.ContractDetails    += (reqId, contractDetails) => HandleMessage(new ContractDetailsMessage(reqId, contractDetails));
            ibClient.ContractDetailsEnd += (reqId) => HandleMessage(new ContractDetailsEndMessage());
            ibClient.ExecDetails        += (reqId, contract, execution) => HandleMessage(new ExecutionMessage(reqId, contract, execution));
            ibClient.ExecDetailsEnd     += reqId => addTextToBox("ExecDetailsEnd. " + reqId + "\n");
            ibClient.CommissionReport   += commissionReport => HandleMessage(new CommissionMessage(commissionReport));
            ibClient.FundamentalData    += (reqId, data) => HandleMessage(new FundamentalsMessage(data));
            ibClient.HistoricalData     += (reqId, date, open, high, low, close, volume, count, WAP, hasGaps) =>
                                           HandleMessage(new HistoricalDataMessage(reqId, date, open, high, low, close, volume, count, WAP, hasGaps));

            ibClient.HistoricalDataEnd  += (reqId, startDate, endDate) => HandleMessage(new HistoricalDataEndMessage(reqId, startDate, endDate));
            ibClient.MarketDataType     += (reqId, marketDataType) => addTextToBox("MarketDataType. " + reqId + ", Type: " + marketDataType + "\n");
            ibClient.UpdateMktDepth     += (tickerId, position, operation, side, price, size) => HandleMessage(new DeepBookMessage(tickerId, position, operation, side, price, size, ""));
            ibClient.UpdateMktDepthL2   += (tickerId, position, marketMaker, operation, side, price, size) => HandleMessage(new DeepBookMessage(tickerId, position, operation, side, price, size, marketMaker));
            ibClient.UpdateNewsBulletin += (msgId, msgType, message, origExchange) =>
                                           addTextToBox("News Bulletins. " + msgId + " - Type: " + msgType + ", Message: " + message + ", Exchange of Origin: " + origExchange + "\n");

            ibClient.Position          += (account, contract, pos, avgCost) => HandleMessage(new PositionMessage(account, contract, pos, avgCost));
            ibClient.PositionEnd       += () => addTextToBox("PositionEnd \n");
            ibClient.RealtimeBar       += (reqId, time, open, high, low, close, volume, WAP, count) => HandleMessage(new RealTimeBarMessage(reqId, time, open, high, low, close, volume, WAP, count));
            ibClient.ScannerParameters += xml => HandleMessage(new ScannerParametersMessage(xml));
            ibClient.ScannerData       += (reqId, rank, contractDetails, distance, benchmark, projection, legsStr) =>
                                          HandleMessage(new ScannerMessage(reqId, rank, contractDetails, distance, benchmark, projection, legsStr));

            ibClient.ScannerDataEnd          += reqId => addTextToBox("ScannerDataEnd. " + reqId + "\r\n");
            ibClient.ReceiveFA               += (faDataType, faXmlData) => HandleMessage(new AdvisorDataMessage(faDataType, faXmlData));
            ibClient.BondContractDetails     += (requestId, contractDetails) => addTextToBox("Receiving bond contract details.");
            ibClient.VerifyMessageAPI        += apiData => addTextToBox("verifyMessageAPI: " + apiData);
            ibClient.VerifyCompleted         += (isSuccessful, errorText) => addTextToBox("verifyCompleted. IsSuccessfule: " + isSuccessful + " - Error: " + errorText);
            ibClient.VerifyAndAuthMessageAPI += (apiData, xyzChallenge) => addTextToBox("verifyAndAuthMessageAPI: " + apiData + " " + xyzChallenge);
            ibClient.VerifyAndAuthCompleted  += (isSuccessful, errorText) => addTextToBox("verifyAndAuthCompleted. IsSuccessfule: " + isSuccessful + " - Error: " + errorText);
            ibClient.DisplayGroupList        += (reqId, groups) => addTextToBox("DisplayGroupList. Request: " + reqId + ", Groups" + groups);
            ibClient.DisplayGroupUpdated     += (reqId, contractInfo) => addTextToBox("displayGroupUpdated. Request: " + reqId + ", ContractInfo: " + contractInfo);

            ibClient.PositionMulti                        += (reqId, account, modelCode, contract, pos, avgCost) => HandleMessage(new PositionMultiMessage(reqId, account, modelCode, contract, pos, avgCost));
            ibClient.PositionMultiEnd                     += (reqId) => HandleMessage(new PositionMultiEndMessage(reqId));
            ibClient.AccountUpdateMulti                   += (reqId, account, modelCode, key, value, currency) => HandleMessage(new AccountUpdateMultiMessage(reqId, account, modelCode, key, value, currency));
            ibClient.AccountUpdateMultiEnd                += (reqId) => HandleMessage(new AccountUpdateMultiEndMessage(reqId));
            ibClient.SecurityDefinitionOptionParameter    += (reqId, exchange, underlyingConId, tradingClass, multiplier, expirations, strikes) => HandleMessage(new SecurityDefinitionOptionParameterMessage(reqId, exchange, underlyingConId, tradingClass, multiplier, expirations, strikes));
            ibClient.SecurityDefinitionOptionParameterEnd += (reqId) => HandleMessage(new SecurityDefinitionOptionParameterEndMessage(reqId));
            ibClient.SoftDollarTiers                      += (reqId, tiers) => HandleMessage(new SoftDollarTiersMessage(reqId, tiers));
        }