public static Contract BuildUSStock(ActiveContract t) { Contract contract = new Contract(); contract.Symbol = "AMZN"; contract.SecType = "STK"; contract.Currency = "USD"; contract.Exchange = "SMART"; return(contract); }
static public dynamic GetPriceData(ActiveContract t) { Console.WriteLine("--Getting Data For: " + t.IBFuturesLocalSymbol); using (var jetiDB = new JETIEntities()) { return((from PriceCapture p in jetiDB.PriceCaptures where p.Ticker == t.IBFuturesLocalSymbol //& p.IBTimestamp == DateTime.Today select new { p.IBTimestamp, p.Ticker, p.Price }).ToList()); } }
public static Contract BuildNymexFuturesContract(ActiveContract t) { Contract contract = new Contract(); contract.SecType = "FUT"; if (t.IBFuturesLocalSymbol.Substring(t.IBFuturesLocalSymbol.Length - 2) == "ES") { contract.Exchange = "GLOBEX"; } else { contract.Exchange = "NYMEX"; } contract.Currency = "USD"; contract.LocalSymbol = t.IBFuturesLocalSymbol; contract.reqId = Contract.GetActiveInstances(); return(contract); }
static public DataTable GetPricesFromDB(ActiveContract t, int periods) { DataTable dt = new DataTable(); dt.Columns.Add("time", typeof(DateTime)); dt.Columns.Add("ticker", typeof(string)); dt.Columns.Add("price", typeof(double)); using (var jetiDB = new JETIEntities()) { var q = (from PriceCapture p in jetiDB.PriceCaptures where p.Ticker == t.IBFuturesLocalSymbol orderby p.IBTimestamp descending //& p.IBTimestamp == DateTime.Today select new { p.IBTimestamp, p.Ticker, p.Price }).Take(periods); foreach (var k in q) { dt.Rows.Add(k.IBTimestamp, k.Ticker, k.Price); //Console.WriteLine(""); } } return(dt); }
public static int Main(string[] args) { //Connect to the API EWrapperImpl ApiWrapper = new EWrapperImpl(); //public EWrapperImpl ApiWrapper; ApiWrapper.ClientSocket.eConnect("127.0.0.1", 7496, 0, false); // before proceding, monitor nextValidId while (ApiWrapper.NextOrderId <= 0) { } // Load securities var activecontracts = GetActiveContracts(); // If no tickers found in database, load a default (hard coded) ticker if (activecontracts.Count == 0) { ActiveContract defaultcontract = new ActiveContract(); DateTime date1 = new DateTime(1900, 12, 31, 0, 0, 0); defaultcontract.ActivityDate = date1; defaultcontract.IBFuturesLocalSymbol = "ZZN6"; activecontracts.Add(defaultcontract); } // BUILD A CONTRACT FOR EACH TICKER var IBcontractlist = new List <Contract>(); activecontracts.ForEach(t => { if (t.ActivityDate == DateTime.Today) { Contract nextcontract = BuildNymexFuturesContract(t); IBcontractlist.Add(nextcontract); } }); // set up dataTable for capture of datafeed price data p.Columns.Add("ticker", typeof(string)); p.Columns.Add("close", typeof(float)); p.Columns.Add("time", typeof(Int64)); //p.Columns.Add("processed", typeof(DateTime)); // set up dictionary of Tickers:ReqIds int i = 0; Parallel.ForEach(IBcontractlist, (t) => { i++; reqIds.Add(t.LocalSymbol, i); }); // open an api datafeed for each contract Parallel.ForEach(IBcontractlist, (t) => { i++; ApiWrapper.ClientSocket.reqRealTimeBars(t.reqId, t, -1, "BID", false, GetFakeParameters(4)); Thread.Sleep(5000); }); // dequeue price updates and write to database while (1 > 0) { // if new data arrived... if (q.Count > 0) { rtbUpdateStruct t = new rtbUpdateStruct(); t = (rtbUpdateStruct)q.Dequeue(); // write to console Console.WriteLine(t.ticker + ", close: " + t.close + ", time: " + t.time); // write to database ApiWrapper.RealTimeBarCapturetoDB(t.close, t.time, t.ticker); // append to datatable p.Rows.Add(t.ticker, t.close, t.time); // update technical indicators //Studies(t.ticker); //Scores(t.ticker); //Weights(t.ticker); //Trades(t.ticker); //Orders(); //Reports(); } } ////Shut down //Console.WriteLine("Disconnecting... Please press ENTER to close application."); //Console.ReadLine(); //ApiWrappper.ClientSocket.eDisconnect(); //return 0; }