mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-19 06:54:19 +01:00
Finish rate api
This commit is contained in:
@@ -33,10 +33,18 @@ namespace BTCPayServer.Controllers
|
|||||||
|
|
||||||
[Route("rates/{baseCurrency}")]
|
[Route("rates/{baseCurrency}")]
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[BitpayAPIConstraint]
|
public async Task<IActionResult> GetBaseCurrencyRates(string baseCurrency, string storeId)
|
||||||
public async Task<IActionResult> GetBaseCurrencyRates(string baseCurrency)
|
|
||||||
{
|
{
|
||||||
|
storeId = storeId ?? this.HttpContext.GetStoreData()?.Id;
|
||||||
var store = this.HttpContext.GetStoreData();
|
var store = this.HttpContext.GetStoreData();
|
||||||
|
if (store == null || store.Id != storeId)
|
||||||
|
store = await _StoreRepo.FindStore(storeId);
|
||||||
|
if (store == null)
|
||||||
|
{
|
||||||
|
var err = Json(new BitpayErrorsModel() { Error = "Store not found" });
|
||||||
|
err.StatusCode = 404;
|
||||||
|
return err;
|
||||||
|
}
|
||||||
var currencypairs = "";
|
var currencypairs = "";
|
||||||
var supportedMethods = store.GetSupportedPaymentMethods(_NetworkProvider);
|
var supportedMethods = store.GetSupportedPaymentMethods(_NetworkProvider);
|
||||||
|
|
||||||
@@ -46,6 +54,10 @@ namespace BTCPayServer.Controllers
|
|||||||
|
|
||||||
foreach (var currencyCode in currencyCodes)
|
foreach (var currencyCode in currencyCodes)
|
||||||
{
|
{
|
||||||
|
if (baseCurrency == currencyCode)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (!string.IsNullOrEmpty(currencypairs))
|
if (!string.IsNullOrEmpty(currencypairs))
|
||||||
{
|
{
|
||||||
currencypairs += ",";
|
currencypairs += ",";
|
||||||
@@ -56,13 +68,12 @@ namespace BTCPayServer.Controllers
|
|||||||
var rates = (result as JsonResult)?.Value as Rate[];
|
var rates = (result as JsonResult)?.Value as Rate[];
|
||||||
if (rates == null)
|
if (rates == null)
|
||||||
return result;
|
return result;
|
||||||
return Json(new DataWrapper<Rate>(rates.First()));
|
return Json(new DataWrapper<Rate[]>(rates));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
[Route("rates/{baseCurrency}/{currency}")]
|
[Route("rates/{baseCurrency}/{currency}")]
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[BitpayAPIConstraint]
|
|
||||||
public async Task<IActionResult> GetCurrencyPairRate(string baseCurrency, string currency, string storeId)
|
public async Task<IActionResult> GetCurrencyPairRate(string baseCurrency, string currency, string storeId)
|
||||||
{
|
{
|
||||||
storeId = storeId ?? this.HttpContext.GetStoreData()?.Id;
|
storeId = storeId ?? this.HttpContext.GetStoreData()?.Id;
|
||||||
@@ -156,6 +167,7 @@ namespace BTCPayServer.Controllers
|
|||||||
var fetching = _RateProviderFactory.FetchRates(pairs, rules);
|
var fetching = _RateProviderFactory.FetchRates(pairs, rules);
|
||||||
await Task.WhenAll(fetching.Select(f => f.Value).ToArray());
|
await Task.WhenAll(fetching.Select(f => f.Value).ToArray());
|
||||||
return Json(pairs
|
return Json(pairs
|
||||||
|
.AsParallel()
|
||||||
.Select(r => (Pair: r, Value: fetching[r].GetAwaiter().GetResult().Value))
|
.Select(r => (Pair: r, Value: fetching[r].GetAwaiter().GetResult().Value))
|
||||||
.Where(r => r.Value.HasValue)
|
.Where(r => r.Value.HasValue)
|
||||||
.Select(r =>
|
.Select(r =>
|
||||||
|
|||||||
Reference in New Issue
Block a user