private static StonkValues GetValues(IQuote quote) { StonkValues vals = new StonkValues(quote.Symbol, quote.TimestampUtc, (double)quote.AskPrice, (double)quote.BidPrice); return(vals); }
public static async Task GetMarketData(List <StonkValues> vals) { AppleNetwork net = new AppleNetwork(); var DClient = Alpaca.Markets.Environments.Paper .GetAlpacaDataClient(new SecretKey(API_KEY, API_SECRET)); var TClient = Alpaca.Markets.Environments.Paper .GetAlpacaTradingClient(new SecretKey(API_KEY, API_SECRET)); var clock = await TClient.GetClockAsync(); try { List <List <StonkValues> > multibars = new List <List <StonkValues> >(); List <double[]> maxes = new List <double[]>(); Random r = new Random(); var now = DateTime.Now; for (int ct = 0; ct < 16; ct++) { try { var into = new DateTime(now.Year, now.Month, now.Day); var from = into.AddDays(-1 * r.Next(1, 500)); while (from.DayOfWeek == DayOfWeek.Sunday || from.DayOfWeek == DayOfWeek.Saturday) { from.AddDays(1); } into = from.AddDays(1); ValueSet set = new ValueSet(); var aaplbars = await DClient.ListHistoricalBarsAsync(new HistoricalBarsRequest("AAPL", from, into, BarTimeFrame.Minute)); var qqqbars = await DClient.ListHistoricalBarsAsync(new HistoricalBarsRequest("QQQ", from, into, BarTimeFrame.Minute)); var vtibars = await DClient.ListHistoricalBarsAsync(new HistoricalBarsRequest("VTI", from, into, BarTimeFrame.Minute)); var bars = new List <StonkValues>(); StonkValues sv = GetValues(aaplbars.Items[0]); var finbar = aaplbars.Items[r.Next(aaplbars.Items.Count()) - 1]; var compbar = aaplbars.Items.GetComparable(); if (DateTime.Compare(finbar.TimeUtc, compbar.TimeUtc) < 0) { Console.WriteLine("Fin Bar Time is : " + finbar.TimeUtc); Console.WriteLine("Comp Bar Time is : " + compbar.TimeUtc); set.FinValue = GetValues(finbar); set.CompValue = GetValues(compbar); set.Increase = (finbar.Open + 1) < compbar.Open; foreach (var b in aaplbars.Items) { if (DateTime.Compare(b.TimeUtc, finbar.TimeUtc) < 0) { set.Values.Add(GetValues(b)); } } foreach (var b in qqqbars.Items) { if (DateTime.Compare(b.TimeUtc, finbar.TimeUtc) < 0) { set.Values.Add(GetValues(b)); } } foreach (var b in vtibars.Items) { if (DateTime.Compare(b.TimeUtc, finbar.TimeUtc) < 0) { set.Values.Add(GetValues(b)); } } } net.Propogate(set, Write); set.Save(Datatype.AAPL); } catch (Exception e) { e.OutputError(); } } //net.Propogate(multibars, maxes, new WriteToCMDLine(Write)); } catch (Exception e) { e.OutputError(); } /* * if (clock.IsOpen) * { * var AAPLQuote = GetValues(await DClient.GetLatestQuoteAsync("AAPL")); * var QQQQuote = GetValues(await DClient.GetLatestQuoteAsync("QQQ")); * var VTIQuote = GetValues(await DClient.GetLatestQuoteAsync("VTI")); * * vals.Add(AAPLQuote); * vals.Add(QQQQuote); * vals.Add(VTIQuote); * * try * { * if(vals.Count() > 6) * { * if(vals.Any(x => x.Symbol == "AAPL")) * { * var prediction = net.Predict(vals, new WriteToCMDLine(Write)); * Write("Prediction : " + prediction[0] + ", " + prediction[1]); * } * } * } * catch (Exception e) * { * e.OutputError(); * } * * }*/ Console.Read(); }
private static StonkValues GetValues(IBar bar) { StonkValues vals = new StonkValues(bar.Symbol, bar.TimeUtc, (double)bar.Open); return(vals); }