示例#1
0
 private static string MakePairListString(WexPair[] pairlist)
 {
     if (pairlist == null)
     {
         return("");
     }
     return(string.Join(
                "-",
                pairlist.Select(x => WexPairHelper.ToString(x)).ToArray()
                ));
 }
示例#2
0
        /// <summary>
        /// Returns trade history.
        /// See https://github.com/wex-exchange/api-doc/blob/master/trade-api.md#TradeHistory
        /// </summary>
        /// <param name="from">Trade ID, from which the display starts</param>
        /// <param name="count">The number of trades for display</param>
        /// <param name="from_id">Trade ID, from which the display starts</param>
        /// <param name="end_id">Trade ID on which the display ends</param>
        /// <param name="order_asc">Sorting</param>
        /// <param name="since">The time to start the display</param>
        /// <param name="end">The time to end the display</param>
        /// <param name="pair">Pair to be displayed</param>
        public TradeHistoryAnswer TradeHistory(
            int?from       = null,
            int?count      = null,
            int?from_id    = null,
            int?end_id     = null,
            bool?order_asc = null,
            DateTime?since = null,
            DateTime?end   = null,
            WexPair pair   = WexPair.Unknown)
        {
            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 (from_id != null)
            {
                args.Add("from_id", from_id.Value.ToString());
            }
            if (end_id != null)
            {
                args.Add("end_id", end_id.Value.ToString());
            }
            if (order_asc != null)
            {
                args.Add("order", (order_asc.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 != WexPair.Unknown)
            {
                args.Add("pair", WexPairHelper.ToString(pair));
            }

            string query_answer = QueryExec(args);
            var    json_result  = ParseAnswer(query_answer);

            return(TradeHistoryAnswer.ReadFromJObject(json_result));
        }
示例#3
0
        /// <summary>
        /// Returns the list of your active orders.
        /// See https://github.com/wex-exchange/api-doc/blob/master/trade-api.md#ActiveOrders
        /// </summary>
        /// <param name="pair">pair, default all pairs</param>
        public OrderList ActiveOrders(WexPair pair = WexPair.Unknown)
        {
            var args = new Dictionary <string, string>()
            {
                { "method", "ActiveOrders" }
            };

            if (pair != WexPair.Unknown)
            {
                args.Add("pair", WexPairHelper.ToString(pair));
            }

            string query_answer = QueryExec(args);
            var    json_result  = ParseAnswer(query_answer);

            return(OrderList.ReadFromJObject(json_result));
        }
示例#4
0
        public TradeAnswer Trade(WexPair pair, TradeType type, decimal rate, decimal amount)
        {
            var args = new NameValueDictionary
            {
                { "pair", WexPairHelper.ToString(pair) },
                { "type", TradeTypeHelper.ToString(type) },
                { "rate", DecimalToString(rate) },
                { "amount", DecimalToString(amount) }
            };
            var result = JObject.Parse(Query("Trade", args));

            if (result.Value <int>("success") == 0)
            {
                throw new WexApiException(result.Value <string>("error"));
            }
            return(TradeAnswer.ReadFromJObject(result["return"] as JObject));
        }
示例#5
0
        public OrderList ActiveOrders(WexPair?pair = null)
        {
            var args = new NameValueDictionary();

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

            var json = Query("ActiveOrders", args);

            if (json.Contains("\"no orders\""))
            {
                return(new OrderList());
            }

            var result = DeserializeBtceObject <OrderList>(json);

            return(result);
        }
示例#6
0
        /// <summary>
        /// The basic method that can be used for creating orders and trading on the exchange.
        /// See https://github.com/wex-exchange/api-doc/blob/master/trade-api.md#Trade
        /// </summary>
        /// <param name="pair">Pair</param>
        /// <param name="type">Order type: buy or sell</param>
        /// <param name="rate">The rate at which you need to buy/sell</param>
        /// <param name="amount">The amount you need to buy/sell</param>
        /// <param name="mode">Order mode</param>
        public TradeAnswer Trade(
            WexPair pair,
            TradeType type,
            decimal rate,
            decimal amount,
            TradeMode mode = TradeMode.Limit)
        {
            var args = new Dictionary <string, string>()
            {
                { "method", "Trade" },
                { "pair", WexPairHelper.ToString(pair) },
                { "type", TradeTypeHelper.ToString(type) },
                { "rate", DecimalToString(rate) },
                { "amount", DecimalToString(amount) },
                { "mode", TradeModeHelper.ToString(mode) }
            };
            string query_answer = QueryExec(args);
            var    json_result  = ParseAnswer(query_answer);

            return(TradeAnswer.ReadFromJObject(json_result));
        }
示例#7
0
        static SortedSet <string> GetDeletedPairs(IEnumerable <string> resp_pairs)
        {
            var our_pairs = WexPairHelper.GetAllPairs();

            foreach (string s_pair in resp_pairs)
            {
                WexPair wex_pair = WexPairHelper.FromString(s_pair);
                if (wex_pair != WexPair.Unknown)
                {
                    our_pairs.Remove(wex_pair);
                }
            }

            SortedSet <string> deleted_pairs = new SortedSet <string>();

            foreach (WexPair pair in our_pairs)
            {
                deleted_pairs.Add(WexPairHelper.ToString(pair));
            }
            return(deleted_pairs);
        }
示例#8
0
        public static decimal GetFee(WexPair pair)
        {
            string queryStr = string.Format(CultureInfo.InvariantCulture, WebApi.RootUrl + "/api/2/{0}/fee", WexPairHelper.ToString(pair));
            var    json     = WebApi.Query(queryStr);

            return(JObject.Parse(json).Value <decimal>("trade"));
        }
示例#9
0
        public static List <TradeInfo> GetTrades(WexPair pair)
        {
            string queryStr = string.Format(CultureInfo.InvariantCulture, WebApi.RootUrl + "/api/2/{0}/trades", WexPairHelper.ToString(pair));
            var    json     = WebApi.Query(queryStr);
            var    result   = JsonConvert.DeserializeObject <List <TradeInfo> >(json);

            return(result);
//            return JArray.Parse(json).OfType<JObject>().Select(TradeInfo.ReadFromJObject).ToList();
        }
示例#10
0
        public static Ticker GetTicker(WexPair pair)
        {
            string queryStr = string.Format(CultureInfo.InvariantCulture, WebApi.RootUrl + "/api/2/{0}/ticker", WexPairHelper.ToString(pair));
            var    json     = WebApi.Query(queryStr);

            return(Ticker.ReadFromJObject(JObject.Parse(json)["ticker"] as JObject));
        }
示例#11
0
        public static Depth GetDepth(WexPair pair)
        {
            string queryStr = string.Format(CultureInfo.InvariantCulture, WebApi.RootUrl + "/api/2/{0}/depth", WexPairHelper.ToString(pair));
            var    json     = WebApi.Query(queryStr);
            var    result   = JsonConvert.DeserializeObject <Depth>(json);

            return(result);

//            return Depth.ReadFromJObject(JObject.Parse(json));
        }