Ejemplo n.º 1
0
        public async Task <bool> CancelOrder(SymbolPairs pair, CancellationToken?cancellationToken = default(CancellationToken?))
        {
            var command = Command.CancelAll.ToString().Normalize() + pair.ToString().Normalize();
            await _client.PostDataAsync(command, null);

            return(true);
        }
Ejemplo n.º 2
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);
            }
        }
Ejemplo n.º 3
0
        public async Task <IEnumerable <Order> > GetOpenOrdersAsync(SymbolPairs pair, CancellationToken?cancellationToken = default(CancellationToken?))
        {
            var command = Command.GetOpenOrders.ToString().Normalize() + pair.ToString().Normalize();
            var json    = await _client.PostDataAsync(command, null);

            var orders = JsonConvert.DeserializeObject <IEnumerable <Order> >(json);

            return(orders);
        }
Ejemplo n.º 4
0
        public async Task <bool> ClosePosition(SymbolPairs pair, ulong positionId, CancellationToken?cancellationToken = default(CancellationToken?))
        {
            var parameters = new Dictionary <string, string>()
            {
                { "id", positionId.ToString() }
            };

            var command = Command.ClosePosition.ToString().Normalize() + pair.ToString().Normalize();
            await _client.PostDataAsync(command, parameters);

            return(true);
        }
Ejemplo n.º 5
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));
            }
        }
Ejemplo n.º 6
0
        public async Task <IEnumerable <Position> > GetOpenPositonsAsync(SymbolPairs pair, CancellationToken?cancellationToken = default(CancellationToken?))
        {
            var command = Command.GetOpenPositions.ToString().Normalize() + pair.ToString().Normalize();
            var json    = await _client.PostDataAsync(command, null);

            var jarr = JObject.Parse(json).Value <JArray>("data");

            IEnumerable <Position> positions = null;

            if (jarr.Count > 0)
            {
                positions = (IEnumerable <Position>)jarr;
            }

            return(positions);
        }
Ejemplo n.º 7
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);
            }
        }
Ejemplo n.º 8
0
 internal static string ToStringNormalized(this SymbolPairs value)
 {
     return(value.ToString().Replace('_', '/'));
 }