예제 #1
0
        public async Task <CancelOrdersForGivenPairResponse> CancelOrdersForGivePair(SymbolPairs pair, EmptyPrivateRequest baseRequest)
        {
            string json = string.Empty;

            var client = new CexHttpClient();

            try
            {
                json = JsonConvert.SerializeObject(baseRequest);
            }
            catch (JsonException ex)
            {
                throw new JsonException(CexConstants.InvalidJsonException, ex);
            }

            var splittedPairs = pair.ToString().Split('_');

            using (HttpContent content = new StringContent(JsonConvert.SerializeObject(baseRequest)))
            {
                var responseObject = await client.CexPostAsync(CexConstants.CacelAllOrderWithPairsUrl(splittedPairs[0], splittedPairs[1]), content);

                var response = JsonConvert.DeserializeObject <CancelOrdersForGivenPairResponse>(responseObject.Item2);
                response.StatusCode = responseObject.Item1;

                return(response);
            }
        }
예제 #2
0
        public async Task <Tuple <HttpStatusCode, string> > GetOpenPositonsAsync(SymbolPairs pair)
        {
            var client = new CexHttpClient();

            var splittedPairs = pair.ToString().Split('_');

            var openPosition = new OpenPositionOrderRequest(_hmac)
            {
                Key = _credentials.ApiKey
            };

            using (HttpContent content = new StringContent(JsonConvert.SerializeObject(JsonConvert.SerializeObject(openPosition))))
            {
                return(await client.CexPostAsync(CexConstants.OpenPositionUrl(splittedPairs[0], splittedPairs[1]), content));
            }
        }
예제 #3
0
        public async Task <ClosePositionResponse> ClosePosition(SymbolPairs pair, ulong positionId)
        {
            var client = new CexHttpClient();

            var splittedPairs = pair.ToString().Split('_');

            var positionRequest = new PositionRequest(_apiSecret)
            {
                Key        = _credentials.ApiKey,
                PositionId = positionId
            };

            using (HttpContent content = new StringContent(JsonConvert.SerializeObject(JsonConvert.SerializeObject(positionRequest))))
            {
                var responseObject = await client.CexPostAsync(CexConstants.ClosePositionUrl(splittedPairs[0], splittedPairs[1]), content);

                var response = JsonConvert.DeserializeObject <ClosePositionResponse>(responseObject.Item2);
                response.StatusCode = responseObject.Item1;

                return(response);
            }
        }