Skip to content

Commit 390b0bf

Browse files
committed
preventedMatches added
1 parent 530c217 commit 390b0bf

File tree

3 files changed

+69
-1
lines changed

3 files changed

+69
-1
lines changed

php-binance-api.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3534,6 +3534,49 @@ public function orderRateLimit(array $params = [])
35343534
return $this->apiRequest("v3/rateLimit/order", 'GET', $params, true);
35353535
}
35363536

3537+
/**
3538+
* preventedMatches - Get the list of orders that were expired due to STP
3539+
*
3540+
* @link https://developers.binance.com/docs/binance-spot-api-docs/rest-api/account-endpoints#query-prevented-matches-user_data
3541+
*
3542+
* @property int $weight 2
3543+
* - 2 if preventedMatchId is provided
3544+
* - 20 if orderId is provided
3545+
*
3546+
* @param string $symbol (mandatory) The symbol, e.g. BTCUSDT
3547+
* @param string $preventedMatchId (optional) The ID of the prevented match (mandatory if orderId is not provided)
3548+
* @param string $orderId (optional) The ID of the order (mandatory if preventedMatchId is not provided)
3549+
* @param string $fromPreventedMatchId (optional) The ID of the prevented match to start from
3550+
* @param int $limit (optional) The number of results to return (default is 500, max is 1000)
3551+
* @param array $params (optional) An array of additional parameters that the API endpoint allows
3552+
*
3553+
* @return array with error message or the rate limit details
3554+
* @throws \Exception
3555+
*/
3556+
public function preventedMatches(string $symbol, ?string $preventedMatchId = null, ?string $orderId = null, ?string $fromPreventedMatchId = null, ?int $limit = null, array $params = []) {
3557+
$request = [
3558+
'symbol' => $symbol,
3559+
];
3560+
3561+
if (is_null($preventedMatchId) && is_null($orderId)) {
3562+
throw new \Exception("Either preventedMatchId or orderId must be provided");
3563+
} else if ($preventedMatchId) {
3564+
$request['preventedMatchId'] = $preventedMatchId;
3565+
} else {
3566+
$request['orderId'] = $orderId;
3567+
}
3568+
3569+
if ($fromPreventedMatchId) {
3570+
$request['fromPreventedMatchId'] = $fromPreventedMatchId;
3571+
}
3572+
3573+
if (!is_null($limit)) {
3574+
$request['limit'] = $limit;
3575+
}
3576+
3577+
return $this->apiRequest("v3/myPreventedMatches", 'GET', array_merge($request, $params), true);
3578+
}
3579+
35373580
/**
35383581
* ocoOrder - Create a new OCO order
35393582
*

tests/BinanceLiveTests.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,12 @@ public function testAvgPriceSpot()
425425
$this->assertIsNumeric($res);
426426
}
427427

428+
public function testPreventedMatchesSpot()
429+
{
430+
$res = $this->spotBinance->preventedMatches($this->symbol, null, '0123456789');
431+
$this->assertIsArray($res);
432+
}
433+
428434
public function testTimeFutures()
429435
{
430436
$res = $this->futuresBinance->futuresTime();
@@ -1388,7 +1394,7 @@ public function testOrderRateLimitFutures()
13881394
$this->assertIsInt($firstEntry['limit']);
13891395
}
13901396

1391-
public function testOrderRateLimit()
1397+
public function testOrderRateLimitSpot()
13921398
{
13931399
$res = $this->spotBinance->orderRateLimit();
13941400
$this->assertIsArray($res);

tests/BinanceStaticTests.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,6 +1111,25 @@ public function testMarginAccountSnapshot()
11111111

11121112
}
11131113

1114+
public function testPreventedMatches()
1115+
{
1116+
try {
1117+
$this->binance->preventedMatches($this->symbol, null, $this->orderId);
1118+
1119+
} catch (\Throwable $e) {
1120+
1121+
}
1122+
$endpoint = "https://api.binance.com/api/v3/myPreventedMatches?";
1123+
$this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint));
1124+
1125+
$queryString = substr(self::$capturedUrl, strlen($endpoint));
1126+
parse_str($queryString, $params);
1127+
1128+
$this->assertEquals($this->symbol, $params['symbol']);
1129+
$this->assertEquals($this->orderId, $params['orderId']);
1130+
1131+
}
1132+
11141133
public function testFuturesAccountSnapshot()
11151134
{
11161135
try {

0 commit comments

Comments
 (0)