using System; using System.Collections.Generic; using System.Text; namespace SDKAdapter.WebSockets.Market { public class SpotMarketWebSocketClient { /// /// 更新间隔(ms) /// protected int updateInterval = 3000; /// /// 交易对 /// public string Symbol { get; private set; } /// /// 最新成交价 /// public decimal NewestPrice { get; private set; } /// r /// 上一次价格更新时间 /// public DateTime? LastUpdateTime { get; private set; } public NLog.ILogger logger { get; private set; } public SpotMarketWebSocketClient(string symbol, NLog.ILogger logger) { this.Symbol = symbol; this.logger = logger; } public virtual void Start() { } public virtual void Stop() { } protected virtual void OnReceived(decimal newestPrice) { NewestPrice = newestPrice; if (LastUpdateTime == null || (DateTime.Now - LastUpdateTime.Value).TotalMilliseconds >= updateInterval) { logger.Info($"NewestPrice:{newestPrice}"); LastUpdateTime = DateTime.Now; } } } }