This commit is contained in:
hackerESQ
2026-03-24 21:04:40 -05:00
parent e8997ecc3e
commit 23ed2e7155
@@ -68,31 +68,11 @@ class BinanceMarketData implements MarketDataInterface
} }
); );
$yearLow = cache()->remember(
'binance-low-'.$symbol,
1440,
function () use ($symbol) {
$this->createNewClient();
$response = $this->client
->baseUrl($this->apiBaseUrl)
->withQueryParameters([
'symbol' => $symbol,
'interval' => '1d',
'start' => now()->firstOfYear()->timestamp,
])
->get('klines');
return $response->json();
}
);
return new Quote([ return new Quote([
'name' => $symbol, 'name' => $symbol,
'symbol' => $symbol, 'symbol' => $symbol,
'currency' => Arr::get($fundamental, 'symbols.quoteAsset'), 'currency' => Arr::get($fundamental, 'symbols.0.quoteAsset'),
'market_value' => Arr::get($quote, 'weightedAvgPrice'), 'market_value' => (float) Arr::get($quote, 'weightedAvgPrice'),
]); ]);
} }
@@ -111,7 +91,7 @@ class BinanceMarketData implements MarketDataInterface
public function history(string $symbol, $startDate, $endDate): Collection public function history(string $symbol, $startDate, $endDate): Collection
{ {
$startDate = Carbon::parse($startDate); $startDate = Carbon::parse($startDate);
$endDate = Carbon::parse($endDate); // alpaca has sip data limits $endDate = Carbon::parse($endDate);
$allHistory = collect(); $allHistory = collect();
@@ -133,8 +113,8 @@ class BinanceMarketData implements MarketDataInterface
->withQueryParameters([ ->withQueryParameters([
'symbol' => $symbol, 'symbol' => $symbol,
'interval' => '1d', 'interval' => '1d',
'start' => $startDate->timestamp, 'startTime' => $startDate->timestamp * 1000,
'end' => $chunkEnd->timestamp, 'endTime' => $chunkEnd->timestamp * 1000,
])->get('klines'); ])->get('klines');
$history = $response->json(); $history = $response->json();
@@ -142,14 +122,14 @@ class BinanceMarketData implements MarketDataInterface
throw_if(empty($history), NotFoundHttpException::class, "Symbol `{$symbol}` was not found"); throw_if(empty($history), NotFoundHttpException::class, "Symbol `{$symbol}` was not found");
$chunkedHistory = collect($history) $chunkedHistory = collect($history)
->mapWithKeys(function ($history) use ($symbol) { ->mapWithKeys(function ($history_item) use ($symbol) {
$date = Carbon::parse($history[0])->format('Y-m-d'); $date = Carbon::parse($history_item[0])->format('Y-m-d');
return [$date => new Ohlc([ return [$date => new Ohlc([
'symbol' => $symbol, 'symbol' => $symbol,
'date' => $date, 'date' => $date,
'close' => $history[4], 'close' => $history_item[4],
])]; ])];
}); });