private async void buttonPut_Click(object sender, RoutedEventArgs e) { textTime.Text = ""; _watch.Start(); var priceProposalRequest = new PriceProposalRequest { proposal = 1, amount = "100", basis = "payout", contract_type = "PUT", currency = "USD", duration = "60", duration_unit = "s", symbol = "R_100" }; var jsonPriceProposalRequest = JsonConvert.SerializeObject(priceProposalRequest); await _bws.SendRequest(jsonPriceProposalRequest); var jsonPriceProposalResponse = await _bws.StartListen(); var priceProposal = JsonConvert.DeserializeObject <PriceProposalResponse>(jsonPriceProposalResponse); var id = priceProposal.proposal.id; var price = priceProposal.proposal.display_value; await _bws.SendRequest($"{{\"buy\":\"{id}\", \"price\": 100}}"); var jsonBuy = await _bws.StartListen(); _watch.Stop(); textTime.Text = _watch.ElapsedMilliseconds.ToString(); _watch.Reset(); }
private async void Buy(string contractType) { TextTime.Text = ""; _watch.Start(); foreach (var acc in MainWindowViewModel.Accounts.Where(m => m.Selected)) { var priceProposalRequest = new PriceProposalRequest { proposal = 1, amount = ViewModel.BasisValue.ToString(CultureInfo.InvariantCulture), basis = ViewModel.SelectedBasis.Key, contract_type = contractType, currency = ViewModel.SelectedCurrency.Key, duration = ViewModel.Duration.ToString(), duration_unit = ViewModel.SelectedTimeUnit.Key, symbol = ViewModel.SelectedSymbol.symbol // TODO: date_start commented cause it should be tested more carefully // date_start = ViewModel.SelectedStartTime.Key !=0 ? ViewModel.SelectedStartTime.Key : (int)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds }; var jsonPriceProposalRequest = JsonConvert.SerializeObject(priceProposalRequest); acc.Bws.SendRequest(jsonPriceProposalRequest).Wait(); var jsonPriceProposalResponse = Task.Run(() => acc.Bws.StartListen()).Result; var priceProposal = JsonConvert.DeserializeObject <PriceProposalResponse>(jsonPriceProposalResponse); switch (contractType) { case "CALL": ViewModel.CallDisplayValue = priceProposal.proposal != null ? priceProposal.proposal.display_value : string.Empty; ViewModel.CallProposalId = priceProposal.proposal != null ? priceProposal.proposal.id : string.Empty; break; case "PUT": ViewModel.PutDisplayValue = priceProposal.proposal != null ? priceProposal.proposal.display_value : string.Empty; ViewModel.PutProposalId = priceProposal.proposal != null ? priceProposal.proposal.id : string.Empty; break; } var price = "CALL" == contractType ? ViewModel.CallDisplayValue : ViewModel.PutDisplayValue; var id = "CALL" == contractType ? ViewModel.CallProposalId : ViewModel.PutProposalId; if ((string.IsNullOrEmpty(price)) || (string.IsNullOrEmpty(id))) { continue; } await acc.Bws.SendRequest($"{{\"buy\":\"{id}\", \"price\": {price}}}"); var jsonBuy = await acc.Bws.StartListen(); } _watch.Stop(); TextTime.Text = _watch.ElapsedMilliseconds.ToString(); _watch.Reset(); }
public void PriceProposalRequest(string contractType) { if ((string.IsNullOrEmpty(SelectedBasis.Key)) || (string.IsNullOrEmpty(SelectedCurrency.Key)) || (string.IsNullOrEmpty(SelectedTimeUnit.Key)) || string.IsNullOrEmpty(SelectedSymbol?.symbol) || 0 == Duration) { return; } var priceProposalRequest = new PriceProposalRequest { proposal = 1, amount = BasisValue.ToString(CultureInfo.InvariantCulture), basis = SelectedBasis.Key, contract_type = contractType, currency = SelectedCurrency.Key, duration = Duration.ToString(), duration_unit = SelectedTimeUnit.Key, symbol = SelectedSymbol.symbol // TODO: date_start commented cause it should be tested more carefully // date_start = ViewModel.SelectedStartTime.Key !=0 ? ViewModel.SelectedStartTime.Key : (int)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds }; var jsonPriceProposalRequest = JsonConvert.SerializeObject(priceProposalRequest); Task.Run(() => Bws.SendRequest(jsonPriceProposalRequest)).Wait(); var jsonPriceProposalResponse = Task.Run(() => Bws.StartListen()).Result; var priceProposal = JsonConvert.DeserializeObject <PriceProposalResponse>(jsonPriceProposalResponse); switch (contractType) { case "CALL": CallDisplayValue = priceProposal.proposal != null ? priceProposal.proposal.display_value : string.Empty; CallProposalId = priceProposal.proposal != null ? priceProposal.proposal.id : string.Empty; _callPayout = priceProposal.proposal != null ? priceProposal.proposal.payout : string.Empty; OnPropertyChanged("CallLabel"); break; case "PUT": PutDisplayValue = priceProposal.proposal != null ? priceProposal.proposal.display_value : string.Empty; PutProposalId = priceProposal.proposal != null ? priceProposal.proposal.id : string.Empty; _putPayout = priceProposal.proposal != null ? priceProposal.proposal.payout : string.Empty; OnPropertyChanged("PutLabel"); break; } }