using Binance.TradeRobot.Model.Base;
using System;

namespace Binance.TradeRobot.Model.Dto
{
    public class RobotResponse
    {
        public RobotResponse()
        {

        }

        public long Id { get; set; }
        public DateTime CreateTime { get; set; }
        public Enums.TradePolicy TradePolicy { get; set; }

        /// <summary>
        /// 运行时长(s)
        /// </summary>
        public long RunningTime { get; set; } = 0;

        public Enums.RobotState State { get; set; }

        public string Symbol { get; set; }

        public Enums.BusinessType BusinessType { get; set; }

        public Enums.Exchange ExchangeId { get; set; }

        //public virtual string OrderPublishLogKey
        //{
        //    get
        //    {
        //        return $"OrderPublish-{ExchangeId}-{BusinessType}-{Symbol}";
        //    }
        //}

        /// <summary>
        /// 机器人账户对象
        /// </summary>
        public RobotAccountResponse RobotAccount { get; set; }

        /// <summary>
        /// 机器人绑定的交易所APIKey对象
        /// </summary>
        public SimpleExchangeAPIKeyResponse ExchangeAPIKey { get; set; }

        public string ExecuteKey { get { return $"Execute-{ExchangeId}-{TradePolicy}-{Symbol}"; } }

        public string KLineKey { get { return $"KLine-{ExchangeId}-{BusinessType}-{Symbol}"; } }

        /// <summary>
        /// 订单推送监听实例Key
        /// <para>币安逐仓杠杆需要单独的运行实例</para>
        /// </summary>
        public string OrderPublishKey
        {
            get
            {
                if (State == Enums.RobotState.Runing && ExchangeAPIKey != null)
                {
                    string key = $"{BusinessType}-{ExchangeAPIKey.AccountId}";           //币安现货,币安合约,同一个账户内不区分websocket实例
                    if (ExchangeId == Enums.Exchange.Binance && BusinessType == Enums.BusinessType.IsolateMargin)
                        key = $"{BusinessType}-{ExchangeAPIKey.AccountId}-{Symbol}";     //币安逐仓杠杆,同一个账户内的每个交易对需要区分websocket实例
                    return $"OrderPublish-{ExchangeId}-{key}";
                }
                return string.Empty;
            }
        }
    }
}