public override void RecordTickGMT(DateTime time, GTickTypeEnum 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 GMarketDataType(DateTime t, GTickTypeEnum tt, double p, int v, GTimeStampStatus b) { time = t; tickType = tt; price = p; volume = v; isNewTimeStamp = b; }
public bool RecordTick(DateTime dt, GTickTypeEnum tickType, double price, int volume) { DateTime newDateTimeGMT = dt.ToUniversalTime(); newDateGMTTicks = newDateTimeGMT.Date.Ticks; if (((_fileMode == GFileModeType.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, GTickTypeEnum 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 }
public override void RecordTickGMT(DateTime time, GTickTypeEnum tickType, double price, int volume) { bool newMinuteHappened = false; 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 }
public void WriteData(int timestamp, GTickTypeEnum tickType, double price, int volume, bool withsecond) { Byte statbyte; ushort 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 ((UInt16)(timestamp)); bw.Write(sec); } 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); } } _pivotPrice = price; }
virtual public void RecordTickGMT(DateTime date, GTickTypeEnum tickType, double price, int volume) { }
protected virtual void GOnMarketDataWithTime(DateTime tickTime, GTickTypeEnum tickType, double price, int volume, bool firstTickOfBar) { }
protected virtual void GOnMarketData(GTickTypeEnum tickType, double price, int volume, bool firstTickOfBar) { }
protected virtual void GOnMarketData(GTickTypeEnum tickType, double price, int volume) { }
private int _CalcDelta(GTickTypeEnum tickType, double price, int volume, GCDCalculationModeType calcmode, bool backupmode, int filtersize, GFilterModeType filtermode) { int delta = 0; int direction = _lastDirection; if ((calcmode == GCDCalculationModeType.BidAsk) && (tickType != GTickTypeEnum.Unknown) && (tickType != GTickTypeEnum.BetweenBidAsk)) { if ((tickType == GTickTypeEnum.BelowBid) || (tickType == GTickTypeEnum.AtBid)) { delta = -volume; } else if ((tickType == GTickTypeEnum.AboveAsk) || (tickType == GTickTypeEnum.AtAsk)) { delta = volume; } } else if (calcmode == GCDCalculationModeType.UpDownTick) { if (_lastPrice != 0) { if (price > _lastPrice) { delta = volume; } if (price < _lastPrice) { delta = -volume; } } } else if ((calcmode == GCDCalculationModeType.UpDownTickWithContinuation) || (calcmode == GCDCalculationModeType.UpDownOneTickWithContinuation) || ((calcmode == GCDCalculationModeType.BidAsk) && (backupmode == true))) { if (price > _lastPrice) //normal uptick/dn tick { direction = 1; } else if (price < _lastPrice) { direction = -1; } if (calcmode == GCDCalculationModeType.UpDownOneTickWithContinuation) { delta = direction; } else { delta = direction * volume; } } // added else if ((calcmode == GCDCalculationModeType.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 == GTickTypeEnum.AtBid) || (tickType == GTickTypeEnum.BelowBid); } else { _startLookingForReversal = (tickType == GTickTypeEnum.AtAsk) || (tickType == GTickTypeEnum.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 == GTickTypeEnum.AtAsk) || (tickType == GTickTypeEnum.BetweenBidAsk))) { direction = -1; } else if ((direction == -1) && _startLookingForReversal && ((tickType == GTickTypeEnum.AtBid) || (tickType == GTickTypeEnum.BetweenBidAsk))) { direction = 1; //buyers take control of ask } } delta = direction * volume; } _lastPrice = price; _lastDirection = direction; if ((filtermode == GFilterModeType.OnlyLargerThan) && (volume <= filtersize)) { delta = 0; } if ((filtermode == GFilterModeType.OnlySmallerThan) && (volume >= filtersize)) { delta = 0; } return(delta); }
protected int CalcDelta(GTickTypeEnum tickType, double price, int volume) { return(_CalcDelta(tickType, price, volume, _calcMode, _backupMode, _filterSize, _filterMode)); }