Exemple #1
0
        public OrderResponse OrderLimit(string paramOrd, string publicKey, string secretKey)
        {
            string correctParam = paramOrd.Replace("_", "");

            var    privateApi = new SecretKeyRequiredRequester();
            string response   = string.Empty;

            Regex  my_reg     = new Regex(@"\D");
            string serverTime = string.Empty;

            try
            {
                serverTime = my_reg.Replace(ServiceRequests.ServerTime(), "");
            }
            catch (Exception ex)
            {
                // TODO: loging
            }

            string url_order     = "https://api.binance.com/api/v3/order?" + correctParam + "&type=LIMIT&recvWindow=5000&timeInForce=GTC&timestamp=" + serverTime;
            string api_parametrs = correctParam + "&type=LIMIT&recvWindow=5000&timeInForce=GTC&timestamp=" + serverTime;

            try
            {
                response = privateApi.GetWebRequest(url_order, api_parametrs, publicKey, secretKey, "POST");
            }
            catch (Exception ex)
            {
                // TODO: ВЫВЕСТИ НА МОРДУ
            }

            return(JConverter.JsonConver <OrderResponse>(response));
        }
Exemple #2
0
        //public List<Trade> RequestedTrades(string publicKey, string secretKey, TradeConfiguration configuration)
        //{
        //    var trades = TradesRequest(publicKey, secretKey, $"{configuration.MainCoin}{configuration.AltCoin}");
        //    if (trades != null)
        //    {
        //        foreach (var trade in trades)
        //        {
        //            tradeRepository.Create(new DataBaseWork.Models.Trade()
        //            {
        //                FK_PublicKey = publicKey,
        //                Symbol = trade.symbol,
        //                TradeID = trade.id,
        //                OrderID = trade.orderId,
        //                OrderListID = trade.orderListId,
        //                Price = trade.price,
        //                Qty = trade.qty,
        //                QuoteQty = trade.quoteQty,
        //                Commission = trade.commission,
        //                CommissionAsset = trade.commissionAsset,
        //                Time = trade.time,
        //                IsBuyer = trade.isBuyer,
        //                IsMaker = trade.isMaker,
        //                IsBestMatch = trade.isBestMatch
        //            });
        //        }
        //    }
        //    return trades;
        //}

        private List <Trade> TradesRequest(string key, string secret, string pair, long fromId)
        {
            logService.Write("***********TradesRequest START***********", true);
            logService.Write($"\tTradesRequest Public key: {key}");
            logService.Write($"\tTradesRequest pair: {pair}");
            List <Trade> result     = null;
            var          privateApi = new SecretKeyRequiredRequester();
            var          my_reg     = new Regex(@"\D");
            var          serverTime = "";
            var          response   = "";

            try
            {
                serverTime = my_reg.Replace(ServiceRequests.ServerTime(), "");
                logService.Write($"\tTradesRequest get serverTime successful: {serverTime}");
            }
            catch (Exception ex)
            {
                logService.Write($"\tAccount get serverTime error: Exception: {ex.Message} Innerexception: {ex.InnerException?.Message}");
            }
            try
            {
                var request = CreatRequest(pair, serverTime, out string requestParams, fromId);
                response = privateApi.GetWebRequest(request, requestParams, key, secret, "GET");
                logService.Write($"\tTradesRequest {Resources.DOMAIN_V3}myTrades... successful: response = {response}");
            }
            catch (Exception ex)
            {
                logService.Write($"\tTradesRequest {Resources.DOMAIN_V3}myTrades... error: Exception: {ex.Message} Innerexception: {ex.InnerException?.Message}");
            }

            try
            {
                result = JConverter.JsonConver <List <Trade> >(response);
                logService.Write($"\tTradesRequest JConverter successful.");
            }
            catch (Exception ex)
            {
                logService.Write($"\tTradesRequest JConverter error: Exception: {ex.Message} Innerexception: {ex.InnerException?.Message}");
            }

            if (result != null)
            {
                var tradeForRemove = result.FirstOrDefault(x => x.id == fromId);
                if (tradeForRemove != null)
                {
                    result.Remove(tradeForRemove);
                }
            }
            logService.Write("***********TradesRequest END***********", true);
            return(result);
        }
Exemple #3
0
        private Account Account(string key, string secret)
        {
            logService.Write("***********Account START***********", true);
            logService.Write($"\tPublic key: {key}");
            Account result = null;
            SecretKeyRequiredRequester privateApi = new SecretKeyRequiredRequester();
            string response   = string.Empty;
            Regex  my_reg     = new Regex(@"\D");
            string serverTime = string.Empty;

            try
            {
                serverTime = my_reg.Replace(ServiceRequests.ServerTime(), "");
                logService.Write($"\tAccount get serverTime successful: {serverTime}");
            }
            catch (Exception ex)
            {
                logService.Write($"\tAccount get serverTime error: Exception: {ex.Message} Innerexception: {ex.InnerException?.Message}");
            }
            try
            {
                response = privateApi.GetWebRequest($"{Resources.DOMAIN_V3}account?recvWindow=5000&timestamp=" + serverTime, "recvWindow=5000&timestamp=" + serverTime, key, secret, "GET");
                logService.Write($"\tAccount {Resources.DOMAIN_V3}account... successful: response = {response.Substring(0, 500)}");
            }
            catch (Exception ex)
            {
                logService.Write($"\tAccount {Resources.DOMAIN_V3}account... error: Exception: {ex.Message} Innerexception: {ex.InnerException?.Message}");
            }

            try
            {
                result = JConverter.JsonConver <Account>(response);
                logService.Write($"\tAccount JConverter successful.");
            }
            catch (Exception ex)
            {
                logService.Write($"\tAccount JConverter error: Exception: {ex.Message} Innerexception: {ex.InnerException?.Message}");
            }
            logService.Write("***********Account END***********", true);
            return(result);
        }