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")); }
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)); }
public static WexPair FromString(string s) { WexPair ret = WexPair.Unknown; Enum.TryParse <WexPair>(s.ToLowerInvariant(), out ret); return(ret); }
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(); }
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)); }
/// <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)); }
//PRIVATE: static SortedSet <string> GetAddedPairs(List <string> resp_pairs) { SortedSet <string> added_pairs = new SortedSet <string>(); foreach (string s_pair in resp_pairs) { WexPair wex_pair = WexPairHelper.FromString(s_pair); if (wex_pair == WexPair.Unknown) { added_pairs.Add(s_pair.ToLowerInvariant()); } } return(added_pairs); }
/// <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)); }
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)); }
public static PairCurrencies GetPairCurrencies(WexPair p) { if (p == WexPair.Unknown) { return(null); } string str_p = ToString(p); string[] arr = str_p.Split(PAIR_TO_CURR_SPLIT_CHARS); if (arr.Length != 2) { throw new Exception("Strange pair " + str_p); } return(new PairCurrencies { BaseCurrency = WexCurrencyHelper.FromString(arr[0]), QuoteCurrency = WexCurrencyHelper.FromString(arr[1]) }); }
/// <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)); }
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); }
static void Main(string[] args) { //----------------------------------------------------------------- Console.WriteLine("0. Check WexApi code is relevant."); APIRelevantTest.Check(); Console.WriteLine("Code is ok."); //----------------------------------------------------------------- Console.WriteLine(); Console.WriteLine(); Console.WriteLine(); Console.WriteLine("1. Public API Tests."); // info example: { Console.WriteLine(); Console.WriteLine("1.1. info"); var info = WexPublicApi.Info(); decimal btc_min_price_in_usd = info.Pairs[WexPair.btc_usd].MinPrice; Console.WriteLine("Min BTC price in wex is {0}$", btc_min_price_in_usd); } var BTC_USD_PAIR = new WexPair[] { WexPair.btc_usd }; // ticker example: { Console.WriteLine(); Console.WriteLine("1.2. ticker"); var ticker = WexPublicApi.Ticker(BTC_USD_PAIR); decimal btc_usd_hight = ticker[WexPair.btc_usd].High; decimal btc_usd_low = ticker[WexPair.btc_usd].Low; Console.WriteLine("I'm hamster. I bought BTC for {0}$ and sold for {1}$", btc_usd_hight, btc_usd_low); } // depth example: { Console.WriteLine(); Console.WriteLine("1.3. depth"); var depth = WexPublicApi.Depth(BTC_USD_PAIR, limit: 1); decimal btc_ask = depth[WexPair.btc_usd].Asks[0].Price; decimal btc_bid = depth[WexPair.btc_usd].Bids[0].Price; Console.WriteLine("Now BTC ask {0}$ and bid {1}$", btc_ask, btc_bid); } // trades example: { Console.WriteLine(); Console.WriteLine("1.4. trades"); var trades = WexPublicApi.Trades(BTC_USD_PAIR, limit: 1); string str_deal = DealTypeHelper.ToString(trades[WexPair.btc_usd][0].Type); decimal amount = trades[WexPair.btc_usd][0].Amount; decimal price = trades[WexPair.btc_usd][0].Price; Console.WriteLine("BTC/USD: Last deal is {0} {1}BTC by price {2}$", str_deal, amount, price); } //----------------------------------------------------------------- // 2. Trade API Console.WriteLine(); Console.WriteLine(); Console.WriteLine(); Console.WriteLine("2. Trade API Tests."); Console.WriteLine("Enter API-key:"); string api_key = Console.ReadLine(); Console.WriteLine("Enter API secret key:"); string api_secret = Console.ReadLine(); var wex_trade_api = new WexTradeApi(api_key, api_secret); // GetInfo example: { Console.WriteLine(); Console.WriteLine("2.1. GetInfo"); var account_info = wex_trade_api.GetInfo(); Console.WriteLine("Our balance:"); foreach (var fund in account_info.Funds.Amounts) { Console.WriteLine("{0}: {1}", WexCurrencyHelper.ToString(fund.Key), fund.Value); } } // Trade example: { Console.WriteLine(); Console.WriteLine("2.2. Trade"); Console.WriteLine("I need to buy 1BTC for 10$."); Console.WriteLine("Commented because it's operation with real money :)"); //var trade_result = wex_trade_api.Trade(WexPair.btc_usd, TradeType.Buy, 10.0m, 1m); //if( trade_result.OrderId == 0 ) // Console.WriteLine("Done. Now I have {0}BTC.", // trade_result.Funds.Amounts[WexCurrency.btc]); //else // Console.WriteLine("New order with id {0}.", trade_result.OrderId); } // ActiveOrders example: { Console.WriteLine(); Console.WriteLine("2.3. ActiveOrders"); Console.WriteLine("My BTC/USD orders:"); OrderList active_orders = null; try { active_orders = wex_trade_api.ActiveOrders(pair: WexPair.btc_usd); } catch (Exception e) { // Wex, for example, throw error if orders don't exists :D Console.WriteLine(e.ToString()); } if (active_orders != null) { foreach (var ord in active_orders.List) { Console.WriteLine("{0}: {1} {2} BTC by price {3}.", ord.Key, // order id TradeTypeHelper.ToString(ord.Value.Type), // buy or sell ord.Value.Amount, // count btc ord.Value.Rate // price in usd ); } } } // OrderInfo example: { Console.WriteLine(); Console.WriteLine("2.4. OrderInfo"); Console.WriteLine( "Commented because most likely order with id 12345 does not exists :)"); //var order_info = wex_trade_api.OrderInfo(order_id: 12345); //Console.WriteLine("Order id 12345 has amount " + order_info.Amount); } // CancelOrder example: { Console.WriteLine(); Console.WriteLine("2.5. CancelOrder"); Console.WriteLine("Commented because it's operation with real money :)"); //var cancel_order_info = wex_trade_api.CancelOrder(order_id: 12345); //Console.WriteLine("Order id 12345 is canceled, now I have {0} RUR", // cancel_order_info.Funds.GetAmount(WexCurrency.rur)); } // TradeHistory example: { Console.WriteLine(); Console.WriteLine("2.6. TradeHistory"); var trade_history = wex_trade_api.TradeHistory( pair: WexPair.btc_usd, count: 10, order_asc: false ); Console.WriteLine("My last 10 BTC/USD deals:"); foreach (var t in trade_history.List) { Console.WriteLine("{0}: {1} {2} BTC by price {3}.", t.Key, // order id TradeTypeHelper.ToString(t.Value.Type), // buy or sell t.Value.Amount, // count btc t.Value.Rate // price in usd ); } } // TransHistory example: { Console.WriteLine(); Console.WriteLine("2.7. TransHistory"); var trans_history = wex_trade_api.TransHistory( count: 10, order_asc: false ); Console.WriteLine("My last 10 transactions:"); foreach (var t in trans_history.List) { Console.WriteLine("{0}: {1} {2}, {3}: {4}", t.Key, // order id t.Value.Amount, WexCurrencyHelper.ToString(t.Value.Currency), TransTypeHelper.ToString(t.Value.Type), t.Value.Description ); } } // CoinDepositAddress example: { Console.WriteLine(); Console.WriteLine("2.8. CoinDepositAddress"); var coin_dep_addr = wex_trade_api.CoinDepositAddress(WexCurrency.btc); Console.WriteLine("My BTC deposit address is " + coin_dep_addr); } Console.ReadKey(); }
public static string ToString(WexPair v) { return(Enum.GetName(typeof(WexPair), v).ToLowerInvariant()); }