void UpdateEvents(System.Collections.Specialized.NotifyCollectionChangedEventArgs e) { Series s = this.chartControl1.Series["Events"]; s.Points.BeginUpdate(); this.chartControl1.Annotations.BeginUpdate(); s.Points.Clear(); this.chartControl1.Annotations.Clear(); try { ResizeableArray <CandleStickData> cd = Ticker.CandleStickData; DateTime endTime = cd.Count == 0 ? DateTime.MinValue : cd.Last().Time; DateTime startTime = cd.Count == 0 ? DateTime.MaxValue : cd.First().Time; for (int i = 0; i < Ticker.Events.Count; i++) { TickerEvent ev = Ticker.Events[i]; if (ev.Time <= endTime && ev.Time >= startTime) { SeriesPoint sp = CreateEventPoint(Ticker.Events[i]); s.Points.Add(sp); CreateAnnotation(sp); } } } finally { s.Points.EndUpdate(); this.chartControl1.Annotations.EndUpdate(); } }
private void HandleTickerItem(object sender, MessageData item) { var data = JsonSerializer.Deserialize <Ticker>(item.Data); Debug.WriteLine(JsonSerializer.ToJsonString(data)); TickerEvent?.Invoke(sender, data); }
private void chartControl1_MouseClick(object sender, MouseEventArgs e) { if (e.Button != MouseButtons.Right) { return; } ChartHitInfo info = this.chartControl1.CalcHitInfo(e.Location); Series evSeries = (Series)info.HitObjects.FirstOrDefault(s => s is Series && ((Series)s).Name == "Events"); Series crSeries = (Series)info.HitObjects.FirstOrDefault(s => s is Series && ((Series)s).Name == "Current"); DiagramCoordinates coor = ((XYDiagram)this.chartControl1.Diagram).PointToDiagram(info.HitPoint); Time = coor.DateTimeArgument; SelectedEvent = null; if (info.InSeriesPoint) { SelectedEvent = info.SeriesPoint.Tag as TickerEvent; } this.biRemoveEvent.Visibility = SelectedEvent == null ? BarItemVisibility.Never : BarItemVisibility.Always; this.biEditEvent.Visibility = SelectedEvent == null ? BarItemVisibility.Never : BarItemVisibility.Always; this.pmChartMenu.ShowPopup(Control.MousePosition); }
private void CreateAnnotation(SeriesPoint sp) { TickerEvent ev = (TickerEvent)sp.Tag; TextAnnotation ta = this.chartControl1.Annotations.AddTextAnnotation("Event" + ev.Time.Ticks, ev.Text); ta.AnchorPoint = new SeriesPointAnchorPoint(sp); ta.ShapePosition = new RelativePosition(90, 100); }
protected SeriesPoint CreateEventPoint(TickerEvent ev) { SeriesPoint pt = new SeriesPoint(ev.Time, ev.Current); pt.ToolTipHint = ev.Text; pt.Tag = ev; pt.Color = ev.Color; return(pt); }
private void processMessage(byte[] receivedData) { using (MemoryStream responseStream = new MemoryStream(receivedData)) { protobuf.ws.WsResponse response = ProtoBuf.Serializer.Deserialize <protobuf.ws.WsResponse>(responseStream); if (response.Meta.ResponseType == protobuf.ws.WsResponseMetaData.WsResponseMsgType.TickerChannelSubscribed) { using (MemoryStream messageStream = new MemoryStream(response.Msg)) { protobuf.ws.TickerChannelSubscribedResponse message = ProtoBuf.Serializer.Deserialize <protobuf.ws.TickerChannelSubscribedResponse>(messageStream); string channelId = "Ticker_" + message.CurrencyPair; WsClient_OnSubscribe(channelId); message.Datas.ForEach(delegate(protobuf.ws.TickerEvent evt) { TickerEvent preparedEvent = prepareTickerEvent(evt); preparedEvent.ChannelId = "Ticker_" + message.CurrencyPair; WsClient_OnTicker(preparedEvent); }); } } else if (response.Meta.ResponseType == protobuf.ws.WsResponseMetaData.WsResponseMsgType.TickerNotify) { using (MemoryStream messageStream = new MemoryStream(response.Msg)) { protobuf.ws.TickerNotification message = ProtoBuf.Serializer.Deserialize <protobuf.ws.TickerNotification>(messageStream); string channelId = "Ticker_" + message.CurrencyPair; message.Datas.ForEach(delegate(protobuf.ws.TickerEvent evt) { TickerEvent preparedEvent = prepareTickerEvent(evt); preparedEvent.ChannelId = "Ticker_" + message.CurrencyPair; WsClient_OnTicker(preparedEvent); }); } } else if (response.Meta.ResponseType == protobuf.ws.WsResponseMetaData.WsResponseMsgType.Error) { using (MemoryStream messageStream = new MemoryStream(response.Msg)) { protobuf.ws.ErrorResponse message = ProtoBuf.Serializer.Deserialize <protobuf.ws.ErrorResponse>(messageStream); WsClient_OnError(message.Code, message.Message); } } else if (response.Meta.ResponseType == protobuf.ws.WsResponseMetaData.WsResponseMsgType.ChannelUnsubscribed) { using (MemoryStream messageStream = new MemoryStream(response.Msg)) { protobuf.ws.ChannelUnsubscribedResponse message = ProtoBuf.Serializer.Deserialize <protobuf.ws.ChannelUnsubscribedResponse>(messageStream); if (message.Type == protobuf.ws.UnsubscribeRequest.ChannelType.Ticker) { WsClient_OnUnsubscribe("Ticker_" + message.CurrencyPair); } } } else if (response.Meta.ResponseType == protobuf.ws.WsResponseMetaData.WsResponseMsgType.LoginResponse) { WsClient_OnLogin(); } } }
private void biAddEvent_ItemClick(object sender, ItemClickEventArgs e) { TickerEvent ev = new TickerEvent(); ev.Time = Time; EventEditForm form = new EventEditForm(); form.Event = ev; if (form.ShowDialog() != DialogResult.OK) { return; } ev.Current = Ticker.GetCurrent(ev.Time); Ticker.Events.Add(ev); }
protected void RaiseEventDoubleClick() { TickerEvent ev = (TickerEvent)this.gvEvents.GetFocusedRow(); if (ev == null) { return; } TickerEventHandler handler = (TickerEventHandler)Events[eventDoubleClick]; if (handler != null) { handler(this, new TickerEventArgs(ev)); } }
// parsing events private TickerEvent prepareTickerEvent(protobuf.ws.TickerEvent evt) { TickerEvent ticker = new TickerEvent(); ticker.Last = parseDecimal(evt.Last); ticker.High = parseDecimal(evt.High); ticker.Low = parseDecimal(evt.Low); ticker.Volume = parseDecimal(evt.Volume); ticker.Vwap = parseDecimal(evt.Vwap); ticker.MaxBid = parseDecimal(evt.MaxBid); ticker.MinAsk = parseDecimal(evt.MinAsk); ticker.BestBid = parseDecimal(evt.BestBid); ticker.BestAsk = parseDecimal(evt.BestAsk); return(ticker); }
private void biEditEvent_ItemClick(object sender, ItemClickEventArgs e) { if (Ticker == null) { return; } TickerEvent ev = SelectedEvent.Clone(); EventEditForm form = new EventEditForm(); form.Event = ev; if (form.ShowDialog() != DialogResult.OK) { return; } SelectedEvent.Assign(ev); Ticker.OnEventsChanged(); }
private async Task Receive(ClientWebSocket webSocket) { byte[] buffer = new byte[receiveChunkSize]; while (webSocket.State == WebSocketState.Open) { var result = await webSocket.ReceiveAsync(new ArraySegment <byte>(buffer), CancellationToken.None); if (result.MessageType == WebSocketMessageType.Close) { await webSocket.CloseAsync(WebSocketCloseStatus.NormalClosure, string.Empty, CancellationToken.None); } else { //LogStatus(true, buffer, result.Count); TickerEvent?.Invoke(buffer); } } }
private void biRemove_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { if (Ticker == null) { return; } TickerEvent focused = (TickerEvent)this.gvEvents.GetFocusedRow(); if (focused == null) { return; } if (XtraMessageBox.Show("Do you really want to remove event?", "Delete", MessageBoxButtons.YesNoCancel) != DialogResult.Yes) { return; } Ticker.Events.Remove(focused); }
public static TickerEvent Serdes(TickerEvent e, AssetMapping mapping, ISerializer s) { if (s == null) { throw new ArgumentNullException(nameof(s)); } e ??= new TickerEvent(); e.Operation = s.EnumU8(nameof(Operation), e.Operation); e.Amount = s.UInt8(nameof(Amount), e.Amount); e.Unk4 = s.UInt8(nameof(Unk4), e.Unk4); int zeroed = s.UInt8(null, 0); e.TickerId = TickerId.SerdesU16(nameof(TickerId), e.TickerId, mapping, s); zeroed += s.UInt16(null, 0); ApiUtil.Assert(e.Unk4 is 0 or 1); s.Assert(zeroed == 0, "TickerEvent: Expected fields 5, 8 to be 0"); return(e); }
private void biAdd_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { if (Ticker == null) { return; } TickerEvent ev = new TickerEvent(); ev.Time = DateTime.UtcNow; EventEditForm form = new EventEditForm(); form.Event = ev; if (form.ShowDialog() != DialogResult.OK) { return; } ev.Current = Ticker.GetCurrent(ev.Time); Ticker.Events.Add(ev); }
private void biEdit_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { if (Ticker == null) { return; } TickerEvent focused = (TickerEvent)this.gvEvents.GetFocusedRow(); if (focused == null) { return; } TickerEvent ev = focused.Clone(); EventEditForm form = new EventEditForm(); form.Event = ev; if (form.ShowDialog() != DialogResult.OK) { return; } focused.Assign(ev); Ticker.OnEventsChanged(); }
public static ModifyEvent BaseSerdes(ModifyEvent genericEvent, AssetMapping mapping, AssetId eventSource, ISerializer s) { if (s == null) { throw new ArgumentNullException(nameof(s)); } var subType = s.EnumU8("SubType", genericEvent?.SubType ?? ModifyType.Unk2); return(subType switch { ModifyType.Switch => SwitchEvent.Serdes((SwitchEvent)genericEvent, mapping, s), // 0 ModifyType.DisableEventChain => DisableEventChainEvent.Serdes((DisableEventChainEvent)genericEvent, eventSource, s), // 1 ModifyType.Unk2 => ModifyUnk2Event.Serdes((ModifyUnk2Event)genericEvent, s), // 2 ModifyType.NpcActive => DisableNpcEvent.Serdes((DisableNpcEvent)genericEvent, s), // 4 ModifyType.AddPartyMember => AddPartyMemberEvent.Serdes((AddPartyMemberEvent)genericEvent, mapping, s), // 5 ModifyType.InventoryItem => AddRemoveInventoryItemEvent.Serdes((AddRemoveInventoryItemEvent)genericEvent, mapping, s), // 6 ModifyType.MapLighting => SetMapLightingEvent.Serdes((SetMapLightingEvent)genericEvent, s), // B ModifyType.PartyGold => ChangePartyGoldEvent.Serdes((ChangePartyGoldEvent)genericEvent, s), // F ModifyType.PartyRations => ChangePartyRationsEvent.Serdes((ChangePartyRationsEvent)genericEvent, s), // 10 ModifyType.Time => ChangeTimeEvent.Serdes((ChangeTimeEvent)genericEvent, s), // 12 ModifyType.Leader => SetPartyLeaderEvent.Serdes((SetPartyLeaderEvent)genericEvent, mapping, s), // 1A ModifyType.Ticker => TickerEvent.Serdes((TickerEvent)genericEvent, mapping, s), // 1C _ => throw new InvalidEnumArgumentException(nameof(subType), (int)subType, typeof(ModifyType)) });
private void HandleTickerItem(object sender, MessageData item) { var data = JsonSerializer.Deserialize <Ticker>(item.Data); TickerEvent?.Invoke(sender, data); }
private void processMessage(byte[] receivedData) { // parsing response using (MemoryStream responseStream = new MemoryStream(receivedData)) { protobuf.ws.WsResponse response = ProtoBuf.Serializer.Deserialize <protobuf.ws.WsResponse>(responseStream); if (response.Meta.ResponseType == protobuf.ws.WsResponseMetaData.WsResponseMsgType.TickerChannelSubscribed) { using (MemoryStream messageStream = new MemoryStream(response.Msg)) { protobuf.ws.TickerChannelSubscribedResponse message = ProtoBuf.Serializer.Deserialize <protobuf.ws.TickerChannelSubscribedResponse>(messageStream); string channelId = "Ticker_" + message.CurrencyPair; WsClient_OnSubscribe(channelId); message.Datas.ForEach(delegate(protobuf.ws.TickerEvent evt) { TickerEvent preparedEvent = prepareTickerEvent(evt); preparedEvent.ChannelId = channelId; WsClient_OnTicker(preparedEvent); }); } } else if (response.Meta.ResponseType == protobuf.ws.WsResponseMetaData.WsResponseMsgType.TickerNotify) { using (MemoryStream messageStream = new MemoryStream(response.Msg)) { protobuf.ws.TickerNotification message = ProtoBuf.Serializer.Deserialize <protobuf.ws.TickerNotification>(messageStream); string channelId = "Ticker_" + message.CurrencyPair; message.Datas.ForEach(delegate(protobuf.ws.TickerEvent evt) { TickerEvent preparedEvent = prepareTickerEvent(evt); preparedEvent.ChannelId = channelId; WsClient_OnTicker(preparedEvent); }); } } if (response.Meta.ResponseType == protobuf.ws.WsResponseMetaData.WsResponseMsgType.TradeChannelSubscribed) { using (MemoryStream messageStream = new MemoryStream(response.Msg)) { protobuf.ws.TradeChannelSubscribedResponse message = ProtoBuf.Serializer.Deserialize <protobuf.ws.TradeChannelSubscribedResponse>(messageStream); string channelId = "Trade_" + message.CurrencyPair; WsClient_OnSubscribe(channelId); message.Datas.ForEach(delegate(protobuf.ws.TradeEvent evt) { TradeEvent preparedEvent = prepareTradeEvent(evt); preparedEvent.ChannelId = channelId; WsClient_OnTrade(preparedEvent); }); } } else if (response.Meta.ResponseType == protobuf.ws.WsResponseMetaData.WsResponseMsgType.TradeNotify) { using (MemoryStream messageStream = new MemoryStream(response.Msg)) { protobuf.ws.TradeNotification message = ProtoBuf.Serializer.Deserialize <protobuf.ws.TradeNotification>(messageStream); string channelId = "Trade_" + message.CurrencyPair; message.Datas.ForEach(delegate(protobuf.ws.TradeEvent evt) { TradeEvent preparedEvent = prepareTradeEvent(evt); preparedEvent.ChannelId = channelId; WsClient_OnTrade(preparedEvent); }); } } else if (response.Meta.ResponseType == protobuf.ws.WsResponseMetaData.WsResponseMsgType.Error) { using (MemoryStream messageStream = new MemoryStream(response.Msg)) { protobuf.ws.ErrorResponse message = ProtoBuf.Serializer.Deserialize <protobuf.ws.ErrorResponse>(messageStream); WsClient_OnError(response.Meta.Token, message.Code, message.Message); } } else if (response.Meta.ResponseType == protobuf.ws.WsResponseMetaData.WsResponseMsgType.ChannelUnsubscribed) { using (MemoryStream messageStream = new MemoryStream(response.Msg)) { protobuf.ws.ChannelUnsubscribedResponse message = ProtoBuf.Serializer.Deserialize <protobuf.ws.ChannelUnsubscribedResponse>(messageStream); if (message.Type == protobuf.ws.UnsubscribeRequest.ChannelType.Ticker) { WsClient_OnUnsubscribe("Ticker_" + message.CurrencyPair); } else if (message.Type == protobuf.ws.UnsubscribeRequest.ChannelType.Trade) { WsClient_OnUnsubscribe("Trade_" + message.CurrencyPair); } } } else if (response.Meta.ResponseType == protobuf.ws.WsResponseMetaData.WsResponseMsgType.LoginResponse) { WsClient_OnLogin(); } else if (response.Meta.ResponseType == protobuf.ws.WsResponseMetaData.WsResponseMsgType.PrivateTradeChannelSubscribed) { Console.WriteLine("Private Trades channel subscribed!"); using (MemoryStream messageStream = new MemoryStream(response.Msg)) { protobuf.ws.PrivateTradeChannelSubscribedResponse message = ProtoBuf.Serializer.Deserialize <protobuf.ws.PrivateTradeChannelSubscribedResponse>(messageStream); message.Datas.ForEach(delegate(protobuf.ws.PrivateTradeEvent evt) { performPrivateTradeEvent(evt); }); } } else if (response.Meta.ResponseType == protobuf.ws.WsResponseMetaData.WsResponseMsgType.PrivateTradeNotify) { using (MemoryStream messageStream = new MemoryStream(response.Msg)) { Console.WriteLine("Private Trades notification!"); Console.WriteLine(ByteArrayToString(response.Msg)); protobuf.ws.PrivateTradeNotification message = ProtoBuf.Serializer.Deserialize <protobuf.ws.PrivateTradeNotification>(messageStream); message.Datas.ForEach(delegate(protobuf.ws.PrivateTradeEvent evt) { performPrivateTradeEvent(evt); }); } } // here you can make your trade decision } }
private void WsClient_OnTicker(TickerEvent tickerEvent) { Console.WriteLine(tickerEvent); //here you can make your trade decision }
public TickerEventArgs(TickerEvent ev) { Event = ev; }