예제 #1
0
        /// <summary>
        /// Pubnubでデータ取得
        /// </summary>
        /// <param name="subscribeKey">受信用キー(ex:"sub-c-52a9ab50-291b-11e5-baaa-0619f8945a4f")</param>
        /// <param name="channel">チャンネル(ex:"lightning_ticker_FX_BTC_JPY")</param>
        /// <param name="useId">モード0:Ticker 1:約定</param>
        public PubnubManager(string subscribeKey, string channel, PubNubUse useId)
        {
            this.useId = useId;
            buyVol     = new List <RawExecute>();
            sellVol    = new List <RawExecute>();

            config = new PNConfiguration
            {
                SubscribeKey = subscribeKey // 受信用キー
            };
            this.channel = channel;
            pubnub       = new Pubnub(config);
            //config.PublishKey = "demo";   // 配信用キー

            // ろうそく初期化
            prevCandle = new Candle();
            candle     = new Candle();
        }
예제 #2
0
        /// <summary>
        /// MWebSocketテーブルの設定内容で初期化する
        /// PubNubなどに接続する
        /// </summary>
        public void InitializeWebSocket()
        {
            // 初期化
            PubnubList = InitializeDictionary(PubnubList);

            // パラメータ読み込み
            using (var db = new MWebSocketDbContext(DbContextOptions))
            {
                // データを取得
                var mWebSocket = db.MWebSocket;

                // PubNubのキーリスト作成
                var PubNubKeys = new Dictionary <int, string>();
                foreach (var item in mWebSocket)
                {
                    if (item.Enabled == Enabled)
                    {
                        if (item.CategoryId == (int)WebSocketCategory.PubNub)
                        {
                            if (item.UseId == (int)PubNubUse.Key)
                            {
                                PubNubKeys.Add(item.ExchangeId, item.Value);
                            }
                        }
                    }
                }

                // キーが見つかった取引所のPubNubを作成
                foreach (var item in mWebSocket)
                {
                    if (item.Enabled == Enabled)
                    {
                        if (item.CategoryId == (int)WebSocketCategory.PubNub)
                        {
                            // PubNubの場合、PubNubのリストに追加
                            // 取引所ID
                            int RecordId = item.ExchangeId;
                            if (PubNubKeys.ContainsKey(RecordId))
                            {
                                // 用途ID
                                PubNubUse useId = (PubNubUse)item.UseId;
                                if (useId != PubNubUse.Key)
                                {
                                    if (!PubnubList.ContainsKey(item.ExchangeId))
                                    {
                                        PubnubList.Add(item.ExchangeId, new Dictionary <int, PubnubManager>());
                                    }
                                    PubnubList[item.ExchangeId].Add(item.UseId, new PubnubManager(PubNubKeys[item.ExchangeId], item.Value, useId));
                                }
                            }
                        }
                    }
                }
            }


            foreach (var pubnub in PubnubList.Values)
            {
                foreach (var item in pubnub.Values)
                {
                    Logger.Log("PubNubを開始します:" + item.ToString());
                    item.Start();
                }
            }
        }