using System; using System.Collections.Generic; using System.Text; namespace SDKAdapter.WebSockets.Market { public class SpotMarketWebSocketClient { /// <summary> /// 更新间隔(ms) /// </summary> protected int updateInterval = 3000; /// <summary> /// 交易对 /// </summary> public string Symbol { get; private set; } /// <summary> /// 最新成交价 /// </summary> public decimal NewestPrice { get; private set; } /// <summary>r /// 上一次价格更新时间 /// </summary> 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; } } } }