예제 #1
0
        /// <summary>
        /// Creates websocket message subscriptions for the supplied symbols
        /// </summary>
        public override void Subscribe(IEnumerable <Symbol> symbols)
        {
            foreach (var item in symbols)
            {
                if (item.Value.Contains("UNIVERSE") ||
                    item.SecurityType != SecurityType.Forex && item.SecurityType != SecurityType.Crypto)
                {
                    continue;
                }

                if (!IsSubscribeAvailable(item))
                {
                    //todo: refactor this outside brokerage
                    //alternative service: http://openexchangerates.org/latest.json
                    PollTick(item);
                }
                else
                {
                    this.ChannelList[item.Value] = new Channel {
                        Name = item.Value, Symbol = item.Value
                    };
                }
            }

            var products = ChannelList.Select(s => s.Value.Symbol.Substring(0, 3) + "-" + s.Value.Symbol.Substring(3)).ToArray();

            var payload = new
            {
                type        = "subscribe",
                product_ids = products,
                channels    = ChannelNames
            };

            if (payload.product_ids.Length == 0)
            {
                return;
            }

            var token = GetAuthenticationToken(JsonConvert.SerializeObject(payload), "GET", "/users/self/verify");

            var json = JsonConvert.SerializeObject(new
            {
                type        = payload.type,
                channels    = payload.channels,
                product_ids = payload.product_ids,
                SignHeader  = token.Signature,
                KeyHeader   = ApiKey,
                PassHeader  = _passPhrase,
                TimeHeader  = token.Timestamp
            });

            WebSocket.Send(json);


            OnMessage(new BrokerageMessageEvent(BrokerageMessageType.Information, -1, "GDAXBrokerage.Subscribe: Sent subscribe."));
        }
        /// <summary>
        /// Gets a list of current subscriptions
        /// </summary>
        /// <returns></returns>
        protected override IList <Symbol> GetSubscribed()
        {
            IList <Symbol> list = new List <Symbol>();

            lock (ChannelList)
            {
                foreach (var ticker in ChannelList.Select(x => x.Value.Symbol).Distinct())
                {
                    list.Add(_symbolMapper.GetLeanSymbol(ticker));
                }
            }
            return(list);
        }
예제 #3
0
        private void ipc_MessageReceived(IPC.IPCMessage.IIPCMessage message)
        {
            IPC.IPCMessage.ChannelListIPCMessage    chlistmsg = message as IPC.IPCMessage.ChannelListIPCMessage;
            IPC.IPCMessage.CurrentChannelIPCMessage curchmsg  = message as IPC.IPCMessage.CurrentChannelIPCMessage;
            IPC.IPCMessage.TimeIPCMessage           timemsg   = message as IPC.IPCMessage.TimeIPCMessage;

            if (chlistmsg != null)
            {
                //選択できるチャンネルリストを伝えるメッセージ
                channelList.Clear();
                channelList.AddRange(chlistmsg.ChannelList);
            }
            else if (curchmsg != null)
            {
                //現在のチャンネル・番組情報を伝えるメッセージ
                //NID,TSID,SIDがすべて同じならチャンネルは同じで変わってないと判定する
                if (this.currentChannel.Value == null || (this.currentChannel.Value.NetworkId != curchmsg.Channel.NetworkId ||
                                                          this.currentChannel.Value.TransportStreamId != curchmsg.Channel.TransportStreamId || this.currentChannel.Value.ServiceId != curchmsg.Channel.ServiceId))
                {
                    this.currentChannel.Value = curchmsg.Channel;
                }

                var currentChannel = ChannelList.Select((ch, idx) => new { Channel = ch, Index = idx }).FirstOrDefault((x) =>
                                                                                                                       curchmsg.Channel.NetworkId == x.Channel.NetworkId && curchmsg.Channel.TransportStreamId == x.Channel.TransportStreamId &&
                                                                                                                       curchmsg.Channel.ServiceId == x.Channel.ServiceId);

                //チャンネルリスト内に同じチャンネルがあればそれを今回のメッセージで得たインスタンスに置き換える
                if (currentChannel != null)
                {
                    this.channelList[currentChannel.Index] = this.currentChannel.Value;
                }

                this.currentEvent.Value = curchmsg.Event;
            }
            else if (timemsg != null)
            {
                //TOTを伝えるメッセージ
                //精度は1秒単位で値が変わるごとに来る
                currentTime.Value = timemsg.Time;
            }
        }
예제 #4
0
        /// <summary>
        /// Creates websocket message subscriptions for the supplied symbols
        /// </summary>
        /// <param name="job"></param>
        /// <param name="symbols"></param>
        public override void Subscribe(LiveNodePacket job, IEnumerable <Symbol> symbols)
        {
            foreach (var item in symbols)
            {
                if (item.Value.Contains("UNIVERSE"))
                {
                    continue;
                }

                if (!IsSubscribeAvailable(item))
                {
                    //todo: refactor this outside brokerage
                    //alternative service: http://openexchangerates.org/latest.json
                    PollTick(item);
                }
                else
                {
                    this.ChannelList[item.Value] = new Channel {
                        Name = item.Value, Symbol = item.Value
                    };

                    //emit baseline tick
                    var message = GetTick(item);

                    lock (_tickLocker)
                    {
                        Tick updating = new Tick
                        {
                            AskPrice = message.AskPrice,
                            BidPrice = message.BidPrice,
                            Value    = (message.AskPrice + message.BidPrice) / 2m,
                            Time     = DateTime.UtcNow,
                            Symbol   = item,
                            TickType = TickType.Quote
                                       //todo: tick volume
                        };

                        this.Ticks.Add(updating);
                    }
                }
            }

            var products = ChannelList.Select(s => s.Value.Symbol.Substring(0, 3) + "-" + s.Value.Symbol.Substring(3)).ToArray();

            var payload = new
            {
                type        = "subscribe",
                product_ids = products,
                channels    = _channelNames
            };

            if (payload.product_ids.Length == 0)
            {
                return;
            }

            var token = GetAuthenticationToken(JsonConvert.SerializeObject(payload), "GET", "/users/self/verify");

            var json = JsonConvert.SerializeObject(new
            {
                type        = payload.type,
                channels    = payload.channels,
                product_ids = payload.product_ids,
                SignHeader  = token.Signature,
                KeyHeader   = ApiKey,
                PassHeader  = _passPhrase,
                TimeHeader  = token.Timestamp
            });

            WebSocket.Send(json);


            OnMessage(new BrokerageMessageEvent(BrokerageMessageType.Information, -1, "GDAXBrokerage.Subscribe: Sent subcribe."));
        }
예제 #5
0
 private void SyncChannelList(object sender, NotifyCollectionChangedEventArgs e)
 {
     _container.Values[channelCollectionKey] = String.Join(splitChar.ToString(), ChannelList.Select(ch => ch.UniqueId));
 }