Esempio n. 1
0
        public TradeAnswer Trade(BtcePair pair, TradeType type, decimal rate, decimal amount)
        {
            var args = new Dictionary <string, string>()
            {
                { "method", "Trade" },
                { "pair", BtcePairHelper.ToString(pair) },
                { "type", TradeTypeHelper.ToString(type) },
                { "rate", DecimalToString(rate) },
                { "amount", DecimalToString(amount) }
            };
            var result = JObject.Parse(Query(args));

            if (result.Value <int>("success") == 0)
            {
                throw new Exception(result.Value <string>("error"));
            }
            return(TradeAnswer.ReadFromJObject(result["return"] as JObject));
        }
Esempio n. 2
0
        public OrderList GetActiveOrders(BtcePair?pair = null)
        {
            var args = new Dictionary <string, string>()
            {
                { "method", "ActiveOrders" }
            };

            if (pair != null)
            {
                args.Add("pair", BtcePairHelper.ToString(pair.Value));
            }
            var result = JObject.Parse(Query(args));

            if (result.Value <int>("success") == 0)
            {
                throw new Exception(result.Value <string>("error"));
            }
            return(OrderList.ReadFromJObject(result["return"] as JObject));
        }
Esempio n. 3
0
        public static Order ReadFromJObject(JObject o)
        {
            if (o == null)
            {
                return(null);
            }

            var r = new Order()
            {
                Pair             = BtcePairHelper.FromString(o.Value <string>("pair")),
                Type             = TradeTypeHelper.FromString(o.Value <string>("type")),
                Amount           = o.Value <decimal>("amount"),
                Rate             = o.Value <decimal>("rate"),
                TimestampCreated = o.Value <UInt32>("timestamp_created"),
                Status           = o.Value <int>("status")
            };

            return(r);
        }
Esempio n. 4
0
        public static Trade ReadFromJObject(JObject o)
        {
            if (o == null)
            {
                return(null);
            }

            var r = new Trade()
            {
                Pair        = BtcePairHelper.FromString(o.Value <string>("pair")),
                Type        = TradeTypeHelper.FromString(o.Value <string>("type")),
                Amount      = o.Value <decimal>("amount"),
                Rate        = o.Value <decimal>("rate"),
                Timestamp   = o.Value <UInt32>("timestamp"),
                IsYourOrder = o.Value <int>("is_your_order") == 1,
                OrderId     = o.Value <int>("order_id")
            };

            return(r);
        }
Esempio n. 5
0
        public static TradeInfo ReadFromJObject(JObject o)
        {
            if (o == null)
            {
                return(null);
            }

            return(new TradeInfo
            {
                Amount = o.Value <decimal>("amount"),
                Price = o.Value <decimal>("price"),
                Date = UnixTime.ConvertToDateTime(o.Value <uint>("date")),
                Item = BtceCurrencyHelper.FromString(o.Value <string>("item")),
                PriceCurrency = BtceCurrencyHelper.FromString(o.Value <string>("price_currency")),
                Tid = o.Value <uint>("tid"),
                Type = TradeInfoTypeHelper.FromString(o.Value <string>("trade_type")),
                CurrencyPair =
                    BtcePairHelper.FromString(o.Value <string>("item") + "_" + o.Value <string>("price_currency"))
            });
        }
Esempio n. 6
0
 /// <summary>
 ///     Returns the fee for the supplied currnecy pair
 /// </summary>
 /// <param name="pair">Currency pair to obtain fee for </param>
 /// <returns>Fee amount for trading the supplied currency pair</returns>
 public static decimal GetFee(BtcePair pair)
 {
     return
         (JObject.Parse(Query(string.Format("{1}api/2/{0}/fee", BtcePairHelper.ToString(pair), ExchangeHost)))
          .Value <decimal>("trade"));
 }
Esempio n. 7
0
 public static Depth GetDepth(BtcePair pair)
 {
     return
         (Depth.ReadFromJObject(
              JObject.Parse(Query(string.Format("{1}api/2/{0}/depth", BtcePairHelper.ToString(pair), ExchangeHost)))));
 }
Esempio n. 8
0
        public TradeHistory GetTradeHistory(
            int?from       = null,
            int?count      = null,
            int?fromId     = null,
            int?endId      = null,
            bool?orderAsc  = null,
            DateTime?since = null,
            DateTime?end   = null,
            BtcePair?pair  = null)
        {
            var args = new Dictionary <string, string> {
                { "method", "TradeHistory" }
            };

            if (from != null)
            {
                args.Add("from", from.Value.ToString());
            }

            if (count != null)
            {
                args.Add("count", count.Value.ToString());
            }

            if (fromId != null)
            {
                args.Add("from_id", fromId.Value.ToString());
            }

            if (endId != null)
            {
                args.Add("end_id", endId.Value.ToString());
            }

            if (orderAsc != null)
            {
                args.Add("order", orderAsc.Value ? "ASC" : "DESC");
            }

            if (since != null)
            {
                args.Add("since", UnixTime.GetFromDateTime(since.Value).ToString());
            }

            if (end != null)
            {
                args.Add("end", UnixTime.GetFromDateTime(end.Value).ToString());
            }

            if (pair != null)
            {
                args.Add("pair", BtcePairHelper.ToString(pair.Value));
            }

            JObject result = JObject.Parse(Query(args));

            if (result.Value <int>("success") == 0)
            {
                throw new BtceException(result.Value <string>("error"));
            }
            return(TradeHistory.ReadFromJObject(result["return"] as JObject));
        }
Esempio n. 9
0
 private static string MakePairListString(BtcePair[] pairlist)
 {
     return(string.Join("-", pairlist.Select(x => BtcePairHelper.ToString(x)).ToArray()));
 }
Esempio n. 10
0
 private static Dictionary <BtcePair, T> ReadPairDict <T>(JObject o, Func <JContainer, T> valueReader)
 {
     return(o.OfType <JProperty>().Select(x => new KeyValuePair <BtcePair, T>(BtcePairHelper.FromString(x.Name), valueReader(x.Value as JContainer))).ToDictionary(x => x.Key, x => x.Value));
 }
Esempio n. 11
0
        public static decimal GetFee(BtcePair pair)
        {
            string queryStr = string.Format("https://btc-e.com/api/2/{0}/fee", BtcePairHelper.ToString(pair));

            return(JObject.Parse(WebApi.Query(queryStr)).Value <decimal>("trade"));
        }
Esempio n. 12
0
        public static List <TradeInfo> GetTrades(BtcePair pair)
        {
            string queryStr = string.Format("https://btc-e.com/api/2/{0}/trades", BtcePairHelper.ToString(pair));

            return(JArray.Parse(WebApi.Query(queryStr)).OfType <JObject>().Select(TradeInfo.ReadFromJObject).ToList());
        }
Esempio n. 13
0
        public static Ticker GetTicker(BtcePair pair)
        {
            string queryStr = string.Format("https://btc-e.com/api/2/{0}/ticker", BtcePairHelper.ToString(pair));

            return(Ticker.ReadFromJObject(JObject.Parse(WebApi.Query(queryStr))["ticker"] as JObject));
        }
Esempio n. 14
0
        public OrderList GetOrderList(
            int?from       = null,
            int?count      = null,
            int?fromId     = null,
            int?endId      = null,
            bool?orderAsc  = null,
            DateTime?since = null,
            DateTime?end   = null,
            BtcePair?pair  = null,
            bool?active    = null
            )
        {
            var args = new Dictionary <string, string>()
            {
                { "method", "OrderList" }
            };

            if (from != null)
            {
                args.Add("from", from.Value.ToString());
            }
            if (count != null)
            {
                args.Add("count", count.Value.ToString());
            }
            if (fromId != null)
            {
                args.Add("from_id", fromId.Value.ToString());
            }
            if (endId != null)
            {
                args.Add("end_id", endId.Value.ToString());
            }
            if (orderAsc != null)
            {
                args.Add("order", orderAsc.Value ? "ASC" : "DESC");
            }
            if (since != null)
            {
                args.Add("since", UnixTime.GetFromDateTime(since.Value).ToString());
            }
            if (end != null)
            {
                args.Add("end", UnixTime.GetFromDateTime(end.Value).ToString());
            }
            if (pair != null)
            {
                args.Add("pair", BtcePairHelper.ToString(pair.Value));
            }
            if (active != null)
            {
                args.Add("active", active.Value ? "1" : "0");
            }

            var resultStr = Query(args);
            var result    = JObject.Parse(resultStr);

            if (result.Value <int>("success") == 0)
            {
                throw new Exception(result.Value <string>("error"));
            }

            return(OrderList.ReadFromJObject(result["return"] as JObject));
        }
Esempio n. 15
0
        public static Depth GetDepth(BtcePair pair)
        {
            string queryStr = string.Format("https://btc-e.com/api/2/{0}/depth", BtcePairHelper.ToString(pair));

            return(Depth.ReadFromJObject(JObject.Parse(WebApi.Query(queryStr))));
        }
Esempio n. 16
0
 public static Tuple <string, string> FromBtcePair(BtcePair pair)
 {
     string[] currencyStrs = BtcePairHelper.ToString(pair).Split('_');
     return(Tuple.Create(currencyStrs[0].ToUpperInvariant(), currencyStrs[1].ToUpperInvariant()));
 }