using Binance.Net.Clients;
using Binance.Net.Objects;
using Binance.TradeRobot.Model.Base;
using CryptoExchange.Net.Authentication;
using Newtonsoft.Json;
using SDKAdapter.APIClient;
using SDKAdapter.WebSockets.Order.Spot;
using System;
using System.Threading.Tasks;

namespace SDKTestConsole
{
    internal class Program
    {
        private static System.Threading.Timer timer;

        private static SpotOrderWebSocketClient orderWebSocketClient;
        static void Main(string[] args)
        {
            var apiKey = "pXKdUPbGN4DNar2f2HRoL2qxHoCWcLNf9V5uHTL2lBVCxz66eE8PMPwBw9h8RbKf";
            var secret = "c14tJd7kpMnePKRDoo4nzZk4bIn9bDO8ZCYo69amB4uspLgO5s4GlzYvTwD2zYav";
            var client = BaseAPIClient.Create(Enums.Exchange.Binance, 0, apiKey, secret);

            //逐仓杠杆账户资产
            //var marginList = client.GetIsolatedMarginAccountAssets();
            //var s = JsonConvert.SerializeObject(marginList);

            //var spotClientOption = new BinanceApiClientOptions()
            //{
            //    BaseAddress = "https://api.binance.com",
            //    ApiCredentials = new ApiCredentials(apiKey, secret)
            //};
            //var usdFuturesClientOption = new BinanceApiClientOptions()
            //{
            //    BaseAddress = "https://fapi.binance.com",
            //    ApiCredentials = new ApiCredentials(apiKey, secret)
            //};
            //var binanceClient = new BinanceClient(new BinanceClientOptions()
            //{
            //    UsdFuturesApiOptions = usdFuturesClientOption,
            //    SpotApiOptions = spotClientOption
            //});

            var binanceSocketClient = new BinanceSocketClient();
            //var newClientOrderId = "abcd_286129845448773_1";
            //var orderId = client.IsolatedMarginPlaceOrder("ETHUSDT", Enums.TradeDirection.Buy, Enums.OrderType.MARKET, quoteAmount: 20M, newClientOrderId: newClientOrderId);

            var logger = NLog.LogManager.GetLogger("test");




            var stopLossClientOrderId = "stoploss2_286129845448773_1";
            long stopLossOrderId = 0;

            while (true)
            {
                var input = Console.ReadLine();
                if (input == "start")
                {
                    orderWebSocketClient = SpotOrderWebSocketClient.Create(Enums.BusinessType.IsolateMargin,
                                                                         Enums.Exchange.Binance,
                                                                         0,
                                                                         apiKey,
                                                                         secret,
                                                                         logger,
                                                                         null);
                    orderWebSocketClient.Start("ETHUSDT");
                }
                if (input == "down")
                {
                    stopLossOrderId = client.IsolatedMarginPlaceOrder("ETHUSDT", Enums.TradeDirection.Sell, Enums.OrderType.STOP_LOSS_LIMIT, quantity: 0.0101M, price: 1876M, stopPrice: 1876M, newClientOrderId: stopLossClientOrderId);
                }
                if (input == "cancel")
                {
                    client.CancelIsolateMarginOrder("ETHUSDT", stopLossOrderId, stopLossClientOrderId);
                }
            }
            Console.ReadKey();
        }
    }
}