// 今は1取引所なので全部取る。 public Ticker(RawTicker _ticker) { ProductCode = _ticker.ProductCode; TimeStamp = _ticker.TimeStamp; TickId = _ticker.TickId; BestBid = _ticker.BestBid; BestBidSize = _ticker.BestBidSize; BestAsk = _ticker.BestAsk; BestAskSize = _ticker.BestAskSize; TotalBidDepth = _ticker.TotalBidDepth; TotalAskDepth = _ticker.TotalAskDepth; Itp = _ticker.Itp; Volume = _ticker.Volume; VolumeByProduct = _ticker.VolumeByProduct; }
public virtual async Task <Ticker> GetTicker() { // リクエスト送信 string json = await m_apiClient.Get(ticker); // 応答パース try { RawTicker _ticker = JsonConvert.DeserializeObject <RawTicker>(json); return(new Ticker(_ticker)); } catch (Exception ex) { throw new Exception("GetTickerError: " + ex.Message); } }
/// <summary> /// pubnubの受信を開始する /// </summary> public void Start() { pubnub.AddListener(new SubscribeCallbackExt( (pubnubObj, message) => { // 何かメッセージがあったら? if (message != null) { if (message.Channel != null) { // Message has been received on channel group stored in //Console.WriteLine(message.Channel); //Console.WriteLine(message.Message); string json = message.Message.ToString(); if (json != "") { switch (useId) { case PubNubUse.Ticker: // RowTickerにする latestRawTicker = JsonConvert.DeserializeObject <RawTicker>(json); latestTicker = new Ticker(latestRawTicker); // ろうそく更新 candle.UpdateByTicker(latestTicker); break; case PubNubUse.Execution: // RawExecuteにする var tempExecute = JsonConvert.DeserializeObject <List <RawExecute> >(json); foreach (var item in tempExecute) { item.parseDate(); if (item.Side == "BUY") { buyVol.Add(item); } else if (item.Side == "SELL") { sellVol.Add(item); } } break; } // PubNub止まってません restartCount = 1; } } else { // Message has been received on channel stored in Logger.Log(message.Subscription); } } }, (pubnubObj, presence) => { }, (pubnubObj, status) => { if (status.Category == PNStatusCategory.PNUnexpectedDisconnectCategory) { // This event happens when radio / connectivity is lost Logger.Log("PNUnexpectedDisconnectCategory"); } else if (status.Category == PNStatusCategory.PNConnectedCategory) { Logger.Log("PNConnectedCategory"); // Connect event. You can do stuff like publish, and know you'll get it. // Or just use the connected event to confirm you are subscribed for // UI / internal notifications, etc #region 発信用(不使用) //pubnub.Publish() // .Channel("awesomeChannel") // .Message("hello!!") // .Async(new PNPublishResultExt((publishResult, publishStatus) => // { // // Check whether request successfully completed or not. // if (!publishStatus.Error) // { // Console.WriteLine("Message successfully published to specified channel."); // } // else // { // Console.WriteLine("Request processing failed."); // // Handle message publish error. Check 'Category' property to find out possible issue // // because of which request did fail. // } // })); #endregion } else if (status.Category == PNStatusCategory.PNReconnectedCategory) { Logger.Log("PNReconnectedCategory"); // Happens as part of our regular operation. This event happens when // radio / connectivity is lost, then regained. } else if (status.Category == PNStatusCategory.PNDecryptionErrorCategory) { Logger.Log("PNDecryptionErrorCategory"); // Handle messsage decryption error. Probably client configured to // encrypt messages and on live data feed it received plain text. } } )); pubnub.Subscribe <string>().Channels(new string[] { channel }).Execute(); }