コード例 #1
0
ファイル: OrdersList.cs プロジェクト: 4e4y/BTCeAPI
        public static OrdersList ReadFromJSON(string orders)
        {
            JObject data    = JObject.Parse(orders)["return"] as JObject;
            JValue  success = JObject.Parse(orders)["success"] as JValue;
            JValue  error   = JObject.Parse(orders)["error"] as JValue;

            if ((int)success == 1)
            {
                var list = new OrdersList();

                foreach (var order in data)
                {
                    int       orderId   = int.Parse(order.Key.ToString());
                    OrderInfo orderInfo = OrderInfo.ReadFromJSON(order.Value.ToString(), orderId);
                    list.List.Add(key: orderId, value: orderInfo);
                }

                return(list);
            }

            throw new BTCeAPIException((string)error);
        }
コード例 #2
0
ファイル: BTCeAPIWrapper.cs プロジェクト: 4e4y/BTCeAPI
        private void CallBTCeAPIActiveOrders()
        {
            var resultStr = Query(new Dictionary <string, string>()
            {
                { "method", "ActiveOrders" },
                { "pair", BtcePairHelper.ToString(currency) }
            });

            if (ActiveOrdersReceived != null ||
                ActiveOrdersCountChanged != null ||
                ActiveOrdersTotalAmountChanged != null)
            {
                try
                {
                    OrdersList orders = OrdersList.ReadFromJSON(resultStr);

                    var totalAmount = orders.List.Sum(x => x.Value.Amount);

                    if (ActiveOrdersReceived != null)
                    {
                        ActiveOrdersReceived(orders, EventArgs.Empty);
                    }

                    if (ActiveOrdersCountChanged != null)
                    {
                        if (latestActiveOrdersCount > -1 &&
                            latestActiveOrdersCount != orders.List.Count)
                        {
                            ActiveOrdersCountChanged(orders, new DecimalEventArgs(latestActiveOrdersCount));
                        }
                    }

                    if (ActiveOrdersTotalAmountChanged != null)
                    {
                        if (latestTotalAmount > -1 &&
                            latestTotalAmount != totalAmount)
                        {
                            ActiveOrdersTotalAmountChanged(orders, new DecimalEventArgs(latestTotalAmount));
                        }
                    }

                    if (latestActiveOrdersCount != orders.List.Count)
                    {
                        latestActiveOrdersCount = orders.List.Count;
                    }

                    if (latestTotalAmount != totalAmount)
                    {
                        latestTotalAmount = totalAmount;
                    }

                    ActiveOrders.Start();
                }
                catch (BTCeAPIException e)
                {
                    ActiveOrdersReceived(e, EventArgs.Empty);
                }
                catch (Exception ex)
                {
                    ActiveOrdersReceived(ex, EventArgs.Empty);
                }
            }
        }