Esempio n. 1
0
        public async Task PostOrder(BitMexLimitOrder order)
        {
            var urlPath = $"/{_baseApiPath}/order";
            var url     = $"{_domain}{urlPath}";

            dynamic payload = new
            {
                symbol   = order.Symbol,
                ordType  = "Limit",
                price    = BitMexPriceConverter.Convert(order.Price, order.Symbol),
                orderQty = order.Size,
                clOrdID  = order.OrderId,
                side     = order.Size > 0 ? "Buy" : "Sell",
            };

            string content = JsonConvert.SerializeObject(payload);

            using (var client = new HttpClient())
            {
                AddBitMexHeaders(client, HttpMethod.Post, urlPath, content);

                var response = await
                               client.PostAsync(url, new StringContent(content, Encoding.UTF8, "application/json")).ConfigureAwait(false);

                response.EnsureSuccessStatusCode();
            }
        }
Esempio n. 2
0
        public async Task PostOrders(List <BitMexLimitOrder> orders)
        {
            var urlPath = $"/{_baseApiPath}/order/bulk";
            var url     = $"{_domain}{urlPath}";

            var ordersPayload = new List <dynamic>();

            foreach (var order in orders)
            {
                ordersPayload.Add(new
                {
                    symbol         = order.Symbol,
                    ordType        = "Limit",
                    price          = BitMexPriceConverter.Convert(order.Price, order.Symbol),
                    simpleOrderQty = Math.Abs(order.Size),
                    clOrdID        = order.OrderId,
                    side           = order.Side.ToString(),
                });
            }

            var content = $"{{\"orders\": { JsonConvert.SerializeObject(ordersPayload)}}}";

            using (var client = new HttpClient())
            {
                AddBitMexHeaders(client, HttpMethod.Post, urlPath, content);

                var response = await
                               client.PostAsync(url, new StringContent(content, Encoding.UTF8, "application/json")).ConfigureAwait(false);

                if (!response.IsSuccessStatusCode)
                {
                    var message = await response.Content.ReadAsStringAsync();

                    _logger.Error($"Error while postng orders: {message}");
                }

                response.EnsureSuccessStatusCode();
            }
        }