public override OrderItem OrderDetail(string _orderId, params string[] _values) { string _url = "/v1/user/spot/order"; string _pair = _values[0].ToString(); JToken _token = base.HttpCall(HttpCallMethod.Get, "GET", _url, true, "pair", _pair, "order_id", _orderId); if (_token == null || _token.ToString(Newtonsoft.Json.Formatting.None).Trim() == "{}") { return(null); } OrderItem _item = new OrderItem(); _item.Id = _token["order_id"].Value <string>(); _item.Pair = _token["pair"].Value <string>(); _item.Side = _token["side"].Value <string>() == "sell" ? MarketSide.Ask : MarketSide.Bid; _item.Price = _token["price"].Value <decimal>(); _item.Amount = _token["start_amount"].Value <decimal>(); _item.CreateTime = DateTimePlus.JSTime2DateTime(long.Parse(_token["ordered_at"].Value <string>().Remove(10))); string _status = _token["status"].Value <string>(); switch (_status) { case "UNFILLED": _item.Status = OrderStatus.New; break; case "PARTIALLY_FILLED": _item.Status = OrderStatus.Filling; break; case "FULLY_FILLED": _item.Status = OrderStatus.Filled; break; case "CANCELED_UNFILLED": case "CANCELED_PARTIALLY_FILLED": _item.Status = OrderStatus.Canceled; break; } return(_item); }
public override Trade[] GetTrades(string _pair, params string[] _values) { string _url = $"/GET/v1/api/trades?pair={_pair}&count={_values[0]}"; JToken _token = base.HttpCall(HttpCallMethod.Get, "GET", _url); if (_token == null) { return(null); } IList <Trade> _result = new List <Trade>(); JArray _trades = _token.Value <JArray>(); foreach (JToken _item in _trades) { Trade _trade = new Trade(); _trade.Id = _item[0].Value <string>(); _trade.Pair = _pair; _trade.Side = _item[4].Value <bool>() ? MarketSide.Bid : MarketSide.Ask; _trade.Price = _item[1].Value <decimal>(); _trade.Amount = _item[2].Value <decimal>(); _trade.DateTime = DateTimePlus.JSTime2DateTime(_item[3].Value <long>() / 1000); _result.Add(_trade); } return(_result.ToArray()); }
/// <summary> /// /// </summary> /// <param name="_pair"></param> /// <param name="_values">0:size</param> /// <returns></returns> public override Trade[] GetTrades(string _pair, params string[] _values) { string _url = $"/market/history/trade?symbol{_pair}"; if (_values.Length > 0) { _url += $"&size={_values[0]}"; } JToken _token = base.HttpCall(HttpCallMethod.Get, "GET", _url); if (_token == null) { return(null); } IList <Trade> _result = new List <Trade>(); JArray _trades = _token["data"].Value <JArray>(); foreach (JToken _item in _trades) { Trade _trade = new Trade(); _trade.Id = _item["id"].Value <string>(); _trade.Pair = _pair; _trade.Side = _item["direction"].Value <string>() == "sell" ? MarketSide.Ask : MarketSide.Bid; _trade.Price = _item["price"].Value <decimal>(); _trade.Amount = _item["amount"].Value <decimal>(); _trade.DateTime = DateTimePlus.JSTime2DateTime(_item["ts"].Value <long>() / 1000); _result.Add(_trade); } return(_result.ToArray()); }
public DateTime?GetServerTime() { string _url = $"/v2/public/server-time"; JToken _token = base.HttpCall(HttpCallMethod.Get, "GET", _url); if (_token == null) { return(null); } return(DateTimePlus.JSTime2DateTime(_token.Value <long>() / 1000)); }
public override OrderItem OrderCreate(string _pair, MarketSide _side, OrderType _type, decimal _amount, decimal _price = 0M) { string _url = "/api/v3/order"; IList <object> _values = new List <object>(); _values.Add("symbol"); _values.Add(_pair.ToUpper()); _values.Add("side"); _values.Add(_side == MarketSide.Bid ? "BUY" : "SELL"); _values.Add("type"); switch (_type) { case OrderType.Limit: _values.Add("LIMIT"); _values.Add("price"); _values.Add(_price.ToString()); _values.Add("timeInForce"); _values.Add("GTC"); break; case OrderType.Market: _values.Add("MARKET"); break; } _values.Add("quantity"); _values.Add(_amount); _values.Add("timestamp"); long _timestamp = DateTimePlus.DateTime2JSTime(DateTime.UtcNow.AddSeconds(-1)); _values.Add(_timestamp.ToString() + DateTime.UtcNow.Millisecond.ToString()); JToken _token = base.HttpCall(HttpCallMethod.Form, "POST", _url, true, _values.ToArray()); if (_token == null || _token.ToString().Trim() == "{}") { return(null); } this.OnLog(_token.ToString(Newtonsoft.Json.Formatting.None)); OrderItem _item = new OrderItem(); _item.Id = _token["orderId"].Value <string>(); _item.Pair = _token["symbol"].Value <string>(); _item.Side = _token["side"].Value <string>() == "SELL" ? MarketSide.Ask : MarketSide.Bid; _item.Price = _token["price"].Value <decimal>(); _item.Amount = _token["origQty"].Value <decimal>(); _item.CreateTime = DateTimePlus.JSTime2DateTime(long.Parse(_token["transactTime"].Value <string>().Remove(10))); return(_item); }
public override KLine[] GetKLines(string _pair, KLineType _type, params string[] _values) { string _typeText = ""; switch (_type) { case KLineType.M1: _typeText = "1"; break; case KLineType.H1: _typeText = "60"; break; case KLineType.D1: _typeText = "D"; break; default: throw new Exception($"KLine type:{_type.ToString()} not supported."); } string _url = $"/GET/v1/api/kline?pair={_pair}&type={_typeText}"; if (_values.Length > 0) { _url += $"&count={_values[0]}"; } JToken _token = base.HttpCall(HttpCallMethod.Get, "GET", _url); if (_token == null) { return(null); } IList <KLine> _result = new List <KLine>(); JArray _trades = _token.Value <JArray>(); foreach (JToken _item in _trades) { KLine _line = new KLine(); _line.DateTime = DateTimePlus.JSTime2DateTime(_token[0].Value <long>() / 1000); _line.Pair = _pair; _line.Open = _item[1].Value <decimal>(); _line.Close = _item[4].Value <decimal>(); _line.High = _item[2].Value <decimal>(); _line.Low = _item[3].Value <decimal>(); _line.Volume = _item[5].Value <decimal>(); _result.Add(_line); } return(_result.ToArray()); }
protected override void ReceivedTicker(string _pair, JToken _token) { Ticker _ticker = new Ticker(); _ticker.Pair = _pair; _ticker.BidPrice = _token["buy"].Value <decimal>(); _ticker.AskPrice = _token["sell"].Value <decimal>(); _ticker.High24H = _token["high"].Value <decimal>(); _ticker.Low24H = _token["low"].Value <decimal>(); _ticker.LastPrice = _token["last"].Value <decimal>(); _ticker.Volume24H = _token["vol"].Value <decimal>(); _ticker.Change24H = _token["dchange"].Value <decimal>(); _ticker.ChangeRate24H = _token["dchange_pec"].Value <decimal>(); _ticker.DateTime = DateTimePlus.JSTime2DateTime(_token["timestamp"].Value <long>() / 1000); this.Tickers[_pair] = _ticker; }
public MiningStatus GetMiningStatus() { string _url = "/v1/order/mining/difficulty"; JToken _token = base.HttpCall(HttpCallMethod.Get, "GET", _url, true); if (_token == null) { return(null); } MiningStatus _status = new MiningStatus(); _status.Maximum = _token["difficulty"].Value <decimal>(); _status.Current = _token["prediction"].Value <decimal>(); _status.DateTime = DateTimePlus.JSTime2DateTime(_token["update_time"].Value <long>()); return(_status); }
public override OrderItem OrderCreate(string _pair, MarketSide _side, OrderType _type, decimal _amount, decimal _price = 0) { string _url = "/v1/user/spot/order"; IList <object> _values = new List <object>(); _values.Add("pair"); _values.Add(_pair.ToLower()); _values.Add("amount"); _values.Add(_amount.ToString()); _values.Add("price"); _values.Add(int.Parse(_price.ToString())); _values.Add("side"); _values.Add(_side == MarketSide.Bid ? "buy" : "sell"); _values.Add("type"); switch (_type) { case OrderType.Limit: _values.Add("limit"); break; case OrderType.Market: _values.Add("market"); break; } JToken _token = base.HttpCall(HttpCallMethod.Json, "POST", _url, true, _values.ToArray()); if (_token == null || _token.ToString(Newtonsoft.Json.Formatting.None).Trim() == "{}") { return(null); } OrderItem _item = new OrderItem(); _item.Id = _token["order_id"].Value <string>(); _item.Pair = _token["pair"].Value <string>(); _item.Side = _token["side"].Value <string>() == "sell" ? MarketSide.Ask : MarketSide.Bid; _item.Price = _token["price"].Value <decimal>(); _item.Amount = _token["start_amount"].Value <decimal>(); _item.CreateTime = DateTimePlus.JSTime2DateTime(long.Parse(_token["ordered_at"].Value <string>().Remove(10))); return(_item); }
public bool ReceiveFirstPackage(JObject _json, SocketSession _session) { if (_session["TxKey"] + "" != "" && _session["Checksum"] + "" == "DONE") { return(false); } if (_session["RxKey"] + "" == "") { DateTime _time = DateTimePlus.JSTime2DateTime(long.Parse(_json["time"].Value <string>())); if (Math.Abs((_time - DateTime.UtcNow).TotalSeconds) > 300) { _session.Disconnect(); return(true); } _session["TxKey"] = _json["key"].Value <string>(); Random _random = new Random(RandomPlus.RandomSeed); string _rxKey = _random.Next(10000000, 100000000).ToString(); _session["RxKey"] = _rxKey; string _checksum = _random.Next(10000000, 100000000).ToString(); _session["Checksum"] = _checksum; JObject _result = new JObject(); _result["check"] = this.rsa.Sign(_json["num"].Value <string>()); _result["num"] = _checksum; _result["key"] = _rxKey; _session.SendPackage(_result); } else if (_session["Checksum"] + "" != "DONE") { if (!this.rsa.Verify(_session["Checksum"] + "", _json["check"].Value <string>())) { this.socketTxKey = ""; return(true); } _session["Checksum"] = "DONE"; _session.Handshaked = true; } return(true); }
public OrderItem OrderCancel(string _pair, string _orderId) { string _url = "/v1/order/pending"; IList <object> _value = new List <object>(); _value.Add("id"); _value.Add(_orderId); _value.Add("market"); _value.Add(_pair.ToUpper()); JToken _token = base.HttpCall(HttpCallMethod.Get, "DELETE", _url, true, _value.ToArray()); if (_token == null || _token.ToString(Newtonsoft.Json.Formatting.None).Trim() == "{}") { return(null); } OrderItem _item = new OrderItem(); _item.Id = _token["id"].Value <string>(); _item.Pair = _token["market"].Value <string>(); _item.Side = _token["type"].Value <string>() == "sell" ? MarketSide.Ask : MarketSide.Bid; _item.Price = _token["price"].Value <decimal>(); _item.Amount = _token["amount"].Value <decimal>(); _item.FilledAmount = _token["deal_amount"].Value <decimal>(); _item.FilledPrice = _token["avg_price"].Value <decimal>(); _item.FilledVolume = _token["deal_money"].Value <decimal>(); string _status = _token["status"].Value <string>(); switch (_status) { case "not_deal": _item.Status = OrderStatus.New; break; case "part_deal": _item.Status = OrderStatus.Filling; break; case "done": _item.Status = OrderStatus.Filled; break; } _item.CreateTime = DateTimePlus.JSTime2DateTime(long.Parse(_token["create_time"].Value <string>().Remove(10))); return(_item); }
/// <summary> /// GetTrades /// </summary> /// <param name="_pair"></param> /// <param name="_values">0:limit 1:timestamp</param> /// <returns></returns> public override Trade[] GetTrades(string _pair, params string[] _values) { string _url = $"/v1/trades/{_pair}"; if (_values.Length > 0) { _url += $"?limit_trades={_values[0]}"; } if (_values.Length > 1) { _url += $"×tamp={_values[1]}"; } JToken _token = base.HttpCall(HttpCallMethod.Get, "GET", _url); if (_token == null) { return(null); } IList <Trade> _result = new List <Trade>(); JArray _trades = _token.Value <JArray>(); foreach (JToken _item in _trades) { Trade _trade = new Trade(); _trade.Id = _item["tid"].Value <string>(); _trade.Pair = _pair; _trade.Side = _item["type"].Value <string>() == "sell" ? MarketSide.Ask : MarketSide.Bid; _trade.Price = _item["price"].Value <decimal>(); _trade.Amount = _item["amount"].Value <decimal>(); _trade.DateTime = DateTimePlus.JSTime2DateTime(_item[0].Value <long>()); _result.Add(_trade); } return(_result.ToArray()); }
public override KLine[] GetKLines(string _pair, KLineType _type, params string[] _values) { string _typeText = ""; switch (_type) { case KLineType.M1: _typeText = "M1"; break; case KLineType.M5: _typeText = "M5"; break; case KLineType.M15: _typeText = "M15"; break; case KLineType.M30: _typeText = "M30"; break; case KLineType.H1: _typeText = "H1"; break; case KLineType.H4: _typeText = "H4"; break; case KLineType.H6: _typeText = "H6"; break; case KLineType.D1: _typeText = "D1"; break; case KLineType.D7: _typeText = "W1"; break; case KLineType.MM: _typeText = "WN"; break; default: throw new Exception($"KLine type:{_type.ToString()} not supported."); } string _url = $"/v2/market/candles/{_typeText}/{_pair}"; if (_values.Length > 0) { _url += $"?limit={_values[0]}"; } if (_values.Length > 1) { _url += $"&before={_values[1]}"; } JToken _token = base.HttpCall(HttpCallMethod.Get, "GET", _url); if (_token == null) { return(null); } IList <KLine> _result = new List <KLine>(); JArray _trades = _token.Value <JArray>(); foreach (JToken _item in _trades) { KLine _line = new KLine(); _line.DateTime = DateTimePlus.JSTime2DateTime(_item["id"].Value <long>() / 1000); _line.Pair = _pair; _line.Open = _item["open"].Value <decimal>(); _line.Close = _item["close"].Value <decimal>(); _line.High = _item["high"].Value <decimal>(); _line.Low = _item["low"].Value <decimal>(); _line.Count = _item["count"].Value <decimal>(); _line.Volume = _item["base_vol"].Value <decimal>(); _line.Volume2 = _item["quote_vol"].Value <decimal>(); _result.Add(_line); } return(_result.ToArray()); }
/// <summary> /// GetKLines /// </summary> /// <param name="_pair"></param> /// <param name="_type"></param> /// <param name="_values">0:limit 1:sort 2:start 3:end</param> /// <returns></returns> public override KLine[] GetKLines(string _pair, KLineType _type, params string[] _values) { string _typeText = ""; switch (_type) { case KLineType.M1: _typeText = "1m"; break; case KLineType.M5: _typeText = "5m"; break; case KLineType.M15: _typeText = "15m"; break; case KLineType.M30: _typeText = "30m"; break; case KLineType.H1: _typeText = "1h"; break; case KLineType.H6: _typeText = "6h"; break; case KLineType.H12: _typeText = "12h"; break; case KLineType.D1: _typeText = "1D"; break; case KLineType.D7: _typeText = "7D"; break; case KLineType.D14: _typeText = "14D"; break; case KLineType.MM: _typeText = "1M"; break; default: throw new Exception($"KLine type:{_type.ToString()} not supported."); } string _url = $"/v2/candles/trade:{_typeText}:t{_pair.ToUpper()}/hist"; if (_values.Length > 0) { _url += $"?limit={_values[0]}"; } if (_values.Length > 1) { _url += $"&sort={_values[1]}"; } if (_values.Length > 2) { _url += $"&start={_values[2]}"; } if (_values.Length > 4) { _url += $"&end={_values[3]}"; } JToken _token = base.HttpCall(HttpCallMethod.Get, "GET", _url); if (_token == null) { return(null); } IList <KLine> _result = new List <KLine>(); JArray _trades = _token.Value <JArray>(); foreach (JToken _item in _trades) { KLine _line = new KLine(); _line.DateTime = DateTimePlus.JSTime2DateTime(_item[0].Value <long>() / 1000); _line.Pair = _pair; _line.Open = _item[1].Value <decimal>(); _line.Close = _item[2].Value <decimal>(); _line.High = _item[3].Value <decimal>(); _line.Low = _item[4].Value <decimal>(); _line.Volume = _item[5].Value <decimal>(); _result.Add(_line); } return(_result.ToArray()); }
/// <summary> /// /// </summary> /// <param name="_pair"></param> /// <param name="_type"></param> /// <param name="_values">0:size</param> /// <returns></returns> public override KLine[] GetKLines(string _pair, KLineType _type, params string[] _values) { string _typeText = ""; switch (_type) { case KLineType.M1: _typeText = "1min"; break; case KLineType.M5: _typeText = "5min"; break; case KLineType.M15: _typeText = "15min"; break; case KLineType.M30: _typeText = "30min"; break; case KLineType.H1: _typeText = "60min"; break; case KLineType.D1: _typeText = "1day"; break; case KLineType.D7: _typeText = "1week"; break; case KLineType.MM: _typeText = "1mon"; break; case KLineType.YY: _typeText = "1year"; break; default: throw new Exception($"KLine type:{_type.ToString()} not supported."); } string _url = $" /market/history/kline?symbol={_pair}&period={_typeText}"; if (_values.Length > 0) { _url += $"&size={_values[0]}"; } JToken _token = base.HttpCall(HttpCallMethod.Get, "GET", _url); if (_token == null) { return(null); } IList <KLine> _result = new List <KLine>(); JArray _trades = _token["data"].Value <JArray>(); foreach (JToken _item in _trades) { KLine _line = new KLine(); _line.DateTime = DateTimePlus.JSTime2DateTime(_token["id"].Value <long>() / 1000); _line.Pair = _pair; _line.Open = _item["open"].Value <decimal>(); _line.Close = _item["close"].Value <decimal>(); _line.High = _item["high"].Value <decimal>(); _line.Low = _item["low"].Value <decimal>(); _line.Count = _item["count"].Value <decimal>(); _line.Volume = _item["vol"].Value <decimal>(); _line.Volume2 = _item["amount"].Value <decimal>(); _result.Add(_line); } return(_result.ToArray()); }
public override KLine[] GetKLines(string _pair, KLineType _type, params string[] _values) { string _typeText = ""; switch (_type) { case KLineType.M1: _typeText = "1min"; break; case KLineType.M5: _typeText = "5min"; break; case KLineType.M15: _typeText = "15min"; break; case KLineType.M30: _typeText = "30min"; break; case KLineType.H1: _typeText = "1hour"; break; case KLineType.H4: _typeText = "4hour"; break; case KLineType.H6: _typeText = "6hour"; break; case KLineType.D1: _typeText = "1day"; break; case KLineType.D7: _typeText = "1week"; break; default: throw new Exception($"KLine type:{_type.ToString()} not supported."); } string _url = $"/v1/market/kline?market={_pair}&type={_typeText}"; if (_values.Length > 0) { _url += $"?limit={_values[0]}"; } if (_values.Length > 1) { _url += $"&before={_values[1]}"; } JToken _token = base.HttpCall(HttpCallMethod.Get, "GET", _url); if (_token == null) { return(null); } IList <KLine> _result = new List <KLine>(); JArray _trades = _token.Value <JArray>(); foreach (JToken _item in _trades) { KLine _line = new KLine(); _line.DateTime = DateTimePlus.JSTime2DateTime(_item[0].Value <long>()); _line.Pair = _pair; _line.Open = _item[1].Value <decimal>(); _line.Close = _item[2].Value <decimal>(); _line.High = _item[3].Value <decimal>(); _line.Low = _item[4].Value <decimal>(); _line.Volume = _item[5].Value <decimal>(); _line.Volume2 = _item[6].Value <decimal>(); _result.Add(_line); } return(_result.ToArray()); }