public static Index FromFile(string filename) { System.IO.StreamReader sr = new System.IO.StreamReader(filename); Index i = new Index(); i = Index.Deserialize(sr.ReadLine()); i._histfile = sr; return(i); }
/// <summary> /// Build a barlist using an IDX (index) file as a source. /// </summary> /// <param name="filename">The filename.</param> /// <returns></returns> public static BarList FromIDX(string filename) { System.IO.StreamReader sr = new System.IO.StreamReader(filename); Index i = Index.Deserialize(sr.ReadLine()); BarList b = new BarList(BarInterval.FiveMin, i.Name); b.AddTick(i.ToTick()); while (!sr.EndOfStream) { b.AddTick(Index.Deserialize(sr.ReadLine()).ToTick()); } return(b); }
protected override void WndProc(ref System.Windows.Forms.Message m) { long result = 0; TradeLinkMessage tlm = WMUtil.ToTradeLinkMessage(ref m); if (tlm == null) // if it's not a WM_COPYDATA message { base.WndProc(ref m); // let form process it return; // we're done } string msg = tlm.body; string[] r = msg.Split(','); switch (tlm.type) { case TL2.ORDERCANCELRESPONSE: if (gotOrderCancel != null) { gotOrderCancel(Convert.ToUInt32(msg)); } break; case TL2.TICKNOTIFY: if (Index.isIdx(r[(int)TickField.symbol])) { // we got an index update Index i = Index.Deserialize(msg); if (gotIndexTick != null) { gotIndexTick(i); } break; } Tick t = Tick.Deserialize(msg); if (t.isTrade) { try { if (t.trade > chighs[t.sym]) { chighs[t.sym] = t.trade; } if (t.trade < clows[t.sym]) { clows[t.sym] = t.trade; } } catch (KeyNotFoundException) { decimal high = DayHigh(t.sym); decimal low = DayLow(t.sym); chighs.Add(t.sym, high); if (low == 0) { low = 640000; } clows.Add(t.sym, low); } } if (gotTick != null) { gotTick(t); } break; case TL2.EXECUTENOTIFY: // date,time,symbol,side,size,price,comment Trade tr = Trade.Deserialize(msg); try { cpos[tr.symbol] = new Position(tr.symbol, AvgPrice(tr.symbol), PosSize(tr.symbol)); } catch (KeyNotFoundException) { cpos.Add(tr.symbol, new Position(tr.symbol, AvgPrice(tr.symbol), PosSize(tr.symbol))); } if (gotFill != null) { gotFill(tr); } break; case TL2.ORDERNOTIFY: Order o = Order.Deserialize(msg); if (gotOrder != null) { gotOrder(o); } break; case TL2.ACCOUNTRESPONSE: if (gotAccounts != null) { gotAccounts(msg); } break; case TL2.FEATURERESPONSE: string[] p = msg.Split(','); List <TL2> f = new List <TL2>(); foreach (string s in p) { try { f.Add((TL2)Convert.ToInt32(s)); } catch (Exception) { } } if (gotSupportedFeatures != null) { gotSupportedFeatures(f.ToArray()); } break; } result = 0; m.Result = (IntPtr)result; }