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:
@@ -74,7 +74,7 @@ class ConditionalOrderService
|
||||
}
|
||||
|
||||
$display = app(ProductDisplayPriceService::class);
|
||||
$currentPrice = $this->resolveComparePrice($product, $liquidPrice, $display);
|
||||
$currentPrice = $this->resolveComparePrice($product, $liquidPrice, $display, $config, (int) $order->direction);
|
||||
if ($currentPrice <= 0 || ! $order->conditionMet($currentPrice)) {
|
||||
return;
|
||||
}
|
||||
@@ -89,12 +89,20 @@ class ConditionalOrderService
|
||||
$this->executeOrder($order, $product, $currentPrice);
|
||||
}
|
||||
|
||||
private function resolveComparePrice(Product $product, int $liquidPrice, ProductDisplayPriceService $display): int
|
||||
{
|
||||
private function resolveComparePrice(
|
||||
Product $product,
|
||||
int $liquidPrice,
|
||||
ProductDisplayPriceService $display,
|
||||
ConfigService $config,
|
||||
int $direction
|
||||
): int {
|
||||
if ($display->usesAppPrice($product)) {
|
||||
$base = $liquidPrice > 0 ? $liquidPrice : $display->resolveOrderBasePrice($product);
|
||||
|
||||
return max(0, (int) $base);
|
||||
// مقایسه با همان قیمتی که مشتری در اپ میبیند و سفارش با آن ثبت میشود، نه پایهٔ وسط
|
||||
$trade = $config->buildTradeDisplayPrices((float) $base, $config->priceProvider());
|
||||
|
||||
return max(0, (int) ($direction === 2 ? $trade['sell'] : $trade['buy']));
|
||||
}
|
||||
|
||||
$price = (int) ($product->price ?? 0);
|
||||
|
||||
Reference in New Issue
Block a user