public override void Connect()
        {
            _publicKey = ((ServerParameterString)ServerParameters[0]).Value;
            _secretKey = ((ServerParameterPassword)ServerParameters[1]).Value;

            _urlBuilder        = new PublicUrlBuilder(_host);
            _privateUriBuilder = new PrivateUrlBuilder(_publicKey, _secretKey, _host);

            _cancelTokenSource = new CancellationTokenSource();

            StartMessageReader();

            StartMarketDataReader();

            _signer = new Signer(_secretKey);

            _wsSource = new WsSource("wss://" + _host + _path);
            _wsSource.MessageEvent  += WsSourceOnMessageEvent;
            _wsSource.ByteDataEvent += WsSourceOnByteDataEvent;
            _wsSource.Start();

            _marketDataSource = new WsSource("wss://" + _host + "/swap-ws");
            _marketDataSource.ByteDataEvent += MarketDataSourceOnMessageEvent;
            _marketDataSource.Start();
        }
Example #2
0
        private List <Trade> GetTrades(string security, DateTime endTime)
        {
            lock (_locker)
            {
                try
                {
                    var to = TimeManager.GetTimeStampSecondsToDateTime(endTime);

                    string timeStamp = TimeManager.GetUnixTimeStampSeconds().ToString();
                    var    headers   = new Dictionary <string, string>();
                    headers.Add("Timestamp", timeStamp);

                    RestRequestBuilder requestBuilder = new RestRequestBuilder();
                    requestBuilder.AddParam("contract", security);
                    requestBuilder.AddParam("limit", "1000");
                    requestBuilder.AddParam("to", to.ToString());

                    PublicUrlBuilder urlBuilder = new PublicUrlBuilder(_host, _path, _wallet);

                    var tradesJson = _requestREST.SendGetQuery("GET", "", urlBuilder.Build("/trades", requestBuilder), headers);

                    var tradesOut = JsonConvert.DeserializeObject <GfTrade[]>(tradesJson);

                    var oldTrades = CreateTradesFromJson(tradesOut);

                    return(oldTrades);
                }
                catch
                {
                    SendLogMessage(OsLocalization.Market.Message95 + security, LogMessageType.Error);

                    return(null);
                }
            }
        }
Example #3
0
        public void Build_NoRequestParameter_Success()
        {
            var builder = new PublicUrlBuilder("api.huobi.pro");

            string result = builder.Build("/common/symbols");

            Assert.Equal("https://api.huobi.pro/common/symbols", result);
        }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="host">the host that the client connects to</param>
 public CommonClient(string host = DEFAULT_HOST, ILogger logger = null)
 {
     _urlBuilder = new PublicUrlBuilder(host);
     if (logger != null && HttpRequest.logger != null)
     {
         HttpRequest.logger = logger;
     }
 }
Example #5
0
        public void Build_RequestParameter_Success()
        {
            var builder = new PublicUrlBuilder("api.huobi.pro");
            var request = new GetRequest()
                          .AddParam("symbol", "btcusdt")
                          .AddParam("period", "1min")
                          .AddParam("size", "1");

            string result = builder.Build("/market/history/kline", request);

            Assert.Equal("https://api.huobi.pro/market/history/kline?period=1min&size=1&symbol=btcusdt", result);
        }
Example #6
0
        private List <Candle> GetCandles(int oldInterval, string security, DateTime startTime, DateTime endTime)
        {
            lock (_locker)
            {
                try
                {
                    var needIntervalForQuery = CandlesCreator.DetermineAppropriateIntervalForRequest(oldInterval, _supportedIntervals, out var needInterval);

                    var from = TimeManager.GetTimeStampSecondsToDateTime(startTime);
                    var to   = TimeManager.GetTimeStampSecondsToDateTime(endTime);

                    string timeStamp = TimeManager.GetUnixTimeStampSeconds().ToString();
                    var    headers   = new Dictionary <string, string>();
                    headers.Add("Timestamp", timeStamp);

                    RestRequestBuilder requestBuilder = new RestRequestBuilder();
                    requestBuilder.AddParam("contract", security);
                    requestBuilder.AddParam("from", from.ToString());
                    requestBuilder.AddParam("to", to.ToString());
                    requestBuilder.AddParam("interval", needIntervalForQuery);

                    PublicUrlBuilder urlBuilder = new PublicUrlBuilder(_host, _path, _wallet);

                    var candlesJson = _requestREST.SendGetQuery("GET", "", urlBuilder.Build("/candlesticks", requestBuilder), headers);

                    var candlesOut = JsonConvert.DeserializeObject <GfCandle[]>(candlesJson);

                    var oldCandles = CreateCandlesFromJson(candlesOut);

                    if (oldInterval == needInterval)
                    {
                        return(oldCandles);
                    }

                    var newCandles = CandlesCreator.CreateCandlesRequiredInterval(needInterval, oldInterval, oldCandles);

                    return(newCandles);
                }
                catch
                {
                    SendLogMessage(OsLocalization.Market.Message95 + security, LogMessageType.Error);

                    return(null);
                }
            }
        }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="host">the host that the client connects to</param>
 public MarketClient(string host = DEFAULT_HOST)
 {
     _urlBuilder = new PublicUrlBuilder(host);
 }
Example #8
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="host">the host that the client connects to</param>
 public CommonClient(string host = DEFAULT_HOST)
 {
     _urlBuilder = new PublicUrlBuilder(host);
 }
Example #9
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="host">the host that the client connects to</param>
 public CommonClient(string host = Host.SPOT)
 {
     _urlBuilder = new PublicUrlBuilder(host);
 }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="host">the host that the client connects to</param>
 public MarketClient(string host = Host.FUTURES)
 {
     _urlBuilder = new PublicUrlBuilder(host);
 }
Example #11
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="host">the host that the client connects to</param>
 public MarketClient(string host = Host.SPOT)
 {
     _urlBuilder = new PublicUrlBuilder(host);
 }