fix(price): drop quote deviation cap so Montzar live price can apply
Stale prices rows were rejecting a valid ~220M partner quote against an old ~168M reference and locking the app on database_last. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -31,19 +31,13 @@ class ConfigService
|
|||||||
*/
|
*/
|
||||||
public const STORED_PRICE_SOURCES = ['database_last'];
|
public const STORED_PRICE_SOURCES = ['database_last'];
|
||||||
|
|
||||||
/**
|
|
||||||
* حداکثر انحراف مجاز مظنه نسبت به آخرین قیمت معتبر DB.
|
|
||||||
* پرش اشتباه provider (مثل ۱۶۸M ماندهٔ montzar روی مظنهٔ ~۲۲۰M) را رد میکند.
|
|
||||||
*/
|
|
||||||
public const MAX_QUOTE_DEVIATION_RATIO = 0.15;
|
|
||||||
|
|
||||||
public function Config($name)
|
public function Config($name)
|
||||||
{
|
{
|
||||||
return $this->get($name, false);
|
return $this->get($name, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* آخرین قیمت ذخیرهشده در جدول prices — مرجع سلامت مظنهٔ زنده.
|
* آخرین قیمت ذخیرهشده در جدول prices.
|
||||||
*/
|
*/
|
||||||
public function referenceQuotePrice(): float
|
public function referenceQuotePrice(): float
|
||||||
{
|
{
|
||||||
@@ -52,21 +46,10 @@ class ConfigService
|
|||||||
return $last !== null ? (float) $last : 0.0;
|
return $last !== null ? (float) $last : 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** مظنهٔ مثبت قابل استفاده است — محدودیت انحراف نسبت به DB برداشته شد. */
|
||||||
* مظنهٔ زنده وقتی خیلی از آخرین قیمت DB فاصله دارد قابل اتکا نیست (ماندهٔ provider اشتباه).
|
|
||||||
*/
|
|
||||||
public function isPlausibleQuotePrice(float $candidate, ?float $reference = null): bool
|
public function isPlausibleQuotePrice(float $candidate, ?float $reference = null): bool
|
||||||
{
|
{
|
||||||
if ($candidate <= 0) {
|
return $candidate > 0;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$reference = $reference ?? $this->referenceQuotePrice();
|
|
||||||
if ($reference <= 0) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return abs($candidate - $reference) / $reference <= self::MAX_QUOTE_DEVIATION_RATIO;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -7,30 +7,13 @@ use PHPUnit\Framework\TestCase;
|
|||||||
|
|
||||||
class QuotePricePlausibilityTest extends TestCase
|
class QuotePricePlausibilityTest extends TestCase
|
||||||
{
|
{
|
||||||
public function test_rejects_stale_montzar_jump_against_reference(): void
|
public function test_accepts_any_positive_price(): void
|
||||||
{
|
{
|
||||||
$config = new class extends ConfigService {
|
$config = new ConfigService();
|
||||||
public function referenceQuotePrice(): float
|
|
||||||
{
|
|
||||||
return 223_260_000.0;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
$this->assertFalse($config->isPlausibleQuotePrice(168_336_410.0));
|
|
||||||
$this->assertTrue($config->isPlausibleQuotePrice(222_010_000.0));
|
|
||||||
$this->assertTrue($config->isPlausibleQuotePrice(223_260_000.0));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function test_accepts_any_positive_when_no_reference(): void
|
|
||||||
{
|
|
||||||
$config = new class extends ConfigService {
|
|
||||||
public function referenceQuotePrice(): float
|
|
||||||
{
|
|
||||||
return 0.0;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
$this->assertTrue($config->isPlausibleQuotePrice(168_336_410.0));
|
$this->assertTrue($config->isPlausibleQuotePrice(168_336_410.0));
|
||||||
|
$this->assertTrue($config->isPlausibleQuotePrice(222_010_000.0));
|
||||||
$this->assertFalse($config->isPlausibleQuotePrice(0.0));
|
$this->assertFalse($config->isPlausibleQuotePrice(0.0));
|
||||||
|
$this->assertFalse($config->isPlausibleQuotePrice(-1.0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user