Ejemplo n.º 1
0
        public override async void pollPositions(object source, ElapsedEventArgs e)
        {
            if (pollingPositions)
            {
                return;
            }
            else
            {
                pollingPositions = true;
            }
            try
            {
                Dictionary <String, Decimal> positions = await api.GetAmountsAsync();

                foreach (var pos in positions)
                {
                    var    coinType = pos.Key;
                    var    balance  = pos.Value;
                    String symbol   = exchangeUSD(coinType.ToString());
                    if (dctExchangeProducts.ContainsKey(symbol))
                    {
                        CProduct product = dctExchangeProducts[symbol];
                        product.TimeStampLastBalance = DateTime.Now;
                        Double dbal = 0;
                        Double.TryParse(balance.ToString(), out dbal);
                        product.SetBalance(dbal);
                        product.updateGUI();
                    }
                }
            }
            catch (Exception ex)
            {
                server.AddLog(ex.Message);
            }
            pollingPositions = false;
        }
Ejemplo n.º 2
0
        public override async void pollPositions(object source, ElapsedEventArgs e)
        {
            if (pollingPositions)
            {
                return;
            }
            else
            {
                pollingPositions = true;
            }
            HttpClient httpClient = new HttpClient();

            try
            {
                String endpoint;
                Dictionary <string, string> parameters;
                endpoint = "/v1/account/balances";
                int totalPage   = 99;
                int currentPage = 0;
                int limit       = 12;
                while (++currentPage <= totalPage)
                {
                    parameters = new Dictionary <string, string> {
                        { "limit", limit.ToString() },
                        { "page", currentPage.ToString() },
                    };
                    HttpRequestMessage requestMessage = KuCoinPrivate(endpoint, parameters, HttpMethod.Get);

                    // Send the request to the server
                    HttpResponseMessage response = await httpClient.SendAsync(requestMessage);

                    // Just as an example I'm turning the response into a string here
                    string json = await response.Content.ReadAsStringAsync();

                    dynamic balanceData = JsonConvert.DeserializeObject(json);
                    var     numTicks    = balanceData.timestamp;

                    var posixTime = DateTime.SpecifyKind(new DateTime(1970, 1, 1), DateTimeKind.Utc);
                    //var time = posixTime.AddMilliseconds(numTicks);

                    var balances = balanceData.data;
                    if (balances != null)
                    {
                        var total   = balances.total;
                        var pageNos = balances.pageNos;
                        int.TryParse(pageNos.ToString(), out totalPage);
                        foreach (var pos in balances.datas)
                        {
                            var    coinType      = pos.coinType;
                            var    balance       = pos.balance;
                            var    freezeBalance = pos.freezeBalance;
                            String symbol        = exchangeUSD(coinType.ToString());
                            if (dctExchangeProducts.ContainsKey(symbol))
                            {
                                CProduct product = dctExchangeProducts[symbol];
                                product.TimeStampLastBalance = DateTime.Now;
                                Double dbal = 0;
                                Double.TryParse(balance.ToString(), out dbal);
                                Double dfreezeBal = 0;
                                Double.TryParse(freezeBalance.ToString(), out dfreezeBal);
                                if (product.CurrentBalance.HasValue && dbal != product.CurrentBalance.GetValueOrDefault())
                                {
                                    server.AddLog("Balance Changed!");
                                }
                                product.SetBalance(dbal + dfreezeBal);
                                product.updateGUI();
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                server.AddLog(ex.Message);
            }
            pollingPositions = false;
        }