Пример #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));
        }
Пример #2
0
        public static Trade ReadFromJObject(JObject o)
        {
            if (o == null)
            {
                return(null);
            }

            return(new Trade()
            {
                Pair = WexPairHelper.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")
            });
        }
Пример #3
0
        public static Order ReadFromJObject(JObject o)
        {
            if (o == null)
            {
                return(null);
            }

            return(new Order()
            {
                Pair = WexPairHelper.FromString(o.Value <string>("pair")),
                Type = TradeTypeHelper.FromString(o.Value <string>("type")),
                Amount = o.Value <decimal>("amount"),
                StartAmount = o.Value <decimal>("start_amount"),
                Rate = o.Value <decimal>("rate"),
                TimestampCreated = UnixTime.ConvertToDateTime(
                    o.Value <UInt32>("timestamp_created")),
                Status = o.Value <int>("status"),
            });
        }
Пример #4
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));
        }