fix price force refresh 2

This commit is contained in:
2026-06-14 12:33:29 +03:30
parent 1abddfbab8
commit db0cc5f1a6
8 changed files with 246 additions and 120 deletions
+48
View File
@@ -102,6 +102,54 @@ class ConfigService
return $sellFee > 0 ? $sellFee : $feeSingle;
}
/**
* sell / buy / price_last — یک منبع حقیقت برای lastPrice و buildFromDatabase.
*
* @param float $priceValue قیمت پایه (ریال/گرم) — از API یا DB
* @param string|null $priceSource montzar | zaarbox | main_product | database_last | null
* @param array{montzar_open_buy?:bool,montzar_open_sell?:bool} $montzarFlags فقط وقتی API تازه خوانده شده
* @return array{sell:int,buy:int,priceLast:int}
*/
public function buildTradeDisplayPrices(
float $priceValue,
?string $priceSource = null,
array $montzarFlags = []
): array {
$diffBuy = (float) $this->displayBuySpreadRial();
$diffSell = (float) $this->displaySellSpreadRial();
$feeSingle = (float) $this->get('fee_single', 0);
$openBuy = true;
$openSell = true;
if ($priceSource === 'montzar') {
$montzarProfit = (float) $this->get('montzar_diff', 0);
$finalBuyDiff = $diffBuy + $montzarProfit;
$finalSellDiff = $diffSell + $montzarProfit;
$openBuy = $montzarFlags['montzar_open_buy'] ?? $this->getBool('montzar_open_buy', true);
$openSell = $montzarFlags['montzar_open_sell'] ?? $this->getBool('montzar_open_sell', true);
$sell = $openSell ? (int) ceil($priceValue - $finalSellDiff) : 0;
$buy = $openBuy ? (int) ceil($priceValue + $finalBuyDiff) : 0;
$priceLast = (int) ceil($priceValue + $finalBuyDiff);
return compact('sell', 'buy', 'priceLast');
}
$sell = $openSell ? (int) ceil($priceValue - $feeSingle) : 0;
$buy = $openBuy ? (int) ceil($priceValue + $feeSingle) : 0;
$priceLast = (int) ceil($priceValue + $feeSingle);
$provider = $this->priceProvider();
if (in_array($provider, ['main_product', 'zaarbox'], true)) {
$sell = $openSell ? (int) ceil($priceValue - $diffSell) : 0;
$buy = $openBuy ? (int) ceil($priceValue + $diffBuy) : 0;
$priceLast = (int) ceil($priceValue + $diffBuy);
}
return compact('sell', 'buy', 'priceLast');
}
/**
* تنها منبع فعال قیمت — montzar | main_product | zaarbox
*