Price orders at the provider's real trade rate instead of the mid quote.
montzar_live_price is the midpoint between the colleague's buy and sell rates, so orders priced straight from it charged the customer less than we pay the provider and the whole spread was lost on every trade, even though the app already showed the correct side. Order base price now follows the traded side (base + spread on buy, base - spread on sell), which also makes price_original the real cost basis so the dashboard stops counting the provider spread as profit. Conditional order triggers compare against the same displayed price. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -471,6 +471,45 @@ class ProductDisplayPriceService
|
||||
return $this->resolveHistoricalBasePrice();
|
||||
}
|
||||
|
||||
/**
|
||||
* قیمت پایهٔ سفارش برای یک جهت — با اختلاف واقعی نرخ همکار.
|
||||
* پایه وسطِ نرخ خرید/فروش همکار است؛ سفارش باید با همان سمتی حساب شود که ما با همکار معامله میکنیم.
|
||||
*/
|
||||
public function resolveOrderTradePrice(?Product $product = null, ?int $direction = null): int
|
||||
{
|
||||
$base = (float) $this->resolveOrderBasePrice($product);
|
||||
|
||||
return (int) $this->applyProviderTradeSpread($base, $product, $direction);
|
||||
}
|
||||
|
||||
/**
|
||||
* خرید → پایه + اختلاف نرخ همکار، فروش → پایه − اختلاف.
|
||||
* فقط روی قیمتی که از مظنهٔ اپ آمده؛ محصول با قیمت دستی/فید/فرمول دست نمیخورد.
|
||||
* ceil مثل buildTradeDisplayPrices تا قیمت سفارش با قیمت نمایشی اپ یکی بماند.
|
||||
*/
|
||||
public function applyProviderTradeSpread(
|
||||
float $basePrice,
|
||||
?Product $product = null,
|
||||
?int $direction = null
|
||||
): float {
|
||||
if ($basePrice <= 0 || $direction === null) {
|
||||
return $basePrice;
|
||||
}
|
||||
|
||||
if ($product instanceof Product && ! $this->usesAppPrice($product)) {
|
||||
return $basePrice;
|
||||
}
|
||||
|
||||
$spread = app(ConfigService::class)->providerTradeSpreadRial();
|
||||
if ($spread <= 0) {
|
||||
return $basePrice;
|
||||
}
|
||||
|
||||
return $direction === 2
|
||||
? max(0.0, ceil($basePrice - $spread))
|
||||
: ceil($basePrice + $spread);
|
||||
}
|
||||
|
||||
/** @param array<string, mixed> $payload */
|
||||
private function extractBaseFromPayload(array $payload): int
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user