static IDisposable SubscribeTickerSource(RealtimeSourceFactory factory, BfProductCode productCode) { var source = factory.GetTickerSource(productCode); return(source.Subscribe(ticker => { Console.WriteLine($"{ticker.Timestamp} P:{ticker.LastTradedPrice} A:{ticker.BestAsk} B:{ticker.BestBid}"); })); }
private static async Task RealtimeTickerSample(RealtimeSourceFactory factory) { var tickerSource = await factory.GetTickerSource(ProductCode.BTCJPY); tickerSource.Subscribe(ticker => { Console.WriteLine($"{ticker.ProductCode} {ticker.Timestamp.ToLocalTime()} {ticker.BestBid} {ticker.BestAsk} {ticker.LastTradedPrice}"); }); }
static void Main(string[] args) { // ログファイル出力設定 // Time / JSON LoadRunsettings(args[0]); var key = Properties["ApiKey"]; var secret = Properties["ApiSecret"]; _client = new BitFlyerClient(key, secret); _factory = new RealtimeSourceFactory(key, secret); _factory.MessageReceived += OnRealtimeMessageReceived; _factory.Error += (error) => Console.WriteLine("Error: {0} Socket Error = {1}", error.Message, error.SocketError); _factory.GetTickerSource(ProductCode).Subscribe(ticker => { _ticker = ticker; //Console.WriteLine($"Ask:{_ticker.BestAsk} Bid:{_ticker.BestBid}"); }).AddTo(_disposables); _factory.GetChildOrderEventsSource().Subscribe(OnChildOrderEvent).AddTo(_disposables); _factory.GetParentOrderEventsSource().Subscribe(OnParentOrderEvent).AddTo(_disposables); while (true) { Console.WriteLine("========================================================================"); Console.WriteLine("C)hild order >"); Console.WriteLine("P)arent order >"); Console.WriteLine(""); Console.WriteLine("Q)uit"); Console.WriteLine("========================================================================"); switch (GetCh()) { case 'C': ChildOrderMain(); break; case 'P': ParentOrderMain(); break; case 'Q': _disposables.Dispose(); return; } } }
static void RealtimeTickerSample(RealtimeSourceFactory factory) { factory.GetTickerSource(BfProductCode.FXBTCJPY).Subscribe(ticker => { Console.WriteLine("{0} {1} {2} {3} {4} {5} {6} {7} {8} {9} {10} {11}", ticker.ProductCode, ticker.Timestamp.ToLocalTime(), ticker.TickId, ticker.BestBid, ticker.BestAsk, ticker.BestBidSize, ticker.BestAskSize, ticker.TotalBidDepth, ticker.TotalAskDepth, ticker.LastTradedPrice, ticker.Last24HoursVolume, ticker.VolumeByProduct); }).AddTo(_disposables); }