Exemplo n.º 1
0
 private void _pingTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
 {
     if (_hwsClient != null || _hwsClient.State == WebSocketState.Open)
     {
         var sModel = new HotbitSubscribeModel();
         sModel.method  = "server.ping";
         sModel.@params = new List <object>();
         _hwsClient.Send(sModel.ToJson());
     }
 }
Exemplo n.º 2
0
        private void _hwsClient_Opened(object sender, EventArgs e)
        {
            if (this.SubscribeType == "DEPTH")
            {
                this.NeedAuth = false;
                var market = this.SubscribeSourceObject as string;

                var sModel = new HotbitSubscribeModel();
                sModel.method  = "depth.subscribe";
                sModel.@params = new List <object>()
                {
                    market, 30, 0
                };
                sModel.id = 777;

                this.SubModel = sModel;

                _hwsClient.Send(sModel.ToJson());
            }
            else if (this.SubscribeType == "PRICE")
            {
                this.NeedAuth = false;
                var market = this.SubscribeSourceObject as string;

                var sModel = new HotbitSubscribeModel();
                sModel.method  = "price.subscribe";
                sModel.@params = new List <object>();
                [email protected](market);
                sModel.id = 777;

                this.SubModel = sModel;
                _hwsClient.Send(sModel.ToJson());
            }
            else if (this.SubscribeType == "ORDER")
            {
                this.NeedAuth = true;
                var lstMarket = this.SubAttachment as List <string>;

                var req = new HotbitSubscribeModel
                {
                    method  = "order.subscribe",
                    @params = new List <object>(),
                    id      = SUB_REQ_ID
                };

                foreach (var s in lstMarket)
                {
                    [email protected](s);
                }

                var authModel = new AuthSubscribeModel();
                authModel.ApiKey    = this.ApiKey;
                authModel.SecretKey = this.SecretKey;
                authModel.reqList.Add(req);
                authModel.AuthModel = new HotbitSubscribeModel()
                {
                    method  = "server.auth",
                    @params = new List <object>()
                    {
                        this.ApiKey, GetSign(this.ApiKey, this.SecretKey)
                    },
                    id = SUB_AUTH_ID
                };

                this.SubModel = authModel;
                _hwsClient.Send(authModel.AuthModel.ToJson());
            }
            else if (this.SubscribeType == "ASSET")
            {
                this.NeedAuth = true;
                var lstToken = this.SubAttachment as List <string>;
                var req      = new HotbitSubscribeModel
                {
                    method  = "asset.query",
                    @params = new List <object>()
                };

                foreach (var s in lstToken)
                {
                    [email protected](s);
                }

                var req1 = new HotbitSubscribeModel
                {
                    method  = "asset.subscribe",
                    @params = new List <object>(),
                    id      = SUB_REQ_ID
                };

                foreach (var s in lstToken)
                {
                    [email protected](s);
                }

                var authModel = new AuthSubscribeModel();
                authModel.ApiKey    = this.ApiKey;
                authModel.SecretKey = this.SecretKey;
                authModel.req       = req;
                authModel.reqList.Add(req);
                authModel.reqList.Add(req1);
                authModel.AuthModel = new HotbitSubscribeModel()
                {
                    method  = "server.auth",
                    @params = new List <object>()
                    {
                        this.ApiKey, GetSign(this.ApiKey, this.SecretKey)
                    },
                    id = SUB_AUTH_ID
                };

                this.SubModel = authModel;
                _hwsClient.Send(authModel.AuthModel.ToJson());
            }
        }