public static MarketQuote GetCurrentMarketData(string symbol, StockExchange exchange) { string url_currentMarketData; MarketQuote marketQuote = new MarketQuote(); // switch (exchange.stockExchange_Name) { case "NASDAQ": url_currentMarketData = "https://api.tdameritrade.com/v1/marketdata/" + symbol + "/quotes?apikey=8FBL4ZPB5OPNLAAM90FRWYFKAMYNIVKH"; try { HttpClient client = new HttpClient(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); HttpResponseMessage response = client.GetAsync(url_currentMarketData).Result; if (response.IsSuccessStatusCode) { string JSON = response.Content.ReadAsStringAsync().Result; JObject jobject = JObject.Parse(JSON); JToken jStock = jobject[symbol]; marketQuote.openPrice = (float)jStock["openPrice"]; marketQuote.closePrice = (float)jStock["closePrice"]; marketQuote.lastPrice = (float)jStock["lastPrice"]; marketQuote.highPrice = (float)jStock["highPrice"]; marketQuote.lowPrice = (float)jStock["lowPrice"]; marketQuote.netChange = (float)jStock["netChange"]; marketQuote.totalVolume = (int)jStock["totalVolume"]; marketQuote.volatility = (float)jStock["volatility"]; marketQuote.w52WkHigh = (float)jStock["52WkHigh"]; marketQuote.w52WkLow = (float)jStock["52WkLow"]; marketQuote.markPercentChange = (float)jStock["markPercentChangeInDouble"]; } break; } catch (Exception ex) { //log error return(null); } default: break; } return(marketQuote); }
public static bool UpdateStockObjectWithMarketData(MarketQuote marketQoute, ref Stock e_stock) { try { e_stock.today_Close = marketQoute.closePrice; e_stock.today_High = marketQoute.highPrice; e_stock.today_Low = marketQoute.lowPrice; e_stock.today_Open = marketQoute.openPrice; e_stock.today_Close = marketQoute.closePrice; e_stock.today_Volume = marketQoute.totalVolume; e_stock.volatility = marketQoute.volatility; e_stock.week52High = marketQoute.w52WkHigh; e_stock.week52Low = marketQoute.w52WkLow; e_stock.netChange = marketQoute.netChange; e_stock.last_Price = marketQoute.lastPrice; return(true); } catch (Exception) { return(false);; } }
public bool ProcessRules(StockInfo stockInfo, StockExchange stockExchange)//int ruleType, symbol, ruleXML { bool result_TaLib = false; bool result_PriceBar = false; bool result_PrevioudDayPriceBar = false; bool result_CurrentDayPriceBar = false; bool result_Indices = false; bool result_Sentiments = false; bool result_NASDAQindicator = false; MarketQuote marketQoute = new MarketQuote(); //create Stock object which is the feed for Codefeects rule engine Stock e_stock = new Stock(); e_stock.Symbol = stockInfo.stock_symbol; e_stock.StockID = stockInfo.stock_ID; e_stock.StockExchangeID = stockExchange.stockExchange_ID; try { // fill with market data - open close high low marketQoute = APIReader.GetCurrentMarketData(stockInfo.stock_symbol, stockExchange); } catch (Exception) { Console.WriteLine("ERR in GetCurrentMarketData()"); } result_CurrentDayPriceBar = MarketData.UpdateStockObjectWithMarketData(marketQoute, ref e_stock); //get History data List <Candle> candles = new List <Candle>(); try { candles = APIReader.GetPriceHistory(stockInfo.stock_symbol, stockExchange); } catch (Exception) { Console.WriteLine("ERR in GetPriceHistory()"); } //build a stock qoute object which will be used for all other calculations. this is holding data which needs for other analysis StockQuote stockQuote = new StockQuote(); stockQuote.stock_candles = candles; //fill with previous day market data result_PrevioudDayPriceBar = MarketData.UpdateStockObjectWithPreviousDayData(stockQuote, ref e_stock); //fill with Talib values // result_TaLib = TaLib.UpdateStockObjectWithTechnicalAnalysisData(stockQuote, ref e_stock); //get volatality factor) result_Indices = Indices.UpdateStockObjectWithIndicesData(stockQuote, ref e_stock); //Get sentinments) result_Sentiments = Sentiments.UpdateStockObjectWithSentimentData(ref e_stock); //get rule xml //if (ruleType == 1) //execute //{ // ///execute rule xml /// //// Get the rule XML //// Load Rule XML from the storage as a string List <CERule> rules = new List <CERule>(); rules = ShareBook.App.Engine.Common.Data.DB.LoadRuleXml(1); foreach (CERule rule in rules) { Evaluator <Stock> evaluator = new Evaluator <Stock>(rule.RuleXml); try { e_stock.RuleID = rule.RuleID; // Evaluate the rule against the patient bool success = evaluator.Evaluate(e_stock); } catch (DivideByZeroException) { Console.WriteLine("ERR at rule evaluation-DivideByZeroException"); return(false); } catch (FormatException) { Console.WriteLine("ERR at rule evaluation-FormatException"); return(false); } } return(true); }
public virtual void OnQuote(MarketQuote quote) { }
public OnQuote(MarketQuote quote) { this.Quote = quote; }
public void OnQuote(MarketQuote quote) { Context.Logger.Info(String.Format("on_quote {0} {1} {2} {3}", quote.Code, quote.Time, quote.Last, quote.Volume)); }
static void OnMarketQuote(MarketQuote quote) { Console.WriteLine("on_quote: " + quote.Date + "," + quote.Time + "," + quote.Code + "," + quote.Last + "," + quote.Volume); }
public override void OnQuote(MarketQuote quote) { //Context.Logger.Info(String.Format("OnQuote {0} {1} {2} {3}", quote.Code, quote.Time, quote.Last, quote.Volume)); Context.TradeApi.QueryOrders("sim"); }