private static TickRecord CreateTickRecord2() { TickRecord r = CreateTickRecord1(); r.Zero3 = ((short)0); return(r); }
public void TestStore() { TickRecord record = new TickRecord(); record.MajorTickType = ((byte)2); record.MinorTickType = ((byte)0); record.LabelPosition = ((byte)3); record.Background = ((byte)1); record.LabelColorRgb = (0); record.Zero1 = ((short)0); record.Zero2 = ((short)0); record.Options = ((short)35); record.IsAutoTextColor = (true); record.IsAutoTextBackground = (true); record.Rotation = ((short)0); record.IsAutorotate = (true); record.TickColor = ((short)77); record.Zero3 = ((short)0); byte[] recordBytes = record.Serialize(); Assert.AreEqual(recordBytes.Length - 4, data.Length); for (int i = 0; i < data.Length; i++) { Assert.AreEqual(data[i], recordBytes[i + 4], "At offset " + i); } }
/// <summary> /// With a TickRecord Id == 0, will create a new TickRecord /// </summary> /// <param name="tickRecord"></param> public static void UpdateTickRecord(TickRecord tickRecord) { // Create a new connection using (var db = new SQLiteConnection(new SQLitePlatformWinRT(), DbPath)) { // Update db.Update(tickRecord); } }
/// <summary> /// With a TickRecord Id == 0, will create a new TickRecord /// </summary> /// <param name="tickRecord"></param> public static void AddTickRecord(TickRecord tickRecord) { // Create a new connection using (var db = new SQLiteConnection(new SQLitePlatformWinRT(), DbPath)) { // New db.Insert(tickRecord); } }
/// <summary> /// Retrieve a TickRecord by Id /// </summary> /// <param name="key">TickRecord Id</param> /// <returns>TickRecord</returns> public static TickRecord SearchTickRecordByKey(long key) { using (var db = new SQLiteConnection(new SQLitePlatformWinRT(), DbPath)) { TickRecord m = (from p in db.Table <TickRecord>() where p.Key == key select p).FirstOrDefault(); return(m); } }
public GetTickPricesResponse(string body) : base(body) { this.Ticks = new LinkedList <TickRecord>(); JSONArray arr = (JSONArray)this.ReturnData; foreach (JSONObject tickRecordJson in arr) { TickRecord record = new TickRecord(tickRecordJson); this.Ticks.AddLast(record); } }
public TickPricesResponse(string body) : base(body) { JSONObject ob = (JSONObject)this.ReturnData; JSONArray arr = (JSONArray)ob["quotations"]; foreach (JSONObject e in arr) { TickRecord record = new TickRecord(); record.FieldsFromJSONObject(e); ticks.AddLast(record); } }
/// <summary> /// Delete a TickRecord by id /// </summary> /// <param name="key"></param> public static void DeleteTickRecordById(long key) { using (var db = new SQLiteConnection(new SQLitePlatformWinRT(), DbPath)) { TickRecord m = (from p in db.Table <TickRecord>() where p.Key == key select p).FirstOrDefault(); if (m != null) { db.Delete(m); } } }
public override void Write(int flowID, IEnumerable <KeyValuePair <long, Tick> > flow) { using (bulkInsertSessions[flowID]) { foreach (var kv in flow) { TickRecord entity = new TickRecord(kv.Key, kv.Value); bulkInsertSessions[flowID].Store(entity); recordsCount++; } } }
public AXSAggregate(RecordStream rs, ChartRecordAggregate container) : base(RuleName_AXS, container) { if (rs.PeekNextChartSid() == IFmtRecordRecord.sid) { ifmt = (IFmtRecordRecord)rs.GetNext(); } if (rs.PeekNextChartSid() == TickRecord.sid) { tick = (TickRecord)rs.GetNext(); } if (rs.PeekNextChartSid() == FontXRecord.sid) { fontx = (FontXRecord)rs.GetNext(); } if (rs.PeekNextChartSid() == AxisLineRecord.sid) { while (rs.PeekNextChartSid() == AxisLineRecord.sid) { axisLines.Add((AxisLineRecord)rs.GetNext()); lineFormats.Add((LineFormatRecord)rs.GetNext()); } } if (rs.PeekNextChartSid() == AreaFormatRecord.sid) { areaFormat = (AreaFormatRecord)rs.GetNext(); } if (rs.PeekNextChartSid() == GelFrameRecord.sid) { gelFrame = new GelFrameAggregate(rs, this); } if (rs.PeekNextChartSid() == ShapePropsStreamRecord.sid) { while (rs.PeekNextChartSid() == ShapePropsStreamRecord.sid) { shapes.Add(new ShapePropsAggregate(rs, this)); } } if (rs.PeekNextChartSid() == TextPropsStreamRecord.sid) { textProps = (TextPropsStreamRecord)rs.GetNext(); while (rs.PeekNextChartSid() == ContinueFrt12Record.sid) { continues.Add((ContinueFrt12Record)rs.GetNext()); } } }
public override IEnumerable <KeyValuePair <long, STS.General.Generators.Tick> > Read() { foreach (var kv in clients[0].GetAllItemsFromSortedSet(sortedSet)) { TickRecord data = kv.Value; Tick tick = new Tick( data.Symbol, TickRecord.UnixTimestampToDateTime(data.UnixTime), data.Bid, data.Ask, data.BidSize, data.AskSize, data.Provider); yield return(new KeyValuePair <long, Tick>(kv.Key, tick)); } }
/// <summary> /// With a TickRecord Id == 0, will create a new TickRecord /// </summary> /// <param name="tickRecord"></param> public static void AddOrUpdateTickRecord(TickRecord tickRecord) { // Create a new connection using (var db = new SQLiteConnection(new SQLitePlatformWinRT(), DbPath)) { if (DoesRecordExist(tickRecord.Key) == false) { // New db.Insert(tickRecord); } else { // Update db.Update(tickRecord); } } }
public override void Write(int flowID, IEnumerable <KeyValuePair <long, STS.General.Generators.Tick> > flow) { RedisTypedClient <KeyValuePair <long, TickRecord> > client = clients[flowID]; foreach (var kv in flow) { var data = kv.Value; TickRecord tick = new TickRecord( data.Symbol, TickRecord.DateTimeToUnixTimestamp(data.Timestamp), data.Bid, data.Ask, data.BidSize, data.AskSize, data.Provider); client.AddItemToSortedSet(sortedSet, new KeyValuePair <long, TickRecord>(kv.Key, tick)); } }
public void Record(string tag) { TickRecord lsttick = TagStack.Pop(); TickRecord curtick = new TickRecord(tag); Int32 diff = Util.EnvironmentTickCountSubtract(curtick.Tick, lsttick.Tick); string path = lsttick.Tag + "==>" + curtick.Tag; if (!Stats.ContainsKey(path)) { Stats.Add(path, new StatRecord(diff)); } else { Stats[path].AddRecord(diff); } TagStack.Push(curtick); }
private static TickRecord CreateTickRecord1() { TickRecord r = new TickRecord(); r.MajorTickType = ((byte)2); r.MinorTickType = ((byte)0); r.LabelPosition = ((byte)3); r.Background = ((byte)1); r.LabelColorRgb = (0); r.Zero1 = ((short)0); r.Zero2 = ((short)0); r.Zero3 = ((short)45); r.IsAutorotate = (true); r.IsAutoTextBackground = (true); r.Rotation = ((short)0); r.IsAutorotate = (true); r.TickColor = ((short)77); return(r); }
public void TestLoad() { TickRecord record = new TickRecord(TestcaseRecordInputStream.Create(0x101e, data)); Assert.AreEqual((byte)2, record.MajorTickType); Assert.AreEqual((byte)0, record.MinorTickType); Assert.AreEqual((byte)3, record.LabelPosition); Assert.AreEqual((short)1, record.Background); Assert.AreEqual(0, record.LabelColorRgb); Assert.AreEqual((short)0, record.Zero1); Assert.AreEqual((short)0, record.Zero2); Assert.AreEqual((short)35, record.Options); Assert.AreEqual(true, record.IsAutoTextColor); Assert.AreEqual(true, record.IsAutoTextBackground); Assert.AreEqual((short)0x0, record.Rotation); Assert.AreEqual(true, record.IsAutorotate); Assert.AreEqual((short)77, record.TickColor); Assert.AreEqual((short)0x0, record.Zero3); Assert.AreEqual(34, record.RecordSize); }
public AXSAggregate(RecordStream rs, ChartRecordAggregate container) : base(RuleName_AXS, container) { if (rs.PeekNextChartSid() == IFmtRecordRecord.sid) ifmt = (IFmtRecordRecord)rs.GetNext(); if (rs.PeekNextChartSid() == TickRecord.sid) tick = (TickRecord)rs.GetNext(); if (rs.PeekNextChartSid() == FontXRecord.sid) fontx = (FontXRecord)rs.GetNext(); if (rs.PeekNextChartSid() == AxisLineRecord.sid) { while (rs.PeekNextChartSid() == AxisLineRecord.sid) { axisLines.Add((AxisLineRecord)rs.GetNext()); lineFormats.Add((LineFormatRecord)rs.GetNext()); } } if (rs.PeekNextChartSid() == AreaFormatRecord.sid) areaFormat = (AreaFormatRecord)rs.GetNext(); if (rs.PeekNextChartSid() == GelFrameRecord.sid) gelFrame = new GelFrameAggregate(rs, this); if (rs.PeekNextChartSid() == ShapePropsStreamRecord.sid) { while (rs.PeekNextChartSid() == ShapePropsStreamRecord.sid) { shapes.Add(new ShapePropsAggregate(rs,this)); } } if (rs.PeekNextChartSid() == TextPropsStreamRecord.sid) { textProps = (TextPropsStreamRecord)rs.GetNext(); while (rs.PeekNextChartSid() == ContinueFrt12Record.sid) { continues.Add((ContinueFrt12Record)rs.GetNext()); } } }
public void Record(string tag) { TickRecord lsttick = TagStack.Pop(); TickRecord curtick = new TickRecord(tag); Int32 diff = Util.EnvironmentTickCountSubtract(curtick.Tick,lsttick.Tick); string path = lsttick.Tag + "==>" + curtick.Tag; if (! Stats.ContainsKey(path)) Stats.Add(path,new StatRecord(diff)); else Stats[path].AddRecord(diff); TagStack.Push(curtick); }
/// <summary> /// Handler for streaming message. /// </summary> /// <param name="sender">Sender</param> /// <param name="args">Args</param> private void StreamingMessageHandler(object sender, IncomingMessageArgs args) { var message = args.Message.Parameters.GetString("update"); JSONObject responseBody = (JSONObject)JSONObject.Parse(message); string commandName = responseBody["command"].ToString(); if (RecordReceived != null) { RecordReceived.Invoke(message); } switch (commandName) { case "tickPrices": TickRecord tickRecord = new TickRecord((JSONObject)responseBody["data"]); if (TickPricesRecordReceived != null) { TickPricesRecordReceived.Invoke(tickRecord); } break; case "trade": StreamingTradeRecord tradeRecord = new StreamingTradeRecord((JSONObject)responseBody["data"]); if (TradeRecordReceived != null) { TradeRecordReceived.Invoke(tradeRecord); } break; case "indicators": IndicatorsRecord balanceRecord = new IndicatorsRecord((JSONObject)responseBody["data"]); if (AccountIndicatorsRecordReceived != null) { AccountIndicatorsRecordReceived.Invoke(balanceRecord); } break; case "orderStatus": OrderStatusRecord tradeStatusRecord = new OrderStatusRecord((JSONObject)responseBody["data"]); if (OrderStatusRecordReceived != null) { OrderStatusRecordReceived.Invoke(tradeStatusRecord); } break; case "profit": ProfitRecord profitRecord = new ProfitRecord((JSONObject)responseBody["data"]); if (ProfitRecordReceived != null) { ProfitRecordReceived.Invoke(profitRecord); } break; case "news": NewsRecord newsRecord = new NewsRecord((JSONObject)responseBody["data"]); if (NewsRecordReceived != null) { NewsRecordReceived.Invoke(newsRecord); } break; case "keepAlive": KeepAliveRecord keepAliveRecord = new KeepAliveRecord((JSONObject)responseBody["data"]); if (KeepAliveRecordReceived != null) { KeepAliveRecordReceived.Invoke(keepAliveRecord); } break; case "candle": StreamingCandleRecord candleRecord = new StreamingCandleRecord((JSONObject)responseBody["data"]); if (CandleRecordReceived != null) { CandleRecordReceived.Invoke(candleRecord); } break; case "error": StreamingErrorRecord streamingErrorRecord = new StreamingErrorRecord((JSONObject)responseBody["data"]); if (ErrorRecordReceived != null) { ErrorRecordReceived.Invoke(streamingErrorRecord); } break; default: throw new APICommunicationException("Unknown streaming record received"); } }
protected override void OnRender(DrawingContext drawingContext) { if (this.majorTickMarkInterval == 0) return; Rect r = new Rect(new Point(0, 0), new Size(this.ActualWidth, this.ActualHeight)); RectangleGeometry rg = new RectangleGeometry(r); drawingContext.PushClip(rg); drawingContext.DrawRectangle(Brushes.Transparent, null, r); drawingContext.DrawLine(axisPen, new Point(0, 0.5), new Point(this.ActualWidth, 0.5)); double totalTimeWidth = Math.Max((double)this.AbsoluteTimeEnd - (double)this.AbsoluteTimeStart, 1d); double visibleTimeWidth = (double)this.TotalVisibleTime; double visibleWidthPercent = visibleTimeWidth / totalTimeWidth; double visiblePixelWidth = Math.Max(this.ActualWidth * visibleWidthPercent, 10); double marginTimeWidth = (double)this.VisibleTimeStart; double marginWidthPercent = marginTimeWidth / totalTimeWidth; double marginPixelWidth = this.ActualWidth * marginWidthPercent; double minorTickPixelWidth = this.minorTickMarkInterval * (this.ActualWidth / (double)this.TotalVisibleTime); double majorTickPixelWidth = minorTickPixelWidth * 10; drawingContext.DrawLine(visibleWindowPen, new Point(marginPixelWidth, 2), new Point(marginPixelWidth + visiblePixelWidth, 2)); List<TickRecord> ticks = new List<TickRecord>(); ulong nextMajorTickTime = this.firstVisibleMajorTickMark; bool labelWiderThanMinorTick = false; bool labelWiderThanHalfMajorTick = false; int minorTicksSinceLastMajorTick = 0; int absoluteTickIndex = -1; int firstMajorTickIndex = -1; bool makeFirstVisibleTickAbsolute = (this.ActualWidth / majorTickPixelWidth) < 2.5; ulong absoluteTickTime = makeFirstVisibleTickAbsolute ? this.firstVisibleMinorTickMark : this.firstVisibleMajorTickMark; // Create tick records for (ulong x = firstVisibleMinorTickMark; x < this.lastVisibleMajorTickMark; x += minorTickMarkInterval) { double tx = Math.Floor(TimeToScreen(x)) + 0.5; if (tx >= 0) { bool isAbsoluteTimeTick = makeFirstVisibleTickAbsolute ? (ticks.Count == 0) : (x == this.firstVisibleMajorTickMark); bool isMajor = (x == nextMajorTickTime); double interval = (double)this.minorTickMarkInterval; // (To make major ticks change units on their own schedule, use majorTickMarkInterval here) string text = isAbsoluteTimeTick ? CreateAbsoluteTimeLabel(x) : CreateRelativeTimeLabel((double)x - (double)absoluteTickTime, interval); FormattedText label = new FormattedText(text, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, isAbsoluteTimeTick ? this.absoluteTimeTypeface : this.relativeTimeTypeface, this.AxisFontSize, this.Foreground); var newTick = new TickRecord { IsMajor = isMajor, IsAbsolute = isAbsoluteTimeTick, Position = tx, Value = x, Label = label }; if (isAbsoluteTimeTick) { absoluteTickIndex = ticks.Count; } if (isMajor && (firstMajorTickIndex == -1)) { firstMajorTickIndex = ticks.Count; } ticks.Add(newTick); if (isMajor) { nextMajorTickTime += majorTickMarkInterval; minorTicksSinceLastMajorTick = 0; } if (!newTick.IsAbsolute) { if ((newTick.Label.Width + tickLabelTrailingSpace) > minorTickPixelWidth) { labelWiderThanMinorTick = true; } if ((minorTicksSinceLastMajorTick == 0 || minorTicksSinceLastMajorTick == 5) && ((newTick.Label.Width + tickLabelTrailingSpace) > (minorTickPixelWidth * 5))) { labelWiderThanHalfMajorTick = true; } } } } // If we're squeezed small enough, we may have no ticks at all. Oh well. if (ticks.Count > 0) { Debug.Assert(absoluteTickIndex >= 0); // By default we're in "every-minor" label mode -- all ticks get labels. // If any label is wider than a minor tick, then we drop to "every-fifth-minor" mode. // If any label is wider than half a major tick, then we drop all the way to "every-major" mode. // Depending on our labeling mode, cull out unneeded/unwanted labels. // First, take care of any ticks prior to the absolute tick. for (int i = absoluteTickIndex - 1; i >= 0; i--) { if (labelWiderThanHalfMajorTick || (labelWiderThanMinorTick && (i != absoluteTickIndex - 5))) { // Culled because we're in every-fifth-minor or every-major label mode. ticks[i].Label = null; } } // And now the rest. int minorTickIndex = (absoluteTickIndex > 0) ? 0 : 10 - firstMajorTickIndex; double endOfAbsoluteText = ticks[absoluteTickIndex].Label.Width + ticks[absoluteTickIndex].Position + tickLabelTrailingSpace; for (int i = absoluteTickIndex; i < ticks.Count; i++, minorTickIndex++) { if (i != absoluteTickIndex && ticks[i].Position < endOfAbsoluteText) { // Remove this label because it overlaps the absolute time. Need to special case this so // the absolute time doesn't throw all the others into every-fifth-minor or every-major label mode. ticks[i].Label = null; } else if (i != absoluteTickIndex && !ticks[i].IsMajor && (labelWiderThanHalfMajorTick || (labelWiderThanMinorTick && (minorTickIndex != 5)))) { // Not the absolute tick, and not a major tick, culled because we're in every-fifth-minor or every-major label mode. ticks[i].Label = null; } if (ticks[i].IsMajor) { minorTickIndex = 0; } } } // Draw ticks and labels foreach (var record in ticks) { if (record.Label != null) { drawingContext.DrawLine(axisPen, new Point(record.Position, 0), new Point(record.Position, majorTickHeight)); drawingContext.DrawText(record.Label, new Point(record.Position, this.tickGutterHeight)); } else { drawingContext.DrawLine(axisPen, new Point(record.Position, 0), new Point(record.Position, minorTickHeight)); } } drawingContext.Pop(); // pop clip if (this.MouseOverElement != null && this.MouseOverElement.IsMouseOver) { PathGeometry clipGeometry = null; var timeline = this.MouseOverElement as Timeline; if (timeline != null && timeline.ClipSpans != null && timeline.ClipSpans.Count != 0) { double top = 0; PathFigure figure; clipGeometry = new PathGeometry(); foreach (var clip in timeline.ClipSpans) { figure = new PathFigure { IsClosed = true, StartPoint = new Point(0, top) }; figure.Segments.Add(new LineSegment(new Point(0, clip.Top), false)); figure.Segments.Add(new LineSegment(new Point(this.ActualWidth, clip.Top), false)); figure.Segments.Add(new LineSegment(new Point(this.ActualWidth, top), false)); figure.Segments.Add(new LineSegment(new Point(0, top), false)); top = clip.Top + clip.Height; clipGeometry.Figures.Add(figure); } if (top < this.MouseOverElement.ActualHeight) { figure = new PathFigure { IsClosed = true, StartPoint = new Point(0, top) }; figure.Segments.Add(new LineSegment(new Point(0, this.MouseOverElement.ActualHeight), false)); figure.Segments.Add(new LineSegment(new Point(this.ActualWidth, this.MouseOverElement.ActualHeight), false)); figure.Segments.Add(new LineSegment(new Point(this.ActualWidth, top), false)); figure.Segments.Add(new LineSegment(new Point(0, top), false)); clipGeometry.Figures.Add(figure); } drawingContext.PushClip(clipGeometry); } int pixelX = (int)Mouse.GetPosition(this).X; int pixelY = (int)Mouse.GetPosition(this).Y; string timeString = CreateAbsoluteTimeLabel((double)this.PixelToTime(pixelX)); FormattedText timeText = new FormattedText(timeString, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, this.relativeTimeTypeface, this.AxisFontSize, this.MousePointBrush); double rectHeight = Math.Ceiling(timeText.Height); drawingContext.DrawRectangle(this.Background, this.mousePointPen, new Rect(pixelX + 0.5, pixelY + 0.5 - rectHeight, Math.Ceiling(timeText.Width) + 6, Math.Ceiling(timeText.Height))); drawingContext.DrawText(timeText, new Point(pixelX + 3, pixelY - rectHeight + 0.5)); drawingContext.DrawLine(this.mousePointPen, new Point(pixelX + 0.5, 0), new Point(pixelX + 0.5, this.MouseOverElement.ActualHeight)); if (clipGeometry != null) { drawingContext.Pop(); } } base.OnRender(drawingContext); }