public void SelectOption(string exchange, string contract, string expiredate) { var optionList = (from c in _contractList where c.Exchange == exchange && c.UnderlyingContract == contract && c.ExpireDate == expiredate select c).ToList(); var strikeList = (from o in optionList orderby o.StrikePrice select o.StrikePrice).Distinct().ToList(); var callList = (from o in optionList where o.ContractType == (int)ContractType.CONTRACTTYPE_CALL_OPTION orderby o.StrikePrice select new ContractKeyVM(exchange, o.Contract)).ToList(); var putList = (from o in optionList where o.ContractType == (int)ContractType.CONTRACTTYPE_PUT_OPTION orderby o.StrikePrice select new ContractKeyVM(exchange, o.Contract)).ToList(); ClearTheoPlot(); CallPutTDOptionVMCollection.Clear(); _optionTheoCallVMList.Clear(); _optionTheoPutVMList.Clear(); var retList = _otcHandler.MakeCallPutTDOptionData(strikeList, callList, putList); foreach (var vm in retList) { CallPutTDOptionVMCollection.Add(vm); _optionTheoCallVMList.Add(new KeyValuePair <ContractKeyVM, double>(vm.CallOptionVM, vm.StrikePrice)); _optionTheoPutVMList.Add(new KeyValuePair <ContractKeyVM, double>(vm.PutOptionVM, vm.StrikePrice)); VolatilityModelVM.TheoAskVolLine.Add(DataPoint.Undefined); VolatilityModelVM.TheoBidVolLine.Add(DataPoint.Undefined); VolatilityModelVM.TheoMidVolLine.Add(DataPoint.Undefined); VolatilityModelVM.TheoAskVolLine1.Add(DataPoint.Undefined); VolatilityModelVM.TheoBidVolLine1.Add(DataPoint.Undefined); VolatilityModelVM.TheoMidVolLine1.Add(DataPoint.Undefined); double value = (vm.PutStrategyVM != null && vm.PutStrategyVM.AskEnabled) ? 1 : 0; VolatilityModelVM.TheoPutAskVolScatter.Add(new ScatterPoint(vm.StrikePrice, 0, 0, value, vm.PutStrategyVM)); value = (vm.PutStrategyVM != null && vm.PutStrategyVM.BidEnabled) ? 1 : 0; VolatilityModelVM.TheoPutBidVolScatter.Add(new ScatterPoint(vm.StrikePrice, 0, 0, value, vm.PutStrategyVM)); value = (vm.CallStrategyVM != null && vm.CallStrategyVM.AskEnabled) ? 1 : 0; VolatilityModelVM.TheoCallAskVolScatter.Add(new ScatterPoint(vm.StrikePrice, 0, 0, value, vm.CallStrategyVM)); value = (vm.CallStrategyVM != null && vm.CallStrategyVM.BidEnabled) ? 1 : 0; VolatilityModelVM.TheoCallBidVolScatter.Add(new ScatterPoint(vm.StrikePrice, 0, 0, value, vm.CallStrategyVM)); } }
private async void expireDateCB_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (AutoOrder_CheckBox.IsChecked.Value) { AutoOrderUpdate(false); } var exchange = exchangeCB.SelectedValue?.ToString(); if (exchange != null) { if (expireDateCB.SelectedValue != null) { var ed = expireDateCB.SelectedValue.ToString(); var uc = underlyingContractCB.SelectedValue.ToString(); var optionList = (from c in _contractList where c.Exchange == exchange && c.UnderlyingContract == uc && c.ExpireDate == ed select c).ToList(); var strikeList = (from o in optionList orderby o.StrikePrice descending select o.StrikePrice).Distinct().ToList(); var callList = (from o in optionList where o.ContractType == (int)ContractType.CONTRACTTYPE_CALL_OPTION orderby o.StrikePrice descending select new ContractKeyVM(exchange, o.Contract)).ToList(); var putList = (from o in optionList where o.ContractType == (int)ContractType.CONTRACTTYPE_PUT_OPTION orderby o.StrikePrice descending select new ContractKeyVM(exchange, o.Contract)).ToList(); var marketDataList = await _marketdataHandler.SubMarketDataAsync(optionList.Select(c => new ContractKeyVM(c.Exchange, c.Contract))); var retList = _otcOptionHandler.MakeCallPutTDOptionData(strikeList, callList, putList, marketDataList); _subbedContracts = await _otcOptionHandler.SubTradingDeskDataAsync(optionList.Select(c => new ContractKeyVM(c.Exchange, c.Contract))); CallPutTDOptionVMCollection.Clear(); foreach (var vm in retList) { CallPutTDOptionVMCollection.Add(vm); var CallPositionLong = 0; var CallPositionShort = 0; var PutPositionLong = 0; var PutPositionShort = 0; var CallPositionVMLong = _tradeExHandler.PositionVMCollection.FirstOrDefault(c => c.Contract == vm.CallOptionVM.Contract && c.Direction == PositionDirectionType.PD_LONG); var PutPositionVMLong = _tradeExHandler.PositionVMCollection.FirstOrDefault(c => c.Contract == vm.PutOptionVM.Contract && c.Direction == PositionDirectionType.PD_LONG); var CallPositionVMShort = _tradeExHandler.PositionVMCollection.FirstOrDefault(c => c.Contract == vm.CallOptionVM.Contract && c.Direction == PositionDirectionType.PD_SHORT); var PutPositionVMShort = _tradeExHandler.PositionVMCollection.FirstOrDefault(c => c.Contract == vm.PutOptionVM.Contract && c.Direction == PositionDirectionType.PD_SHORT); if (CallPositionVMLong != null) { CallPositionLong = CallPositionVMLong.Position; } if (CallPositionVMShort != null) { CallPositionShort = CallPositionVMShort.Position; } if (PutPositionVMLong != null) { PutPositionLong = PutPositionVMLong.Position; } if (PutPositionVMShort != null) { PutPositionShort = PutPositionVMShort.Position; } vm.PutOptionVM.Position = PutPositionLong - PutPositionShort; vm.CallOptionVM.Position = CallPositionLong - CallPositionShort; } var strategyVM = CallPutTDOptionVMCollection.FirstOrDefault().CallStrategyVM ?? CallPutTDOptionVMCollection.LastOrDefault().CallStrategyVM; if (strategyVM != null) { pricingModelCB.ItemsSource = null; volModelLB.Content = null; riskFree_Interest.DataContext = null; adjustment.DataContext = null; AutoOrder_CheckBox.DataContext = null; underlyingEX1.ItemsSource = null; underlyingCB1.ItemsSource = null; orderConditionCombo.SelectedValue = null; underlyingContractCB1.ItemsSource = null; underlyingEX1.ItemsSource = _futurecontractList.Select(c => c.Exchange).Distinct(); pricingModelCB.ItemsSource = _otcOptionHandler.GetModelParamsVMCollection("pm"); if (strategyVM != null) { var pricingContractParamVM = strategyVM.PricingContractParams?.FirstOrDefault(); if (pricingContractParamVM != null) { var futureexchange = pricingContractParamVM.Exchange; var futurecontract = pricingContractParamVM.Contract; var futureunderlying = _futurecontractList.FirstOrDefault(c => c.Exchange == futureexchange && c.Contract == futurecontract)?.ProductID; var adjust = pricingContractParamVM.Adjust; var pricingmodel = strategyVM.PricingModel; var volmodel = strategyVM.VolModel; pricingModelCB.SelectedValue = pricingmodel; underlyingEX1.SelectedValue = futureexchange; underlyingCB1.SelectedValue = futureunderlying; underlyingContractCB1.SelectedValue = futurecontract; volModelLB.Content = volmodel; adjustment.Value = adjust; AutoOrder_CheckBox.DataContext = strategyVM; CountertextBox.DataContext = strategyVM; AutoMaxTradeUpdate((int)CountertextBox.Value); TickSizeIUD.DataContext = strategyVM; orderConditionCombo.SelectedValue = OrderConditionType.LIMIT; var modelVM = pricingModelCB.SelectedItem as ModelParamsVM; if (modelVM != null) { riskFree_Interest.DataContext = modelVM; } } } } } } }