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)); }
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)); }
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); }
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); }
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")) }); }
/// <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")); }
public static Depth GetDepth(BtcePair pair) { return (Depth.ReadFromJObject( JObject.Parse(Query(string.Format("{1}api/2/{0}/depth", BtcePairHelper.ToString(pair), ExchangeHost))))); }
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)); }
private static string MakePairListString(BtcePair[] pairlist) { return(string.Join("-", pairlist.Select(x => BtcePairHelper.ToString(x)).ToArray())); }
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)); }
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")); }
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()); }
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)); }
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)); }
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)))); }
public static Tuple <string, string> FromBtcePair(BtcePair pair) { string[] currencyStrs = BtcePairHelper.ToString(pair).Split('_'); return(Tuple.Create(currencyStrs[0].ToUpperInvariant(), currencyStrs[1].ToUpperInvariant())); }