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; } }
public void Init() { Accounts.Init(); // Open websocket connection to get Market lists for all accounts Task.Run(() => Bws.Connect()).Wait(); Task.Run(() => Bws.SendRequest("{\"trading_times\":\"2015-09-14\"}")).Wait(); var jsonTradingTimesResponse = Task.Run(() => Bws.StartListen()).Result; var tradingTime = JsonConvert.DeserializeObject <TradingTimesResponse>(jsonTradingTimesResponse); foreach (var market in tradingTime.trading_times.markets) { MarketList.Add(new MarketSubmarket(market)); foreach (var submarket in market.submarkets) { MarketList.Add(new MarketSubmarket(submarket)); } } SelectedMarket = MarketList[0]; }
public string this[string columnName] { get { var errorMessage = string.Empty; if (("Key" != columnName) || (string.IsNullOrEmpty(Key))) { return(errorMessage); } if (_auth.authorize == null) { Status = "Inactive"; OnPropertyChanged("Status"); errorMessage = "auth.authorize == null"; } else { Status = "Active"; OnPropertyChanged("Status"); Username = _auth.authorize.loginid; OnPropertyChanged("Username"); Name = _auth.authorize.fullname; OnPropertyChanged("Name"); Balance = "USD" == _auth.authorize.currency ? $"${_auth.authorize.balance}" : _auth.authorize.balance; OnPropertyChanged("Balance"); // Request for opens positions Task.Run(() => Bws.SendRequest($"{{\"portfolio\":1}}")).Wait(); var jsonPortfolio = Task.Run(() => Bws.StartListen()).Result; var portfolio = JsonConvert.DeserializeObject <PortfolioResponse>(jsonPortfolio); Opens = portfolio.portfolio.contracts.Length; OnPropertyChanged("Opens"); } return(errorMessage); } }