Exemple #1
0
        /// <summary>
        /// Retrieve the candlestick charts of mark price. This endpoint can retrieve the latest 1,440 data entries. Charts are returned in groups based on the requested bar.
        /// </summary>
        /// <param name="instrumentId">Instrument ID</param>
        /// <param name="period">Bar size, the default is 1m</param>
        /// <param name="after">Pagination of data to return records earlier than the requested ts, Unix timestamp format in milliseconds, e.g. 1597026383085</param>
        /// <param name="before">Pagination of data to return records newer than the requested ts, Unix timestamp format in milliseconds, e.g. 1597026383085</param>
        /// <param name="limit">Number of results per request. The maximum is 100; the default is 100.</param>
        /// <param name="ct">Cancellation Token</param>
        /// <returns></returns>
        public virtual async Task <WebCallResult <IEnumerable <OkexCandlestick> > > GetMarkPriceCandlesticks_Async(string instrumentId, OkexPeriod period, long?after = null, long?before = null, int limit = 100, CancellationToken ct = default)
        {
            if (limit < 1 || limit > 100)
            {
                throw new ArgumentException("Limit can be between 1-100.");
            }

            var parameters = new Dictionary <string, object>
            {
                { "instId", instrumentId },
                { "bar", JsonConvert.SerializeObject(period, new PeriodConverter(false)) },
            };

            parameters.AddOptionalParameter("after", after?.ToString());
            parameters.AddOptionalParameter("before", before?.ToString());
            parameters.AddOptionalParameter("limit", limit.ToString());

            var result = await SendRequestAsync <OkexRestApiResponse <IEnumerable <OkexCandlestick> > >(GetUrl(Endpoints_V5_Market_MarkPriceCandles), HttpMethod.Get, ct, parameters).ConfigureAwait(false);

            if (!result.Success)
            {
                return(WebCallResult <IEnumerable <OkexCandlestick> > .CreateErrorResult(result.ResponseStatusCode, result.ResponseHeaders, result.Error));
            }
            if (result.Data.ErrorCode > 0)
            {
                return(WebCallResult <IEnumerable <OkexCandlestick> > .CreateErrorResult(result.ResponseStatusCode, result.ResponseHeaders, new ServerError(result.Data.ErrorCode, result.Data.ErrorMessage, result.Data.Data)));
            }

            foreach (var candle in result.Data.Data)
            {
                candle.Instrument = instrumentId;
            }
            return(new WebCallResult <IEnumerable <OkexCandlestick> >(result.ResponseStatusCode, result.ResponseHeaders, result.Data.Data, null));
        }
Exemple #2
0
        /// <summary>
        /// Retrieve the estimated delivery price, which will only have a return value one hour before the delivery/exercise.
        /// </summary>
        /// <param name="instrumentType">Instrument Type</param>
        /// <param name="underlying">Underlying</param>
        /// <param name="after">Pagination of data to return records earlier than the requested ts, Unix timestamp format in milliseconds, e.g. 1597026383085</param>
        /// <param name="before">Pagination of data to return records newer than the requested ts, Unix timestamp format in milliseconds, e.g. 1597026383085</param>
        /// <param name="limit">Number of results per request. The maximum is 100; the default is 100.</param>
        /// <param name="ct">Cancellation Token</param>
        /// <returns></returns>
        public virtual async Task <WebCallResult <IEnumerable <OkexDeliveryExerciseHistory> > > GetDeliveryExerciseHistory_Async(OkexInstrumentType instrumentType, string underlying, long?after = null, long?before = null, int limit = 100, CancellationToken ct = default)
        {
            if (instrumentType.IsNotIn(OkexInstrumentType.Futures, OkexInstrumentType.Option))
            {
                throw new ArgumentException("Instrument Type can be only Futures or Option.");
            }

            if (limit < 1 || limit > 100)
            {
                throw new ArgumentException("Limit can be between 1-100.");
            }

            var parameters = new Dictionary <string, object>
            {
                { "instType", JsonConvert.SerializeObject(instrumentType, new InstrumentTypeConverter(false)) },
                { "uly", underlying },
            };

            parameters.AddOptionalParameter("after", after?.ToString());
            parameters.AddOptionalParameter("before", before?.ToString());
            parameters.AddOptionalParameter("limit", limit.ToString());

            var result = await SendRequestAsync <OkexRestApiResponse <IEnumerable <OkexDeliveryExerciseHistory> > >(GetUrl(Endpoints_V5_Public_DeliveryExerciseHistory), HttpMethod.Get, ct, parameters).ConfigureAwait(false);

            if (!result.Success)
            {
                return(WebCallResult <IEnumerable <OkexDeliveryExerciseHistory> > .CreateErrorResult(result.ResponseStatusCode, result.ResponseHeaders, result.Error));
            }
            if (result.Data.ErrorCode > 0)
            {
                return(WebCallResult <IEnumerable <OkexDeliveryExerciseHistory> > .CreateErrorResult(result.ResponseStatusCode, result.ResponseHeaders, new ServerError(result.Data.ErrorCode, result.Data.ErrorMessage, result.Data.Data)));
            }

            return(new WebCallResult <IEnumerable <OkexDeliveryExerciseHistory> >(result.ResponseStatusCode, result.ResponseHeaders, result.Data.Data, null));
        }
Exemple #3
0
        /// <summary>
        /// Retrieve a instrument is order book.
        /// </summary>
        /// <param name="instrumentId">Instrument ID</param>
        /// <param name="depth">Order book depth per side. Maximum 400, e.g. 400 bids + 400 asks. Default returns to 1 depth data</param>
        /// <param name="ct">Cancellation Token</param>
        /// <returns></returns>
        public virtual async Task <WebCallResult <OkexOrderBook> > GetOrderBook_Async(string instrumentId, int depth = 1, CancellationToken ct = default)
        {
            if (depth < 1 || depth > 400)
            {
                throw new ArgumentException("Depth can be between 1-400.");
            }

            var parameters = new Dictionary <string, object>
            {
                { "instId", instrumentId },
                { "sz", depth },
            };

            var result = await SendRequestAsync <OkexRestApiResponse <IEnumerable <OkexOrderBook> > >(GetUrl(Endpoints_V5_Market_Books), HttpMethod.Get, ct, parameters).ConfigureAwait(false);

            if (!result.Success || result.Data.Data.Count() == 0)
            {
                return(WebCallResult <OkexOrderBook> .CreateErrorResult(result.ResponseStatusCode, result.ResponseHeaders, result.Error));
            }
            if (result.Data.ErrorCode > 0)
            {
                return(WebCallResult <OkexOrderBook> .CreateErrorResult(result.ResponseStatusCode, result.ResponseHeaders, new ServerError(result.Data.ErrorCode, result.Data.ErrorMessage, result.Data.Data)));
            }

            var orderbook = result.Data.Data.FirstOrDefault();

            orderbook.Instrument = instrumentId;
            return(new WebCallResult <OkexOrderBook>(result.ResponseStatusCode, result.ResponseHeaders, orderbook, null));
        }
Exemple #4
0
        /// <summary>
        /// Retrieve mark price.
        /// We set the mark price based on the SPOT index and at a reasonable basis to prevent individual users from manipulating the market and causing the contract price to fluctuate.
        /// </summary>
        /// <param name="instrumentType">Instrument Type</param>
        /// <param name="underlying">Underlying</param>
        /// <param name="instrumentId">Instrument ID</param>
        /// <param name="ct">Cancellation Token</param>
        /// <returns></returns>
        public virtual async Task <WebCallResult <IEnumerable <OkexMarkPrice> > > GetMarkPrices_Async(OkexInstrumentType instrumentType, string underlying = null, string instrumentId = null, CancellationToken ct = default)
        {
            if (instrumentType.IsNotIn(OkexInstrumentType.Margin, OkexInstrumentType.Futures, OkexInstrumentType.Option, OkexInstrumentType.Swap))
            {
                throw new ArgumentException("Instrument Type can be only Margin, Futures, Option or Swap.");
            }

            var parameters = new Dictionary <string, object>
            {
                { "instType", JsonConvert.SerializeObject(instrumentType, new InstrumentTypeConverter(false)) },
            };

            parameters.AddOptionalParameter("uly", underlying);
            parameters.AddOptionalParameter("instId", instrumentId);

            var result = await SendRequestAsync <OkexRestApiResponse <IEnumerable <OkexMarkPrice> > >(GetUrl(Endpoints_V5_Public_MarkPrice), HttpMethod.Get, ct, parameters).ConfigureAwait(false);

            if (!result.Success)
            {
                return(WebCallResult <IEnumerable <OkexMarkPrice> > .CreateErrorResult(result.ResponseStatusCode, result.ResponseHeaders, result.Error));
            }
            if (result.Data.ErrorCode > 0)
            {
                return(WebCallResult <IEnumerable <OkexMarkPrice> > .CreateErrorResult(result.ResponseStatusCode, result.ResponseHeaders, new ServerError(result.Data.ErrorCode, result.Data.ErrorMessage, result.Data.Data)));
            }

            return(new WebCallResult <IEnumerable <OkexMarkPrice> >(result.ResponseStatusCode, result.ResponseHeaders, result.Data.Data, null));
        }
        /// <summary>
        /// Used to make a withdrawal via Lightning. Maximum withdrawal amount is 0.1 BTC, minimum amount is 0.000001 BTC. Rolling 24 hour limit of 1 BTC.
        /// </summary>
        /// <param name="currency">Currency</param>
        /// <param name="invoice">Invoice text</param>
        /// <param name="password">fund password</param>
        /// <param name="ct">Cancellation Token</param>
        /// <returns></returns>
        public virtual async Task <WebCallResult <OkexLightningWithdrawal> > GetLightningWithdrawals_Async(
            string currency,
            string invoice,
            string password,
            CancellationToken ct = default)
        {
            var parameters = new Dictionary <string, object>
            {
                { "ccy", currency },
                { "invoice", invoice },
                { "pwd", password },
            };

            var result = await SendRequestAsync <OkexRestApiResponse <IEnumerable <OkexLightningWithdrawal> > >(GetUrl(Endpoints_V5_Asset_WithdrawalLightning), HttpMethod.Get, ct, parameters, true).ConfigureAwait(false);

            if (!result.Success)
            {
                return(WebCallResult <OkexLightningWithdrawal> .CreateErrorResult(result.ResponseStatusCode, result.ResponseHeaders, result.Error));
            }
            if (result.Data.ErrorCode > 0)
            {
                return(WebCallResult <OkexLightningWithdrawal> .CreateErrorResult(result.ResponseStatusCode, result.ResponseHeaders, new ServerError(result.Data.ErrorCode, result.Data.ErrorMessage, result.Data.Data)));
            }

            return(new WebCallResult <OkexLightningWithdrawal>(result.ResponseStatusCode, result.ResponseHeaders, result.Data.Data.FirstOrDefault(), null));
        }
        /// <summary>
        /// only 100 invoices can be generated within a 24 hour period.
        /// </summary>
        /// <param name="currency">Currency</param>
        /// <param name="amount">deposit amount between 0.000001 - 0.1</param>
        /// <param name="account">Receiving account</param>
        /// <param name="ct">Cancellation Token</param>
        /// <returns></returns>
        public virtual async Task <WebCallResult <IEnumerable <OkexLightningDeposit> > > GetLightningDeposits_Async(
            string currency,
            decimal amount,
            OkexLightningDepositAccount?account = null,
            CancellationToken ct = default)
        {
            var parameters = new Dictionary <string, object>
            {
                { "ccy", currency },
                { "amt", amount.ToString(OkexGlobals.OkexCultureInfo) },
            };

            if (account.HasValue)
            {
                parameters.AddOptionalParameter("to", JsonConvert.SerializeObject(account, new LightningDepositAccountConverter(false)));
            }

            var result = await SendRequestAsync <OkexRestApiResponse <IEnumerable <OkexLightningDeposit> > >(GetUrl(Endpoints_V5_Asset_DepositLightning), HttpMethod.Get, ct, parameters, true).ConfigureAwait(false);

            if (!result.Success)
            {
                return(WebCallResult <IEnumerable <OkexLightningDeposit> > .CreateErrorResult(result.ResponseStatusCode, result.ResponseHeaders, result.Error));
            }
            if (result.Data.ErrorCode > 0)
            {
                return(WebCallResult <IEnumerable <OkexLightningDeposit> > .CreateErrorResult(result.ResponseStatusCode, result.ResponseHeaders, new ServerError(result.Data.ErrorCode, result.Data.ErrorMessage, result.Data.Data)));
            }

            return(new WebCallResult <IEnumerable <OkexLightningDeposit> >(result.ResponseStatusCode, result.ResponseHeaders, result.Data.Data, null));
        }
Exemple #7
0
        /// <summary>
        /// Retrieve the recent transactions of an instrument.
        /// </summary>
        /// <param name="instrumentId">Instrument ID</param>
        /// <param name="limit">Number of results per request. The maximum is 100; the default is 100.</param>
        /// <param name="ct">Cancellation Token</param>
        /// <returns></returns>
        public virtual async Task <WebCallResult <IEnumerable <OkexTrade> > > GetTrades_Async(string instrumentId, int limit = 100, CancellationToken ct = default)
        {
            if (limit < 1 || limit > 500)
            {
                throw new ArgumentException("Limit can be between 1-500.");
            }

            var parameters = new Dictionary <string, object>
            {
                { "instId", instrumentId },
            };

            parameters.AddOptionalParameter("limit", limit.ToString());

            var result = await SendRequestAsync <OkexRestApiResponse <IEnumerable <OkexTrade> > >(GetUrl(Endpoints_V5_Market_Trades), HttpMethod.Get, ct, parameters).ConfigureAwait(false);

            if (!result.Success)
            {
                return(WebCallResult <IEnumerable <OkexTrade> > .CreateErrorResult(result.ResponseStatusCode, result.ResponseHeaders, result.Error));
            }
            if (result.Data.ErrorCode > 0)
            {
                return(WebCallResult <IEnumerable <OkexTrade> > .CreateErrorResult(result.ResponseStatusCode, result.ResponseHeaders, new ServerError(result.Data.ErrorCode, result.Data.ErrorMessage, result.Data.Data)));
            }

            return(new WebCallResult <IEnumerable <OkexTrade> >(result.ResponseStatusCode, result.ResponseHeaders, result.Data.Data, null));
        }
Exemple #8
0
        /// <summary>
        /// applies to master accounts only
        /// </summary>
        /// <param name="password">Funds password of the master account</param>
        /// <param name="subAccountName">Sub Account Name</param>
        /// <param name="apiKey">API public key</param>
        /// <param name="ct">Cancellation Token</param>
        /// <returns></returns>
        public virtual async Task <WebCallResult <OkexSubAccountName> > DeleteSubAccountApiKey_Async(
            string password,
            string subAccountName,
            string apiKey,
            CancellationToken ct = default)
        {
            var parameters = new Dictionary <string, object>
            {
                { "pwd", password },
                { "subAcct", subAccountName },
                { "apiKey", apiKey },
            };

            var result = await SendRequestAsync <OkexRestApiResponse <IEnumerable <OkexSubAccountName> > >(GetUrl(Endpoints_V5_SubAccount_DeleteApiKey), HttpMethod.Post, ct, parameters, true).ConfigureAwait(false);

            if (!result.Success)
            {
                return(WebCallResult <OkexSubAccountName> .CreateErrorResult(result.ResponseStatusCode, result.ResponseHeaders, result.Error));
            }
            if (result.Data.ErrorCode > 0)
            {
                return(WebCallResult <OkexSubAccountName> .CreateErrorResult(result.ResponseStatusCode, result.ResponseHeaders, new ServerError(result.Data.ErrorCode, result.Data.ErrorMessage, result.Data.Data)));
            }

            return(new WebCallResult <OkexSubAccountName>(result.ResponseStatusCode, result.ResponseHeaders, result.Data.Data.FirstOrDefault(), null));
        }
Exemple #9
0
        /// <summary>
        /// Gets the withdrawal history
        /// </summary>
        /// <param name="asset">Filter by asset</param>
        /// <param name="status">Filter by status</param>
        /// <param name="startTime">Filter start time from</param>
        /// <param name="endTime">Filter end time till</param>
        /// <param name="receiveWindow">The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request</param>
        /// <param name="ct">Cancellation token</param>
        /// <returns>List of withdrawals</returns>
        public async Task <WebCallResult <IEnumerable <BinanceWithdrawal> > > GetWithdrawalHistoryAsync(string?asset = null, WithdrawalStatus?status = null, DateTime?startTime = null, DateTime?endTime = null, int?receiveWindow = null, CancellationToken ct = default)
        {
            var timestampResult = await _baseClient.CheckAutoTimestamp(ct).ConfigureAwait(false);

            if (!timestampResult)
            {
                return(new WebCallResult <IEnumerable <BinanceWithdrawal> >(timestampResult.ResponseStatusCode, timestampResult.ResponseHeaders, null, timestampResult.Error));
            }

            var parameters = new Dictionary <string, object>
            {
                { "timestamp", _baseClient.GetTimestamp() }
            };

            parameters.AddOptionalParameter("asset", asset);
            parameters.AddOptionalParameter("status", status != null ? JsonConvert.SerializeObject(status, new WithdrawalStatusConverter(false)) : null);
            parameters.AddOptionalParameter("startTime", startTime != null ? BinanceClient.ToUnixTimestamp(startTime.Value).ToString(CultureInfo.InvariantCulture) : null);
            parameters.AddOptionalParameter("endTime", endTime != null ? BinanceClient.ToUnixTimestamp(endTime.Value).ToString(CultureInfo.InvariantCulture) : null);
            parameters.AddOptionalParameter("recvWindow", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.DefaultReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture));

            var result = await _baseClient.SendRequestInternal <BinanceWithdrawalList>(_baseClient.GetUrlSpot(withdrawHistoryEndpoint, "wapi", "3"), HttpMethod.Get, ct, parameters, true).ConfigureAwait(false);

            if (!result || result.Data == null)
            {
                return(WebCallResult <IEnumerable <BinanceWithdrawal> > .CreateErrorResult(result.Error ?? new UnknownError("Unknown response")));
            }

            if (!result.Data.Success)
            {
                return(new WebCallResult <IEnumerable <BinanceWithdrawal> >(result.ResponseStatusCode, result.ResponseHeaders, null, _baseClient.ParseErrorResponseInternal(result.Data.Message)));
            }

            return(new WebCallResult <IEnumerable <BinanceWithdrawal> >(result.ResponseStatusCode, result.ResponseHeaders, result.Data.List, null));
        }
        /// <summary>
        /// Cancel Hashrate Resale Configuration
        /// </summary>
        /// <param name="configId">Mining id</param>
        /// <param name="userName">Mining account</param>
        /// <param name="ct">Resale hashrate h/s must be transferred (BTC is greater than 500000000000 ETH is greater than 500000)</param>
        /// <returns>Success</returns>
        public async Task <WebCallResult <bool> > PlaceHashrateResaleRequest(int configId, string userName, CancellationToken ct = default)
        {
            userName.ValidateNotNull(nameof(userName));

            var parameters = new Dictionary <string, object>()
            {
                { "configId", configId },
                { "userName", userName },
                { "timestamp", _baseClient.GetTimestamp() }
            };

            var result = await _baseClient.SendRequestInternal <BinanceResult <bool> >(_baseClient.GetUrlSpot(miningHashrateResaleCancel, "sapi", "1"), HttpMethod.Post, ct, parameters, true).ConfigureAwait(false);

            if (!result.Success)
            {
                return(WebCallResult <bool> .CreateErrorResult(result.ResponseStatusCode, result.ResponseHeaders, result.Error !));
            }

            if (result.Data?.Code != 0)
            {
                return(WebCallResult <bool> .CreateErrorResult(result.ResponseStatusCode, result.ResponseHeaders, new ServerError(result.Data !.Code, result.Data.Message)));
            }

            return(new WebCallResult <bool>(result.ResponseStatusCode, result.ResponseHeaders, result.Data.Data, null));
        }
        /// <summary>
        /// This is the taker volume for both buyers and sellers. This shows the influx and exit of funds in and out of {coin}.
        /// </summary>
        /// <param name="currency">Currency</param>
        /// <param name="instrumentType">Instrument Type</param>
        /// <param name="period">period, the default is 5m, e.g. [5m/1H/1D]</param>
        /// <param name="begin">begin, e.g. 1597026383085</param>
        /// <param name="end">end, e.g. 1597026383011</param>
        /// <param name="ct">Cancellation Token</param>
        /// <returns></returns>
        public virtual async Task <WebCallResult <IEnumerable <OkexTakerVolume> > > GetRubikTakerVolume_Async(
            string currency,
            OkexInstrumentType instrumentType,
            OkexPeriod period    = OkexPeriod.FiveMinutes,
            long?begin           = null,
            long?end             = null,
            CancellationToken ct = default)
        {
            var parameters = new Dictionary <string, object> {
                { "ccy", currency },
                { "instType", JsonConvert.SerializeObject(instrumentType, new InstrumentTypeConverter(false)) },
                { "period", JsonConvert.SerializeObject(period, new PeriodConverter(false)) },
            };

            parameters.AddOptionalParameter("begin", begin?.ToString(OkexGlobals.OkexCultureInfo));
            parameters.AddOptionalParameter("end", end?.ToString(OkexGlobals.OkexCultureInfo));

            var result = await SendRequestAsync <OkexRestApiResponse <IEnumerable <OkexTakerVolume> > >(GetUrl(Endpoints_V5_RubikStat_TakerVolume), HttpMethod.Get, ct, parameters).ConfigureAwait(false);

            if (!result.Success)
            {
                return(WebCallResult <IEnumerable <OkexTakerVolume> > .CreateErrorResult(result.ResponseStatusCode, result.ResponseHeaders, result.Error));
            }
            if (result.Data.ErrorCode > 0)
            {
                return(WebCallResult <IEnumerable <OkexTakerVolume> > .CreateErrorResult(result.ResponseStatusCode, result.ResponseHeaders, new ServerError(result.Data.ErrorCode, result.Data.ErrorMessage, result.Data.Data)));
            }

            return(new WebCallResult <IEnumerable <OkexTakerVolume> >(result.ResponseStatusCode, result.ResponseHeaders, result.Data.Data, null));
        }
        /// <summary>
        /// Withdrawal of tokens.
        /// </summary>
        /// <param name="currency">Currency</param>
        /// <param name="amount">Amount</param>
        /// <param name="destination">Withdrawal destination address</param>
        /// <param name="toAddress">Verified digital currency address, email or mobile number. Some digital currency addresses are formatted as 'address+tag', e.g. 'ARDOR-7JF3-8F2E-QUWZ-CAN7F:123456'</param>
        /// <param name="password">Trade password</param>
        /// <param name="fee">Transaction fee</param>
        /// <param name="chain">Chain name. There are multiple chains under some currencies, such as USDT has USDT-ERC20, USDT-TRC20, and USDT-Omni. If this parameter is not filled in because it is not available, it will default to the main chain.</param>
        /// <param name="ct">Cancellation Token</param>
        /// <returns></returns>
        public virtual async Task <WebCallResult <OkexWithdrawalResponse> > Withdraw_Async(
            string currency,
            decimal amount,
            OkexWithdrawalDestination destination,
            string toAddress,
            string password,
            decimal fee,
            string chain         = null,
            CancellationToken ct = default)
        {
            var parameters = new Dictionary <string, object> {
                { "ccy", currency },
                { "amt", amount.ToString(OkexGlobals.OkexCultureInfo) },
                { "dest", JsonConvert.SerializeObject(destination, new WithdrawalDestinationConverter(false)) },
                { "toAddr", toAddress },
                { "pwd", password },
                { "fee", fee.ToString(OkexGlobals.OkexCultureInfo) },
            };

            parameters.AddOptionalParameter("chain", chain);

            var result = await SendRequestAsync <OkexRestApiResponse <IEnumerable <OkexWithdrawalResponse> > >(GetUrl(Endpoints_V5_Asset_Withdrawal), HttpMethod.Post, ct, parameters, true).ConfigureAwait(false);

            if (!result.Success)
            {
                return(WebCallResult <OkexWithdrawalResponse> .CreateErrorResult(result.ResponseStatusCode, result.ResponseHeaders, result.Error));
            }
            if (result.Data.ErrorCode > 0)
            {
                return(WebCallResult <OkexWithdrawalResponse> .CreateErrorResult(result.ResponseStatusCode, result.ResponseHeaders, new ServerError(result.Data.ErrorCode, result.Data.ErrorMessage, result.Data.Data)));
            }

            return(new WebCallResult <OkexWithdrawalResponse>(result.ResponseStatusCode, result.ResponseHeaders, result.Data.Data.FirstOrDefault(), null));
        }
Exemple #13
0
        /// <summary>
        /// Places an order
        /// </summary>
        /// <param name="accountId">The account to place the order for</param>
        /// <param name="symbol">The symbol to place the order for</param>
        /// <param name="orderType">The type of the order</param>
        /// <param name="amount">The amount of the order</param>
        /// <param name="price">The price of the order. Should be omitted for market orders</param>
        /// <returns></returns>
        public async Task <WebCallResult <long> > PlaceOrderAsync(long accountId, string symbol, HuobiOrderType orderType, decimal amount, decimal?price = null)
        {
            if (orderType == HuobiOrderType.StopLimitBuy || orderType == HuobiOrderType.StopLimitSell)
            {
                return(WebCallResult <long> .CreateErrorResult(new ArgumentError("Stop limit orders not supported by API")));
            }

            var parameters = new Dictionary <string, object>
            {
                { "account-id", accountId },
                { "amount", amount },
                { "symbol", symbol },
                { "type", JsonConvert.SerializeObject(orderType, new OrderTypeConverter(false)) }
            };

            // If precision of the symbol = 1 (eg has to use whole amounts, 1,2,3 etc) Huobi doesn't except the .0 postfix (1.0) for amount
            // Issue at the Huobi side
            if (amount % 1 == 0)
            {
                parameters["amount"] = amount.ToString(CultureInfo.InvariantCulture);
            }

            parameters.AddOptionalParameter("price", price);
            var result = await ExecuteRequest <HuobiBasicResponse <long> >(GetUrl(PlaceOrderEndpoint, "1"), "POST", parameters, true).ConfigureAwait(false);

            return(new WebCallResult <long>(result.ResponseStatusCode, result.ResponseHeaders, result.Data?.Data ?? 0, result.Error));
        }
Exemple #14
0
        /// <summary>
        /// Gets miner list
        /// </summary>
        /// <param name="algorithm">Algorithm</param>
        /// <param name="userName">Mining account</param>
        /// <param name="page">Result page</param>
        /// <param name="sortAscending">Sort in ascending order</param>
        /// <param name="sortColumn">Column to sort by</param>
        /// <param name="workerStatus">Filter by status</param>
        /// <param name="ct">Cancellation token</param>
        /// <returns>Miner list</returns>
        public async Task <WebCallResult <BinanceMinerList> > GetMinerListAsync(string algorithm, string userName, int?page = null, bool?sortAscending = null, string?sortColumn = null, MinerStatus?workerStatus = null, CancellationToken ct = default)
        {
            algorithm.ValidateNotNull(nameof(algorithm));
            userName.ValidateNotNull(nameof(userName));

            var parameters = new Dictionary <string, object>()
            {
                { "algo", algorithm },
                { "userName", userName },
            };

            parameters.AddOptionalParameter("page", page?.ToString(CultureInfo.InvariantCulture));
            parameters.AddOptionalParameter("sortAscending", sortAscending == null ? null : sortAscending == true ? "1" : "0");
            parameters.AddOptionalParameter("sortColumn", sortColumn);
            parameters.AddOptionalParameter("workerStatus", workerStatus == null ? null : JsonConvert.SerializeObject(workerStatus, new MinerStatusConverter(false)));

            var result = await _baseClient.SendRequestInternal <BinanceResult <BinanceMinerList> >(_baseClient.GetUrlSpot(minerListEndpoint, "sapi", "1"), HttpMethod.Get, ct, parameters, true).ConfigureAwait(false);

            if (!result.Success)
            {
                return(WebCallResult <BinanceMinerList> .CreateErrorResult(result.ResponseStatusCode, result.ResponseHeaders, result.Error !));
            }

            if (result.Data?.Code != 0)
            {
                return(WebCallResult <BinanceMinerList> .CreateErrorResult(result.ResponseStatusCode, result.ResponseHeaders, new ServerError(result.Data !.Code, result.Data.Message)));
            }

            return(new WebCallResult <BinanceMinerList>(result.ResponseStatusCode, result.ResponseHeaders, result.Data.Data, null));
        }
Exemple #15
0
        /// <summary>
        /// Gets hash rate resale details
        /// </summary>
        /// <param name="configId">The mining id</param>
        /// <param name="userName">Mining account</param>
        /// <param name="page">Page</param>
        /// <param name="pageSize">Results per page</param>
        /// <param name="ct">Cancellation token</param>
        /// <returns>Resale details</returns>
        public async Task <WebCallResult <BinanceHashrateResaleDetails> > GetHashrateResaleDetailsAsync(int configId, string userName, int?page = null, int?pageSize = null, CancellationToken ct = default)
        {
            userName.ValidateNotNull(nameof(userName));

            var parameters = new Dictionary <string, object>()
            {
                { "configId", configId.ToString(CultureInfo.InvariantCulture) },
                { "userName", userName }
            };

            parameters.AddOptionalParameter("pageIndex", page?.ToString(CultureInfo.InvariantCulture));
            parameters.AddOptionalParameter("pageSize", pageSize?.ToString(CultureInfo.InvariantCulture));

            var result = await _baseClient.SendRequestInternal <BinanceResult <BinanceHashrateResaleDetails> >(_baseClient.GetUrlSpot(miningHashrateResaleDetailsEndpoint, "sapi", "1"), HttpMethod.Get, ct, parameters, true).ConfigureAwait(false);

            if (!result.Success)
            {
                return(WebCallResult <BinanceHashrateResaleDetails> .CreateErrorResult(result.ResponseStatusCode, result.ResponseHeaders, result.Error !));
            }

            if (result.Data?.Code != 0)
            {
                return(WebCallResult <BinanceHashrateResaleDetails> .CreateErrorResult(result.ResponseStatusCode, result.ResponseHeaders, new ServerError(result.Data !.Code, result.Data.Message)));
            }

            return(new WebCallResult <BinanceHashrateResaleDetails>(result.ResponseStatusCode, result.ResponseHeaders, result.Data.Data, null));
        }
Exemple #16
0
        /// <summary>
        /// Gets mining account list
        /// </summary>
        /// <param name="algorithm">Algorithm</param>
        /// <param name="userName">Mining account user name</param>
        /// <param name="ct">Cancellation token</param>
        /// <returns>Revenue list</returns>
        public async Task <WebCallResult <BinanceMiningAccount> > GetMiningAccountListAsync(string algorithm, string userName, CancellationToken ct = default)
        {
            algorithm.ValidateNotNull(nameof(algorithm));
            userName.ValidateNotNull(nameof(userName));

            var parameters = new Dictionary <string, object>()
            {
                { "algo", algorithm },
                { "userName", userName },
            };

            var result = await _baseClient.SendRequestInternal <BinanceResult <BinanceMiningAccount> >(_baseClient.GetUrlSpot(miningAccountListEndpoint, "sapi", "1"), HttpMethod.Get, ct, parameters, true).ConfigureAwait(false);

            if (!result.Success)
            {
                return(WebCallResult <BinanceMiningAccount> .CreateErrorResult(result.ResponseStatusCode, result.ResponseHeaders, result.Error !));
            }

            if (result.Data?.Code != 0)
            {
                return(WebCallResult <BinanceMiningAccount> .CreateErrorResult(result.ResponseStatusCode, result.ResponseHeaders, new ServerError(result.Data !.Code, result.Data.Message)));
            }

            return(new WebCallResult <BinanceMiningAccount>(result.ResponseStatusCode, result.ResponseHeaders, result.Data.Data, null));
        }
Exemple #17
0
        /// <summary>
        /// applies to master accounts only
        /// </summary>
        /// <param name="enable">Sub-account status,true: Normal ; false: Frozen</param>
        /// <param name="subAccountName">Sub Account Name</param>
        /// <param name="after">Pagination of data to return records earlier than the requested ts, Unix timestamp format in milliseconds, e.g. 1597026383085</param>
        /// <param name="before">Pagination of data to return records newer than the requested ts, Unix timestamp format in milliseconds, e.g. 1597026383085</param>
        /// <param name="limit">Number of results per request. The maximum is 100; the default is 100.</param>
        /// <param name="ct">Cancellation Token</param>
        /// <returns></returns>
        public virtual async Task <WebCallResult <IEnumerable <OkexSubAccount> > > GetSubAccounts_Async(
            bool?enable           = null,
            string subAccountName = null,
            long?after            = null,
            long?before           = null,
            int limit             = 100,
            CancellationToken ct  = default)
        {
            if (limit < 1 || limit > 100)
            {
                throw new ArgumentException("Limit can be between 1-100.");
            }

            var parameters = new Dictionary <string, object>();

            parameters.AddOptionalParameter("enable", enable);
            parameters.AddOptionalParameter("subAcct", subAccountName);
            parameters.AddOptionalParameter("after", after?.ToString(OkexGlobals.OkexCultureInfo));
            parameters.AddOptionalParameter("before", before?.ToString(OkexGlobals.OkexCultureInfo));
            parameters.AddOptionalParameter("limit", limit.ToString(OkexGlobals.OkexCultureInfo));

            var result = await SendRequestAsync <OkexRestApiResponse <IEnumerable <OkexSubAccount> > >(GetUrl(Endpoints_V5_SubAccount_List), HttpMethod.Get, ct, parameters, true).ConfigureAwait(false);

            if (!result.Success)
            {
                return(WebCallResult <IEnumerable <OkexSubAccount> > .CreateErrorResult(result.ResponseStatusCode, result.ResponseHeaders, result.Error));
            }
            if (result.Data.ErrorCode > 0)
            {
                return(WebCallResult <IEnumerable <OkexSubAccount> > .CreateErrorResult(result.ResponseStatusCode, result.ResponseHeaders, new ServerError(result.Data.ErrorCode, result.Data.ErrorMessage, result.Data.Data)));
            }

            return(new WebCallResult <IEnumerable <OkexSubAccount> >(result.ResponseStatusCode, result.ResponseHeaders, result.Data.Data, null));
        }
Exemple #18
0
        /// <summary>
        /// Hashrate resale request
        /// </summary>
        /// <param name="userName">Mining account</param>
        /// <param name="algorithm">Transfer algorithm</param>
        /// <param name="startDate">Resale start time</param>
        /// <param name="endDate">Resale end time</param>
        /// <param name="toUser">To mining account</param>
        /// <param name="hashRate">Results per page</param>
        /// <param name="ct">Resale hashrate h/s must be transferred (BTC is greater than 500000000000 ETH is greater than 500000)</param>
        /// <returns>Mining account</returns>
        public async Task <WebCallResult <int> > PlaceHashrateResaleRequest(string userName, string algorithm, DateTime startDate, DateTime endDate, string toUser, decimal hashRate, CancellationToken ct = default)
        {
            userName.ValidateNotNull(nameof(userName));
            algorithm.ValidateNotNull(nameof(algorithm));
            toUser.ValidateNotNull(nameof(toUser));

            var parameters = new Dictionary <string, object>()
            {
                { "userName", userName },
                { "algo", algorithm },
                { "startDate", JsonConvert.SerializeObject(startDate, new TimestampConverter()) },
                { "endDate", JsonConvert.SerializeObject(endDate, new TimestampConverter()) },
                { "toPoolUser", toUser },
                { "hashRate", hashRate },
            };

            var result = await _baseClient.SendRequestInternal <BinanceResult <int> >(_baseClient.GetUrlSpot(miningHashrateResaleRequest, "sapi", "1"), HttpMethod.Post, ct, parameters, true).ConfigureAwait(false);

            if (!result.Success)
            {
                return(WebCallResult <int> .CreateErrorResult(result.ResponseStatusCode, result.ResponseHeaders, result.Error !));
            }

            if (result.Data?.Code != 0)
            {
                return(WebCallResult <int> .CreateErrorResult(result.ResponseStatusCode, result.ResponseHeaders, new ServerError(result.Data !.Code, result.Data.Message)));
            }

            return(new WebCallResult <int>(result.ResponseStatusCode, result.ResponseHeaders, result.Data.Data, null));
        }
        /// <summary>
        /// This shows what option strikes are the most popular for each expiration.
        /// </summary>
        /// <param name="currency">Currency</param>
        /// <param name="expiryTime">expiry time (Format: YYYYMMdd, for example: "20210623")</param>
        /// <param name="period">period, the default is 8H. e.g. [8H/1D]</param>
        /// <param name="ct">Cancellation Token</param>
        /// <returns></returns>
        public virtual async Task <WebCallResult <IEnumerable <OkexInterestVolumeStrike> > > GetRubikInterestVolumeStrike_Async(
            string currency,
            string expiryTime,
            OkexPeriod period    = OkexPeriod.FiveMinutes,
            CancellationToken ct = default)
        {
            var parameters = new Dictionary <string, object> {
                { "ccy", currency },
                { "expTime", expiryTime },
                { "period", JsonConvert.SerializeObject(period, new PeriodConverter(false)) },
            };

            var result = await SendRequestAsync <OkexRestApiResponse <IEnumerable <OkexInterestVolumeStrike> > >(GetUrl(Endpoints_V5_RubikStat_OptionOpenInterestVolumeStrike), HttpMethod.Get, ct, parameters).ConfigureAwait(false);

            if (!result.Success)
            {
                return(WebCallResult <IEnumerable <OkexInterestVolumeStrike> > .CreateErrorResult(result.ResponseStatusCode, result.ResponseHeaders, result.Error));
            }
            if (result.Data.ErrorCode > 0)
            {
                return(WebCallResult <IEnumerable <OkexInterestVolumeStrike> > .CreateErrorResult(result.ResponseStatusCode, result.ResponseHeaders, new ServerError(result.Data.ErrorCode, result.Data.ErrorMessage, result.Data.Data)));
            }

            return(new WebCallResult <IEnumerable <OkexInterestVolumeStrike> >(result.ResponseStatusCode, result.ResponseHeaders, result.Data.Data, null));
        }
Exemple #20
0
        /// <summary>
        /// applies to master accounts only
        /// </summary>
        /// <param name="currency">Currency</param>
        /// <param name="amount">Amount</param>
        /// <param name="fromAccount">6:Funding Account 18:Unified Account</param>
        /// <param name="toAccount">6:Funding Account 18:Unified Account</param>
        /// <param name="fromSubAccountName">Sub-account name of the account that transfers funds out.</param>
        /// <param name="toSubAccountName">Sub-account name of the account that transfers funds in.</param>
        /// <param name="ct">Cancellation Token</param>
        /// <returns></returns>
        public virtual async Task <WebCallResult <OkexSubAccountTransfer> > TransferBetweenSubAccounts_Async(
            string currency,
            decimal amount,
            OkexAccount fromAccount,
            OkexAccount toAccount,
            string fromSubAccountName,
            string toSubAccountName,
            CancellationToken ct = default)
        {
            var parameters = new Dictionary <string, object>
            {
                { "ccy", currency },
                { "amt", amount.ToString(OkexGlobals.OkexCultureInfo) },
                { "from", JsonConvert.SerializeObject(fromAccount, new AccountConverter(false)) },
                { "to", JsonConvert.SerializeObject(toAccount, new AccountConverter(false)) },
                { "fromSubAccount", fromSubAccountName },
                { "toSubAccount", toSubAccountName },
            };

            var result = await SendRequestAsync <OkexRestApiResponse <IEnumerable <OkexSubAccountTransfer> > >(GetUrl(Endpoints_V5_SubAccount_Transfer), HttpMethod.Post, ct, parameters, true).ConfigureAwait(false);

            if (!result.Success)
            {
                return(WebCallResult <OkexSubAccountTransfer> .CreateErrorResult(result.ResponseStatusCode, result.ResponseHeaders, result.Error));
            }
            if (result.Data.ErrorCode > 0)
            {
                return(WebCallResult <OkexSubAccountTransfer> .CreateErrorResult(result.ResponseStatusCode, result.ResponseHeaders, new ServerError(result.Data.ErrorCode, result.Data.ErrorMessage, result.Data.Data)));
            }

            return(new WebCallResult <OkexSubAccountTransfer>(result.ResponseStatusCode, result.ResponseHeaders, result.Data.Data.FirstOrDefault(), null));
        }
        /// <summary>
        /// PiggyBank Purchase/Redemption
        /// </summary>
        /// <param name="currency">Currency</param>
        /// <param name="amount">Amount</param>
        /// <param name="side">Side</param>
        /// <param name="ct">Cancellation Token</param>
        /// <returns></returns>
        public virtual async Task <WebCallResult <OkexPiggyBankActionResponse> > PiggyBankAction_Async(
            string currency,
            decimal amount,
            OkexPiggyBankActionSide side,
            CancellationToken ct = default)
        {
            var parameters = new Dictionary <string, object> {
                { "ccy", currency },
                { "amt", amount.ToString(OkexGlobals.OkexCultureInfo) },
                { "side", JsonConvert.SerializeObject(side, new PiggyBankActionSideConverter(false)) },
            };

            var result = await SendRequestAsync <OkexRestApiResponse <IEnumerable <OkexPiggyBankActionResponse> > >(GetUrl(Endpoints_V5_Asset_PurchaseRedempt), HttpMethod.Post, ct, parameters, true).ConfigureAwait(false);

            if (!result.Success)
            {
                return(WebCallResult <OkexPiggyBankActionResponse> .CreateErrorResult(result.ResponseStatusCode, result.ResponseHeaders, result.Error));
            }
            if (result.Data.ErrorCode > 0)
            {
                return(WebCallResult <OkexPiggyBankActionResponse> .CreateErrorResult(result.ResponseStatusCode, result.ResponseHeaders, new ServerError(result.Data.ErrorCode, result.Data.ErrorMessage, result.Data.Data)));
            }

            return(new WebCallResult <OkexPiggyBankActionResponse>(result.ResponseStatusCode, result.ResponseHeaders, result.Data.Data.FirstOrDefault(), null));
        }
Exemple #22
0
        /// <summary>
        /// applies to master accounts only
        /// </summary>
        /// <param name="password">Funds password of the master account</param>
        /// <param name="subAccountName">Sub Account Name</param>
        /// <param name="apiKey">APIKey note</param>
        /// <param name="apiLabel">APIKey note</param>
        /// <param name="permission">APIKey access</param>
        /// <param name="ipAddresses">Link IP addresses, separate with commas if more than one. Support up to 20 IP addresses.</param>
        /// <param name="ct">Cancellation Token</param>
        /// <returns></returns>
        public virtual async Task <WebCallResult <OkexSubAccountApiKey> > ModifySubAccountApiKey_Async(
            string password,
            string subAccountName,
            string apiKey,
            string apiLabel,
            OkexApiPermission permission,
            string ipAddresses   = null,
            CancellationToken ct = default)
        {
            var parameters = new Dictionary <string, object>
            {
                { "pwd", password },
                { "subAcct", subAccountName },
                { "label", apiLabel },
                { "apiKey", apiKey },
                { "perm", JsonConvert.SerializeObject(permission, new ApiPermissionConverter(false)) },
            };

            parameters.AddOptionalParameter("ip", ipAddresses);

            var result = await SendRequestAsync <OkexRestApiResponse <IEnumerable <OkexSubAccountApiKey> > >(GetUrl(Endpoints_V5_SubAccount_ModifyApiKey), HttpMethod.Post, ct, parameters, true).ConfigureAwait(false);

            if (!result.Success)
            {
                return(WebCallResult <OkexSubAccountApiKey> .CreateErrorResult(result.ResponseStatusCode, result.ResponseHeaders, result.Error));
            }
            if (result.Data.ErrorCode > 0)
            {
                return(WebCallResult <OkexSubAccountApiKey> .CreateErrorResult(result.ResponseStatusCode, result.ResponseHeaders, new ServerError(result.Data.ErrorCode, result.Data.ErrorMessage, result.Data.Data)));
            }

            return(new WebCallResult <OkexSubAccountApiKey>(result.ResponseStatusCode, result.ResponseHeaders, result.Data.Data.FirstOrDefault(), null));
        }
Exemple #23
0
        /// <summary>
        /// Get other revenue list
        /// </summary>
        /// <param name="algorithm">Algorithm</param>
        /// <param name="userName">Mining account</param>
        /// <param name="page">Result page</param>
        /// <param name="pageSize">Results per page</param>
        /// <param name="coin">Coin</param>
        /// <param name="startDate">Start date</param>
        /// <param name="endDate">End date</param>
        /// <param name="ct">Cancellation token</param>
        /// <returns>Revenue list</returns>
        public async Task <WebCallResult <BinanceOtherRevenueList> > GetMiningOtherRevenueListAsync(string algorithm, string userName, string?coin = null, DateTime?startDate = null, DateTime?endDate = null, int?page = null, int?pageSize = null, CancellationToken ct = default)
        {
            algorithm.ValidateNotNull(nameof(algorithm));
            userName.ValidateNotNull(nameof(userName));

            var parameters = new Dictionary <string, object>()
            {
                { "algo", algorithm },
                { "userName", userName },
            };

            parameters.AddOptionalParameter("page", page?.ToString(CultureInfo.InvariantCulture));
            parameters.AddOptionalParameter("pageSize", pageSize?.ToString(CultureInfo.InvariantCulture));
            parameters.AddOptionalParameter("coin", coin);
            parameters.AddOptionalParameter("startDate", startDate.HasValue ? JsonConvert.SerializeObject(startDate.Value, new TimestampConverter()) : null);
            parameters.AddOptionalParameter("endDate", endDate.HasValue ? JsonConvert.SerializeObject(endDate.Value, new TimestampConverter()) : null);

            var result = await _baseClient.SendRequestInternal <BinanceResult <BinanceOtherRevenueList> >(_baseClient.GetUrlSpot(miningOtherRevenueEndpoint, "sapi", "1"), HttpMethod.Get, ct, parameters, true).ConfigureAwait(false);

            if (!result.Success)
            {
                return(WebCallResult <BinanceOtherRevenueList> .CreateErrorResult(result.ResponseStatusCode, result.ResponseHeaders, result.Error !));
            }

            if (result.Data?.Code != 0)
            {
                return(WebCallResult <BinanceOtherRevenueList> .CreateErrorResult(result.ResponseStatusCode, result.ResponseHeaders, new ServerError(result.Data !.Code, result.Data.Message)));
            }

            return(new WebCallResult <BinanceOtherRevenueList>(result.ResponseStatusCode, result.ResponseHeaders, result.Data.Data, null));
        }
Exemple #24
0
        /// <summary>
        /// Gets the market depth for a symbol
        /// </summary>
        /// <param name="symbol">The symbol to request for</param>
        /// <param name="mergeStep">The way the results will be merged together</param>
        /// <param name="limit">The depth of the book</param>
        /// <returns></returns>
        public async Task <WebCallResult <HuobiMarketDepth> > GetMarketDepthAsync(string symbol, int mergeStep, int?limit = null)
        {
            if (mergeStep < 0 || mergeStep > 5)
            {
                return(WebCallResult <HuobiMarketDepth> .CreateErrorResult(new ArgumentError("MergeStep should be between 0 and 5")));
            }

            if (limit.HasValue && limit != 5 && limit != 10 && limit != 20)
            {
                return(WebCallResult <HuobiMarketDepth> .CreateErrorResult(new ArgumentError("Limit should be one of: 5, 10, 20")));
            }

            var parameters = new Dictionary <string, object>
            {
                { "symbol", symbol },
                { "type", "step" + mergeStep }
            };

            parameters.AddOptionalParameter("depth", limit);

            var result = await ExecuteRequest <HuobiChannelResponse <HuobiMarketDepth> >(GetUrl(MarketDepthEndpoint), parameters : parameters, checkResult : false).ConfigureAwait(false);

            if (!result.Success)
            {
                return(WebCallResult <HuobiMarketDepth> .CreateErrorResult(result.ResponseStatusCode, result.ResponseHeaders, result.Error));
            }

            result.Data.Data.Timestamp = result.Data.Timestamp;
            return(new WebCallResult <HuobiMarketDepth>(result.ResponseStatusCode, result.ResponseHeaders, result.Data.Data, null));
        }
Exemple #25
0
        private WebCallResult <T> EvaluateError <T>(Error error)
        {
            if (ThrowThenErrorResponse)
            {
                throw new BitGoErrorException(error);
            }

            return(WebCallResult <T> .CreateErrorResult(error));
        }
Exemple #26
0
        private static WebCallResult <T> GetResult <T>(WebCallResult <CoinExApiResult <T> > result) where T : class
        {
            if (result.Error != null || result.Data == null)
            {
                return(WebCallResult <T> .CreateErrorResult(result.ResponseStatusCode, result.ResponseHeaders, result.Error));
            }

            return(new WebCallResult <T>(result.ResponseStatusCode, result.ResponseHeaders, result.Data.Data, null));
        }
Exemple #27
0
        /// <summary>
        /// Get the server time
        /// </summary>
        /// <returns>Server time</returns>
        public async Task <CallResult <DateTime> > GetServerTimeAsync()
        {
            var result = await Execute <KrakenServerTime>(GetUri("/0/public/Time")).ConfigureAwait(false);

            if (!result.Success)
            {
                return(WebCallResult <DateTime> .CreateErrorResult(result.Error));
            }
            return(new CallResult <DateTime>(result.Data.UnixTime, null));
        }
Exemple #28
0
        private static WebCallResult <T> GetResult <T>(WebCallResult <BittrexApiResult <T> > result) where T : class
        {
            if (result.Error != null || result.Data == null)
            {
                return(WebCallResult <T> .CreateErrorResult(result.ResponseStatusCode, result.ResponseHeaders, result.Error));
            }

            var messageEmpty = string.IsNullOrEmpty(result.Data.Message);

            return(new WebCallResult <T>(result.ResponseStatusCode, result.ResponseHeaders, !messageEmpty ? null: result.Data.Result, !messageEmpty ? new ServerError(result.Data.Message): null));
        }
Exemple #29
0
        async Task <WebCallResult <IEnumerable <ICommonRecentTrade> > > IExchangeClient.GetRecentTradesAsync(string symbol)
        {
            var tradesResult = await GetTradeHistoryAsync(symbol, null).ConfigureAwait(false);

            if (!tradesResult.Success)
            {
                return(WebCallResult <IEnumerable <ICommonRecentTrade> > .CreateErrorResult(tradesResult.ResponseStatusCode, tradesResult.ResponseHeaders, tradesResult.Error !));
            }

            return(tradesResult.As <IEnumerable <ICommonRecentTrade> >(tradesResult.Data?.Data));
        }
Exemple #30
0
        /// <summary>
        /// Gets a list of balances for a specific sub account
        /// </summary>
        /// <param name="subAccountId">The id of the sub account to get the balances for</param>
        /// <returns></returns>
        public async Task <WebCallResult <List <HuobiBalance> > > GetSubAccountBalancesAsync(long subAccountId)
        {
            var result = await ExecuteRequest <HuobiBasicResponse <List <HuobiAccountBalances> > >(GetUrl(FillPathParameter(GetSubAccountBalancesEndpoint, subAccountId.ToString()), "1"), signed : true).ConfigureAwait(false);

            if (!result.Success)
            {
                return(WebCallResult <List <HuobiBalance> > .CreateErrorResult(result.ResponseStatusCode, result.ResponseHeaders, result.Error));
            }

            return(new WebCallResult <List <HuobiBalance> >(result.ResponseStatusCode, result.ResponseHeaders, result.Data.Data[0].Data, result.Error));
        }