Пример #1
0
        public void MakeTrade(ITradeRequest tradeRequest)
        {
            var p = new Dictionary <string, string>();

            p.Add("pair", BtcePairHelper.ToString(tradeRequest.Pair));
            p.Add("type", TradeTypeHelper.ToString(tradeRequest.TradeType));
            p.Add("rate", tradeRequest.Rate.ToString(CultureInfo.InvariantCulture));
            p.Add("amount", tradeRequest.Amount.ToString(CultureInfo.InvariantCulture));

            requestInputQueue.AddItemToQueue(new InputQueueItem
            {
                MethodName       = BtceCommandTrade,
                MethodParameters = p
            });


            /*
             * string tradeResult = Query("Trade", p);
             * var tradeResponse = JObject.Parse(tradeResult);
             *
             * if (tradeResponse["success"].Value<int>() == 0)
             * {
             *  toReturn.IsSuccess = false;
             *  toReturn.ErrorMessage = tradeResponse["error"].Value<string>();
             * }
             * else
             * {
             *  toReturn.IsSuccess = true;
             *  toReturn.ErrorMessage = string.Empty;
             * }
             *
             * return toReturn;*/
        }
Пример #2
0
        private void HandleActiveOrdersCallBack(string result)
        {
            var  webResult     = JObject.Parse(result);
            bool handleMessage = true;

            if (webResult["success"].Value <int>() == 0)
            {
                LogApiMessage("Error", string.Format("Error while handling AccountInfo message. {0}", webResult["error"].Value <string>()));
                handleMessage = false;
            }

            var newList = new List <IOrder>();

            if (handleMessage)
            {
                foreach (var orderItem in webResult["return"].Value <JObject>())
                {
                    var newOrder = new Order()
                    {
                        Id         = orderItem.Key,
                        Pair       = BtcePairHelper.FromString(orderItem.Value["pair"].Value <string>()),
                        Type       = TradeTypeHelper.FromString(orderItem.Value["type"].Value <string>()),
                        Amount     = orderItem.Value["amount"].Value <decimal>(),
                        Rate       = orderItem.Value["rate"].Value <decimal>(),
                        CreateDate = UnixTimeHelper.UnixTimeToDateTime(orderItem.Value["timestamp_created"].Value <UInt32>()),
                        Status     = orderItem.Value["status"].Value <int>()
                    };
                    newList.Add(newOrder);
                }
            }

            /*
             * ActiveOrders.Add(new Order
             *  {
             *      Amount = 1,
             *      CreateDate = DateTime.Now,
             *      Id = "DEMOBuy",
             *      Pair = BtcePairEnum.nmc_usd,
             *      Rate = 4.88m,
             *      Type = TradeTypeEnum.Buy,
             *      Status = 1
             *  });
             *
             * ActiveOrders.Add(new Order
             * {
             *  Amount = 1,
             *  CreateDate = DateTime.Now,
             *  Id = "DEMOSell",
             *  Pair = BtcePairEnum.nmc_usd,
             *  Rate = 4.956m,
             *  Type = TradeTypeEnum.Sell,
             *  Status = 1
             * });*/

            ActiveOrders = newList;
            OnPropertyChanged("ActiveOrders");

            if (ActiveOrdersUpdated != null)
            {
                ActiveOrdersUpdated(this, null);
            }

            LogApiMessage("Api message processed", "Active orders updated");
        }