Beispiel #1
0
        private void WsClient_Login(String key, String secret, int ttl)
        {
            byte[] msg;

            protobuf.ws.LoginRequest message = new protobuf.ws.LoginRequest
            {
                ExpireControl = new protobuf.ws.RequestExpired
                {
                    Now = (long)(DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds,
                    Ttl = ttl
                },
                ApiKey = key
            };

            using (MemoryStream msgStream = new MemoryStream())
            {
                ProtoBuf.Serializer.Serialize(msgStream, message);
                msg = msgStream.ToArray();
            }
            byte[] sign = ComputeHash(secret, msg);
            var    meta = new protobuf.ws.WsRequestMetaData
            {
                RequestType = protobuf.ws.WsRequestMetaData.WsRequestMsgType.Login,
                Token       = "Login request",
                Sign        = sign
            };

            protobuf.ws.WsRequest request = new protobuf.ws.WsRequest
            {
                Meta = meta,
                Msg  = msg
            };

            sendRequest(request);
        }
Beispiel #2
0
        private void WsClient_Unsubscribe(protobuf.ws.UnsubscribeRequest.ChannelType type, String currencyPair)
        {
            protobuf.ws.UnsubscribeRequest message = new protobuf.ws.UnsubscribeRequest
            {
                channel_type = type,
                CurrencyPair = currencyPair
            };

            byte[] msg;

            using (MemoryStream msgStream = new MemoryStream())
            {
                ProtoBuf.Serializer.Serialize(msgStream, message);
                msg = msgStream.ToArray();
            };

            protobuf.ws.WsRequestMetaData meta = new protobuf.ws.WsRequestMetaData {
                RequestType = protobuf.ws.WsRequestMetaData.WsRequestMsgType.Unsubscribe
            };

            protobuf.ws.WsRequest request = new protobuf.ws.WsRequest {
                Meta = meta,
                Msg  = msg
            };

            sendRequest(request);
        }
Beispiel #3
0
        private void WsClient_SubscribePrivateTrades(String secret, int ttl)
        {
            byte[] msg;

            protobuf.ws.PrivateSubscribeTradeChannelRequest message = new protobuf.ws.PrivateSubscribeTradeChannelRequest()
            {
                ExpireControl = new protobuf.ws.RequestExpired
                {
                    Now = (long)(DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds,
                    Ttl = ttl
                }
            };

            using (MemoryStream msgStream = new MemoryStream())
            {
                ProtoBuf.Serializer.Serialize(msgStream, message);
                msg = msgStream.ToArray();
            }
            byte[] sign = ComputeHash(secret, msg);
            var    meta = new protobuf.ws.WsRequestMetaData
            {
                RequestType = protobuf.ws.WsRequestMetaData.WsRequestMsgType.PrivateSubscribeTrade,
                Token       = "Subscribe private trade channel request",
                Sign        = sign
            };

            protobuf.ws.WsRequest request = new protobuf.ws.WsRequest
            {
                Meta = meta,
                Msg  = msg
            };

            sendRequest(request);
        }
Beispiel #4
0
        //here you can make your trade decision

        private void sendRequest(protobuf.ws.WsRequest request)
        {
            using (var requestStream = new MemoryStream())
            {
                ProtoBuf.Serializer.Serialize(requestStream, request);
                ws.Send(requestStream.ToArray());
            }
        }
Beispiel #5
0
        private void WsClient_Subscribe(Params param)
        {
            byte[] msg;
            if (param is TickerParams)
            {
                TickerParams tickerParams = ((TickerParams)param);
                var          message      = new protobuf.ws.SubscribeTickerChannelRequest
                {
                    CurrencyPair = tickerParams.symbol
                };
                if (tickerParams.frequency != null)
                {
                    message.Frequency = (float)tickerParams.frequency;
                }

                using (MemoryStream msgStream = new MemoryStream())
                {
                    ProtoBuf.Serializer.Serialize(msgStream, message);
                    msg = msgStream.ToArray();
                }
            }
            else
            {
                throw new NotImplementedException();
            }
            var meta = new protobuf.ws.WsRequestMetaData
            {
                RequestType = protobuf.ws.WsRequestMetaData.WsRequestMsgType.SubscribeTicker
            };

            protobuf.ws.WsRequest request = new protobuf.ws.WsRequest
            {
                Meta = meta,
                Msg  = msg
            };

            sendRequest(request);
        }
Beispiel #6
0
        private void WsClient_Subscribe(Params param)
        {   // creating request
            protobuf.ws.WsRequestMetaData meta;
            protobuf.ws.WsRequestMetaData.WsRequestMsgType requestType;
            string token;

            byte[] msg;

            if (param is TickerParams)
            {
                TickerParams tickerParams = ((TickerParams)param);
                var          message      = new protobuf.ws.SubscribeTickerChannelRequest
                {
                    CurrencyPair = tickerParams.symbol
                };
                if (tickerParams.frequency != null)
                {
                    message.Frequency = (float)tickerParams.frequency;
                }

                using (MemoryStream msgStream = new MemoryStream())
                {
                    ProtoBuf.Serializer.Serialize(msgStream, message);
                    msg         = msgStream.ToArray();
                    requestType = protobuf.ws.WsRequestMetaData.WsRequestMsgType.SubscribeTicker;
                    token       = "Ticker_" + tickerParams.symbol + " channel";
                }
            }
            else if (param is TradeParams)
            {
                TradeParams tradeParams = ((TradeParams)param);
                var         message     = new protobuf.ws.SubscribeTradeChannelRequest
                {
                    CurrencyPair = tradeParams.symbol
                };

                using (MemoryStream msgStream = new MemoryStream())
                {
                    ProtoBuf.Serializer.Serialize(msgStream, message);
                    msg         = msgStream.ToArray();
                    requestType = protobuf.ws.WsRequestMetaData.WsRequestMsgType.SubscribeTrade;
                    token       = "Trade_" + tradeParams.symbol + " channel";
                }
            } //here you can make your trade decision
            else
            {
                throw new NotImplementedException();
            }

            meta = new protobuf.ws.WsRequestMetaData
            {
                RequestType = requestType,
                Token       = token
            };

            protobuf.ws.WsRequest request = new protobuf.ws.WsRequest
            {
                Meta = meta,
                Msg  = msg
            };

            sendRequest(request);
        }