/// <inheritdoc />
        public async Task <WebCallResult <Dictionary <string, CoinExBalance> > > GetBalancesAsync(CancellationToken ct = default)
        {
            var result = await _baseClient.Execute <Dictionary <string, CoinExBalance> >(_baseClient.GetUrl(AccountInfoEndpoint), HttpMethod.Get, ct, null, true).ConfigureAwait(false);

            if (result)
            {
                foreach (var b in result.Data)
                {
                    b.Value.Asset = b.Key;
                }
            }

            return(result);
        }
Exemple #2
0
        /// <inheritdoc />
        public async Task <WebCallResult <CoinExOrder> > PlaceOrderAsync(
            string symbol,
            OrderSide side,
            OrderType type,
            decimal quantity,

            decimal?price           = null,
            decimal?stopPrice       = null,
            bool?immediateOrCancel  = null,
            OrderOption?orderOption = null,
            string?clientOrderId    = null,
            string?sourceId         = null,
            CancellationToken ct    = default)
        {
            symbol.ValidateCoinExSymbol();

            var endpoint = "";

            if (type == OrderType.Limit)
            {
                endpoint = PlaceLimitOrderEndpoint;
            }
            else if (type == OrderType.Market)
            {
                endpoint = PlaceMarketOrderEndpoint;
            }
            else if (type == OrderType.StopLimit)
            {
                endpoint = PlaceStopLimitOrderEndpoint;
            }
            else if (type == OrderType.StopMarket)
            {
                endpoint = PlaceStopMarketOrderEndpoint;
            }

            if (immediateOrCancel == true)
            {
                if (type != OrderType.Limit)
                {
                    throw new ArgumentException("ImmediateOrCancel only valid for limit orders");
                }

                endpoint = PlaceImmediateOrCancelOrderEndpoint;
            }

            var parameters = new Dictionary <string, object>
            {
                { "market", symbol },
                { "type", JsonConvert.SerializeObject(side, new OrderSideConverter(false)) },
                { "amount", quantity.ToString(CultureInfo.InvariantCulture) }
            };

            parameters.AddOptionalParameter("price", price?.ToString(CultureInfo.InvariantCulture));
            parameters.AddOptionalParameter("option", orderOption.HasValue ? JsonConvert.SerializeObject(orderOption, new OrderOptionConverter(false)) : null);
            parameters.AddOptionalParameter("stopPrice", stopPrice?.ToString(CultureInfo.InvariantCulture));
            parameters.AddOptionalParameter("client_id", clientOrderId);
            parameters.AddOptionalParameter("source_id", sourceId);

            var result = await _baseClient.Execute <CoinExOrder>(_baseClient.GetUrl(endpoint), HttpMethod.Post, ct, parameters, true).ConfigureAwait(false);

            if (result)
            {
                _baseClient.InvokeOrderPlaced(new OrderId {
                    SourceObject = result.Data, Id = result.Data.Id.ToString(CultureInfo.InvariantCulture)
                });
            }

            return(result);
        }
Exemple #3
0
 /// <inheritdoc />
 public async Task <WebCallResult <IEnumerable <string> > > GetSymbolsAsync(CancellationToken ct = default)
 {
     return(await _baseClient.Execute <IEnumerable <string> >(_baseClient.GetUrl(MarketListEndpoint), HttpMethod.Get, ct).ConfigureAwait(false));
 }