public MarketDataType(DateTime t, TickTypeEnum tt, double p, int v) { Time = t; TickType = tt; Price = p; Volume = v; }
public override void RecordTickGMT(DateTime time, TickTypeEnum tickType, double price, int volume) { bool newMinuteHappened = false; int newMinute = Int32.Parse(time.ToString("yyMMddHHmm")); if (newMinute != lastMinute) { sw.WriteLine(newMinute.ToString("D10") + "\t" + price.ToString("G10", CultureInfo.InvariantCulture)); lastMinute = newMinute; pivotPrice = price; newMinuteHappened = true; } if ((time.Second != lastSecond) || newMinuteHappened) { sw.WriteLine(time.Second.ToString("D2") + "\t" + (int)tickType + "\t" + Convert.ToInt32((price - pivotPrice) / _tickSize) + "\t" + volume); lastSecond = time.Second; } else sw.WriteLine((int)tickType + "\t" + Convert.ToInt32((price - pivotPrice) / _tickSize) + "\t" + volume); #if FORCEFLUSH sw.Flush(); #endif }
public MarketDataType(DateTime t, TickTypeEnum tt, double p, int v, TimeStampStatus b) { Time = t; TickType = tt; Price = p; Volume = v; IsNewTimeStamp = b; }
public override void RecordTickGMT(DateTime time, TickTypeEnum tickType, double price, int volume) { sw.WriteLine(time.ToString((_useMillisec)?dateformatmillisec:dateformat) + "\t" + (int)tickType + "\t" + price.ToString("G10", CultureInfo.InvariantCulture) + "\t" + volume); #if FORCEFLUSH sw.Flush(); #endif }
public MarketDataType(DateTime t, TickTypeEnum tt, double p, int v,TimeStampStatus b) { Time = t; TickType = tt; Price = p; Volume = v; IsNewTimeStamp=b; }
//Helpers #region Helpers public bool RecordTick(DateTime date, TickTypeEnum tickType, double price, int volume) { DateTime newDateTimeGMT = date.ToUniversalTime(); newDateGMTTicks = newDateTimeGMT.Date.Ticks; if (((_fileMode == Gom.FileModeType.OnePerDay) && (_writeOK) && (newDateGMTTicks > curDateGMTTicks)) || (curDateGMTTicks == 0)) { curDateGMTTicks = newDateGMTTicks; initWrite(); } if ((_writeOK)&&(newDateTimeGMT.Ticks > _lastTimeInFile)) RecordTickGMT(newDateTimeGMT, tickType, price, volume); return _writeOK; }
public override void RecordTickGMT(DateTime time, TickTypeEnum tickType, double price, int volume) { bool newMinuteHappened = false; int newMinute = Int32.Parse(time.ToString("yyMMddHHmm")); if (newMinute != lastMinute) { Byte n1 = checked ((Byte)1 << 6); n1 += checked ((Byte)(newMinute % 61)); bw.Write(n1); UInt32 n2 = checked ((UInt32)newMinute); bw.Write(n2); UInt32 n3 = checked (Convert.ToUInt32(price / _tickSize)); bw.Write(n3); lastMinute = newMinute; pivotPrice = price; newMinuteHappened = true; } int nextTimeStamp = time.Second * 1000 + time.Millisecond; if ((nextTimeStamp != lastTimeStamp) || newMinuteHappened) { writedata(nextTimeStamp, tickType, price, volume, true); lastTimeStamp = nextTimeStamp; } else { writedata(nextTimeStamp, tickType, price, volume, false); } #if FORCEFLUSH bw.Flush(); #endif }
//LEGACY METHODS : DO NOT USE #region Legacy Methods protected virtual void GomOnMarketData(TickTypeEnum tickType, double price, int volume) { }
private int CalcDelta(TickTypeEnum tickType, double price, int volume, GomCDCalculationModeType calcmode, bool backupmode, int filtersize, GomFilterModeType filtermode) { int delta = 0; int direction = lastdirection; if ((calcmode == GomCDCalculationModeType.BidAsk) && (tickType != TickTypeEnum.Unknown) && (tickType != TickTypeEnum.BetweenBidAsk)) { if ((tickType == TickTypeEnum.BelowBid) || (tickType == TickTypeEnum.AtBid)) delta = -volume; else if ((tickType == TickTypeEnum.AboveAsk) || (tickType == TickTypeEnum.AtAsk)) delta = volume; } else if (calcmode == GomCDCalculationModeType.UpDownTick) { if (lastprice != 0) { if (price > lastprice) delta = volume; if (price < lastprice) delta = -volume; } } else if ((calcmode == GomCDCalculationModeType.UpDownTickWithContinuation) ||(calcmode == GomCDCalculationModeType.UpDownOneTickWithContinuation)|| ((calcmode == GomCDCalculationModeType.BidAsk) && (backupmode == true))) { if (price > lastprice) //normal uptick/dn tick direction = 1; else if (price < lastprice) direction = -1; if (calcmode == GomCDCalculationModeType.UpDownOneTickWithContinuation) delta=direction; else delta = direction * volume; } // added else if ((calcmode == GomCDCalculationModeType.Hybrid)) { if (price > lastprice) //normal uptick/dn tick { direction = 1; //price changed, we reinit the startlookingforreversal bool. startlookingforreversal = false; } else if (price < lastprice) { direction = -1; startlookingforreversal = false; } if (!startlookingforreversal) if (direction == 1) //if going up, we want to be hitting bid to be able to start to spot reversals (hitting the ask) startlookingforreversal = (tickType == TickTypeEnum.AtBid) || (tickType == TickTypeEnum.BelowBid); else startlookingforreversal = (tickType == TickTypeEnum.AtAsk) || (tickType == TickTypeEnum.AboveAsk); //what happens when price is same if (price == lastprice) { //if going up, and we have already hit the bid (startlookingforreversal is true) at a price level, // and start hitting the ask, let's reverse if ((direction == 1) && startlookingforreversal && ((tickType == TickTypeEnum.AtAsk) || (tickType == TickTypeEnum.BetweenBidAsk))) direction = -1; else if ((direction == -1) && startlookingforreversal && ((tickType == TickTypeEnum.AtBid) || (tickType == TickTypeEnum.BetweenBidAsk))) direction = 1; //buyers take control of ask } delta = direction * volume; } lastprice = price; lastdirection = direction; if ((filtermode == GomFilterModeType.OnlyLargerThan) && (volume <= filtersize)) delta = 0; if ((filtermode == GomFilterModeType.OnlySmallerThan) && (volume >= filtersize)) delta = 0; return delta; }
protected int CalcDelta(TickTypeEnum tickType, double price, int volume) { return CalcDelta(tickType, price, volume, calcMode, backupMode, filterSize, filterMode); }
public override void RecordTickGMT(DateTime time, TickTypeEnum tickType, double price, int volume) { bool newMinuteHappened = false; //int newMinute = Int32.Parse(time.ToString("yyMMddHHmm")); int newMinute = (time.Year - 2000) * 100000000 + time.Month * 1000000 + time.Day * 10000 + time.Hour * 100 + time.Minute; if (newMinute != lastMinute) { Byte n1 = checked((Byte)1 << 6); n1 += checked((Byte)(newMinute % 61)); bw.Write(n1); UInt32 n2 = checked((UInt32)newMinute); bw.Write(n2); UInt32 n3 = checked(Convert.ToUInt32(price / _tickSize)); bw.Write(n3); lastMinute = newMinute; pivotPrice = price; newMinuteHappened = true; } if ((time.Second != lastSecond) || newMinuteHappened) { writedata(time.Second, tickType, price, volume, true); lastSecond = time.Second; } else writedata(time.Second, tickType, price, volume, false); #if FORCEFLUSH bw.Flush(); #endif }
protected virtual void GomOnMarketDataWithTime(DateTime tickTime, TickTypeEnum tickType, double price, int volume, bool firstTickOfBar) { }
// Virtual Methods virtual public void RecordTickGMT(DateTime date, TickTypeEnum tickType, double price, int volume) { }
private int CalcDelta(TickTypeEnum tickType, double price, int volume, GomCDCalculationModeType calcmode, bool backupmode, int filtersize, GomFilterModeType filtermode) { int delta = 0; int direction = lastdirection; if ((calcmode == GomCDCalculationModeType.BidAsk) && (tickType != TickTypeEnum.Unknown) && (tickType != TickTypeEnum.BetweenBidAsk)) { if ((tickType == TickTypeEnum.BelowBid) || (tickType == TickTypeEnum.AtBid)) { delta = -volume; } else if ((tickType == TickTypeEnum.AboveAsk) || (tickType == TickTypeEnum.AtAsk)) { delta = volume; } } else if (calcmode == GomCDCalculationModeType.UpDownTick) { if (lastprice != 0) { if (price > lastprice) { delta = volume; } if (price < lastprice) { delta = -volume; } } } else if ((calcmode == GomCDCalculationModeType.UpDownTickWithContinuation) || ((calcmode == GomCDCalculationModeType.BidAsk) && (backupmode == true))) { if (price > lastprice) //normal uptick/dn tick { direction = 1; } else if (price < lastprice) { direction = -1; } delta = direction * volume; } // added else if ((calcmode == GomCDCalculationModeType.Hybrid)) { if (price > lastprice) //normal uptick/dn tick { direction = 1; //price changed, we reinit the startlookingforreversal bool. startlookingforreversal = false; } else if (price < lastprice) { direction = -1; startlookingforreversal = false; } if (!startlookingforreversal) { if (direction == 1) { //if going up, we want to be hitting bid to be able to start to spot reversals (hitting the ask) startlookingforreversal = (tickType == TickTypeEnum.AtBid) || (tickType == TickTypeEnum.BelowBid); } else { startlookingforreversal = (tickType == TickTypeEnum.AtAsk) || (tickType == TickTypeEnum.AboveAsk); } } //what happens when price is same if (price == lastprice) { //if going up, and we have already hit the bid (startlookingforreversal is true) at a price level, // and start hitting the ask, let's reverse if ((direction == 1) && startlookingforreversal && ((tickType == TickTypeEnum.AtAsk) || (tickType == TickTypeEnum.BetweenBidAsk))) { direction = -1; } else if ((direction == -1) && startlookingforreversal && ((tickType == TickTypeEnum.AtBid) || (tickType == TickTypeEnum.BetweenBidAsk))) { direction = 1; //buyers take control of ask } } delta = direction * volume; } lastprice = price; lastdirection = direction; if ((filtermode == GomFilterModeType.OnlyLargerThan) && (volume <= filtersize)) { delta = 0; } if ((filtermode == GomFilterModeType.OnlySmallerThan) && (volume >= filtersize)) { delta = 0; } return(delta); }
protected int CalcDelta(TickTypeEnum tickType, double price, int volume) { return(CalcDelta(tickType, price, volume, calcMode, backupMode, filterSize, filterMode)); }
public void writedata(int second, TickTypeEnum tickType, double price, int volume, bool withsecond) { Byte statbyte; Byte sec; int diff; if (withsecond) statbyte = 3 << 6; else statbyte = 2 << 6; statbyte += checked((Byte)((int)tickType << 3)); diff = Convert.ToInt32(((price - pivotPrice) / _tickSize)); if (diff >= -8 && diff <= +7 && volume <= 15) statbyte += 7; else { if ((diff > SByte.MaxValue) || (diff < SByte.MinValue)) statbyte += 1 << 2; if (volume > UInt16.MaxValue) statbyte += 2; else if (volume > Byte.MaxValue) statbyte += 1; } bw.Write(statbyte); if (withsecond) { sec = checked((Byte)second); bw.Write(sec); } // bw.Write((byte)0); if (diff >= -8 && diff <= +7 && volume <= 15) { SByte res = checked((SByte)((SByte)(diff << 4) + volume)); bw.Write(res); } else { if ((diff > SByte.MaxValue) || (diff < SByte.MinValue)) { Int16 res = checked((Int16)diff); bw.Write(res); } else { SByte res = checked((SByte)diff); bw.Write(res); } if (volume > UInt16.MaxValue) { Int32 res = checked((Int32)volume); bw.Write(res); } else if (volume > Byte.MaxValue) { UInt16 res = checked((UInt16)volume); bw.Write(res); } else { Byte res = checked((Byte)volume); bw.Write(res); } } }