Example #1
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));
        }
Example #2
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));
        }