Add mining historical recovery assistant
This commit is contained in:
@@ -166,6 +166,10 @@ final class Router
|
||||
$this->respond(['data' => $this->migrateLegacyFxRates($projectKey)], 201);
|
||||
}
|
||||
|
||||
if ($resource === 'historical-recovery-fx' && $method === 'POST') {
|
||||
$this->respond(['data' => $this->saveHistoricalRecoveryFx($projectKey, Http::input())], 201);
|
||||
}
|
||||
|
||||
if ($resource === 'bootstrap' && $method === 'GET') {
|
||||
$view = trim((string) ($_GET['view'] ?? 'overview'));
|
||||
$this->respond(['data' => $this->bootstrap($projectKey, $view)]);
|
||||
@@ -840,6 +844,43 @@ final class Router
|
||||
return $rows;
|
||||
}
|
||||
|
||||
private function saveHistoricalRecoveryFx(string $projectKey, array $input): array
|
||||
{
|
||||
$fxRepository = $this->sharedFxRatesRepository();
|
||||
if ($fxRepository === null) {
|
||||
throw new ApiException('Das Modul fx-rates ist nicht verfuegbar.', 422);
|
||||
}
|
||||
|
||||
$measuredAt = $this->requiredDateTime($input['measured_at'] ?? null, 'measured_at', $this->projectTimezone($projectKey));
|
||||
$dogeUsd = $this->requiredDecimal($input['doge_usd'] ?? null, 'doge_usd');
|
||||
$usdEur = $this->requiredDecimal($input['usd_eur'] ?? null, 'usd_eur');
|
||||
$existing = $fxRepository->findFetchByBaseAndFetchedAt('USD', $measuredAt);
|
||||
|
||||
if (is_array($existing) && is_numeric($existing['id'] ?? null)) {
|
||||
return [
|
||||
'fetch_id' => (int) $existing['id'],
|
||||
'reused' => true,
|
||||
'fetched_at' => $measuredAt,
|
||||
];
|
||||
}
|
||||
|
||||
$saved = $fxRepository->saveFetch(
|
||||
'USD',
|
||||
'coingecko+valutafx',
|
||||
substr($measuredAt, 0, 10),
|
||||
['DOGE' => $dogeUsd, 'EUR' => $usdEur],
|
||||
$measuredAt,
|
||||
'migration'
|
||||
);
|
||||
|
||||
return [
|
||||
'fetch_id' => is_numeric($saved['fetch']['id'] ?? null) ? (int) $saved['fetch']['id'] : null,
|
||||
'reused' => false,
|
||||
'fetched_at' => $measuredAt,
|
||||
'provider' => 'coingecko+valutafx',
|
||||
];
|
||||
}
|
||||
|
||||
private function offerBasisHistory(string $projectKey): array
|
||||
{
|
||||
return $this->repository()->listOfferBasisHistory($projectKey, 50);
|
||||
|
||||
Reference in New Issue
Block a user