private void cnyusdButton_Click(object sender, EventArgs e) { currentSelectedCurrencyPair = CurrencyPairs.CNY2USD; OutputGroupBox.Show(); stockSearchBox.Clear(); resultBox.Text = currentSelectedCurrencyPair.ToString() + " " + DateTime.Now.ToString(); ForexOutput(); }
public void ForexOutput() { StockMarket stockmarket = new StockMarket("MWSOY45W94DB1V3J"); string finalOutputString; string [] currencyInput; string FromCurrency; string ToCurrency; currencyInput = currentSelectedCurrencyPair.ToString().Split('2'); FromCurrency = currencyInput[0]; ToCurrency = currencyInput[1]; try { List <FOREX> GetForexInfo = stockmarket.GetForexInfo(FromCurrency, ToCurrency); FOREX latestData = GetForexInfo[0]; string outputString = string.Format("The current open price of {0} is {1:C2}, highest it has been" + "is {2:C2}, lower it has been is {3:C2}, close is {4}, FOREX info is pulled at {5}, " + "current time is {6:d} at {6:t}", latestData.Pair, latestData.Open, latestData.High, latestData.Low, latestData.Close, latestData.Timestamp, DateTime.Now); finalOutputString = outputString; foreach (FOREX forex in GetForexInfo) { string historicalString = String.Format("" + "Open: {1:C2} \r\n " + "Highest: {2:C2} \r\n " + "Lowest: {3:C2} \r\n " + "Close: {4} \r\n " + "FOREX info is pulled at: {5}, \r\n " + "Current time: {6:d} at {6:t}", forex.Pair, forex.Open, forex.High, forex.Low, forex.Close, forex.Timestamp, DateTime.Now); finalOutputString += "\r\n" + "\r\n" + historicalString; } resultBox.AppendText(finalOutputString); stockPriceBox.Text = latestData.Open.ToString(); } catch (APICallLimitReachedException ex) { MessageBox.Show(ex.Message); } catch (Exception Eex) { MessageBox.Show(Eex.Message); } }
/// <summary> /// Async method to get list of orders by currency pair /// </summary> /// <param name="currencyPairs">Currency pair</param> /// <returns>Order list object, that contains timestamp, asks and bids lists (if there is an error - error info)</returns> public async Task <OrderList> GetOrderListByCurrencyPair(CurrencyPairs currencyPairs) { var _response = await _httpClient.GetStringAsync(Helpers.GetRequestUrl(Constants.API_V2_URL, Constants.GET_ORDER_LIST_ACTION, currencyPairs.ToString())); JObject _root = JObject.Parse(_response); var _orderList = new OrderList { Asks = Helpers.GetOrders(_root, Constants.ASKS_LIST_NAME), Bids = Helpers.GetOrders(_root, Constants.BIDS_LIST_NAME), Error = _root[Constants.ERROR_KEY]?.ToString(), Reason = _root[Constants.REASON_KEY]?.ToString(), Status = _root[Constants.STATUS_KEY]?.ToString(), Timestamp = _root[Constants.TIMESTAMP_KEY].ToString() }; return(_orderList); }
public CurrencyPair(CurrencyPairs currencyPair) { _currencyPair = currencyPair; _baseCurrency = currencyPair.ToString().Split('_')[0]; _quoteCurrency = currencyPair.ToString().Split('_')[1]; }