static void Main(string[] args) { // Test if input arguments were supplied: Arguments CommandLine = new Arguments(args); if (CommandLine["source"] != null) { Console.WriteLine("DataSource is " + CommandLine["source"] + "\n"); } else { Console.WriteLine("Source was not defined"); } // DateTime s = new DateTime(2009,11,12); // DateTime e = new DateTime(2009, 11, 13); // BarList bar = TradeLink.Common.BarListImpl.DayFromYahoo("GOOG",s,e); BarList bar = TradeLink.Common.BarListImpl.DayFromYahoo("GOOG"); TradeLink.Common.TikWriter tw = new TradeLink.Common.TikWriter("GOOG"); Tick t = null; CultureInfo provider = CultureInfo.InvariantCulture; for (int i = bar.Count; i >= 0; i--) { string[] bardata = new string[] { bar[i].Open.ToString(), bar[i].High.ToString(), bar[i].Low.ToString(), bar[i].Close.ToString() }; string mydate = bar[i].Bardate.ToString().Replace("-", ""); mydate = mydate.Replace("/", ""); for (int n = 0; n <= 3; n++) { t = new TradeLink.Common.TickImpl("GOOG"); t.time = 160000; t.size = Convert.ToInt32(bar[i].Volume / 4); t.date = int.Parse(mydate); t.trade = decimal.Parse(bardata[n]); Console.WriteLine(n + " " + mydate + " " + t.trade); tw.newTick(t); } } tw.Close(); }
/// <summary> /// returns true if more data to process, false otherwise /// </summary> /// <returns></returns> public bool NextTick() { if (!_haveheader) { ReadHeader(); } try { // get tick type byte type = ReadByte(); // prepare a tick TickImpl k = new TradeLink.Common.TickImpl(_realsymbol); // get the tick switch (type) { case TikConst.EndData: return(false); case TikConst.EndTick: return(true); case TikConst.StartData: return(true); case TikConst.Version: return(true); case TikConst.TickAsk: { k.date = ReadInt32(); k.time = ReadInt32(); k.datetime = ((long)k.date * 1000000) + (long)k.time; k._ask = ReadUInt64(); k.os = ReadInt32(); k.oe = ReadString(); k.depth = ReadInt32(); break; } case TikConst.TickBid: { k.date = ReadInt32(); k.time = ReadInt32(); k.datetime = ((long)k.date * 1000000) + (long)k.time; k._bid = ReadUInt64(); k.bs = ReadInt32(); k.be = ReadString(); k.depth = ReadInt32(); } break; case TikConst.TickFull: { k.date = ReadInt32(); k.time = ReadInt32(); k.datetime = ((long)k.date * 1000000) + (long)k.time; k._trade = ReadUInt64(); k.size = ReadInt32(); k.ex = ReadString(); k._bid = ReadUInt64(); k.bs = ReadInt32(); k.be = ReadString(); k._ask = ReadUInt64(); k.os = ReadInt32(); k.oe = ReadString(); k.depth = ReadInt32(); } break; case TikConst.TickQuote: { k.date = ReadInt32(); k.time = ReadInt32(); k.datetime = ((long)k.date * 1000000) + (long)k.time; k._bid = ReadUInt64(); k.bs = ReadInt32(); k.be = ReadString(); k._ask = ReadUInt64(); k.os = ReadInt32(); k.oe = ReadString(); k.depth = ReadInt32(); } break; case TikConst.TickTrade: { k.date = ReadInt32(); k.time = ReadInt32(); k.datetime = ((long)k.date * 1000000) + (long)k.time; k._trade = ReadUInt64(); k.size = ReadInt32(); k.ex = ReadString(); } break; default: // weird data, try to keep reading ReadByte(); // but don't send this tick, just get next record return(true); } // send any tick we have if (gotTick != null) { gotTick(k); } // read end of tick ReadByte(); // count it Count++; // assume there is more return(true); } catch (EndOfStreamException) { Close(); return(false); } catch (ObjectDisposedException) { return(false); } }
/// <summary> /// returns true if more data to process, false otherwise /// </summary> /// <returns></returns> public bool NextTick() { if (!_haveheader) ReadHeader(); try { // get tick type byte type = ReadByte(); // prepare a tick TickImpl k = new TradeLink.Common.TickImpl(_realsymbol); // get the tick switch (type) { case TikConst.EndData: return false; case TikConst.EndTick: return true; case TikConst.StartData: return true; case TikConst.Version: return true; case TikConst.TickAsk: { k.date = ReadInt32(); k.time = ReadInt32(); k.datetime = ((long)k.date * 1000000) + (long)k.time; k._ask = ReadUInt64(); k.os = ReadInt32(); k.oe = ReadString(); k.depth = ReadInt32(); break; } case TikConst.TickBid: { k.date = ReadInt32(); k.time = ReadInt32(); k.datetime = ((long)k.date * 1000000) + (long)k.time; k._bid = ReadUInt64(); k.bs = ReadInt32(); k.be = ReadString(); k.depth = ReadInt32(); } break; case TikConst.TickFull: { k.date = ReadInt32(); k.time = ReadInt32(); k.datetime = ((long)k.date * 1000000) + (long)k.time; k._trade = ReadUInt64(); k.size = ReadInt32(); k.ex = ReadString(); k._bid = ReadUInt64(); k.bs = ReadInt32(); k.be = ReadString(); k._ask = ReadUInt64(); k.os = ReadInt32(); k.oe = ReadString(); k.depth = ReadInt32(); } break; case TikConst.TickQuote: { k.date = ReadInt32(); k.time = ReadInt32(); k.datetime = ((long)k.date * 1000000) + (long)k.time; k._bid = ReadUInt64(); k.bs = ReadInt32(); k.be = ReadString(); k._ask = ReadUInt64(); k.os = ReadInt32(); k.oe = ReadString(); k.depth = ReadInt32(); } break; case TikConst.TickTrade: { k.date = ReadInt32(); k.time = ReadInt32(); k.datetime = ((long)k.date * 1000000) + (long)k.time; k._trade = ReadUInt64(); k.size = ReadInt32(); k.ex = ReadString(); } break; default: // weird data, try to keep reading ReadByte(); // but don't send this tick, just get next record return true; } // send any tick we have if (gotTick != null) gotTick(k); // read end of tick ReadByte(); // count it Count++; // assume there is more return true; } catch (EndOfStreamException) { Close(); return false; } catch (ObjectDisposedException) { return false; } }