Skip to content

Commit 29d1f01

Browse files
committed
commissionRate() added
1 parent e384a70 commit 29d1f01

File tree

3 files changed

+81
-0
lines changed

3 files changed

+81
-0
lines changed

php-binance-api.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3623,6 +3623,27 @@ public function allocations(string $symbol, ?int $startTime = null, ?int $endTim
36233623
return $this->apiRequest("v3/myAllocations", 'GET', array_merge($request, $params), true);
36243624
}
36253625

3626+
/**
3627+
* commissionRate - Get the commission rate for a symbol
3628+
*
3629+
* @link https://developers.binance.com/docs/binance-spot-api-docs/rest-api/account-endpoints#query-commission-rates-user_data
3630+
*
3631+
* @property int $weight 20
3632+
*
3633+
* @param string $symbol (mandatory) The symbol, e.g. BTCUSDT
3634+
* @param array $params (optional) An array of additional parameters that the API endpoint allows
3635+
*
3636+
* @return array with error message or the rate limit details
3637+
* @throws \Exception
3638+
*/
3639+
public function commissionRate(string $symbol, array $params = []) {
3640+
$request = [
3641+
'symbol' => $symbol,
3642+
];
3643+
3644+
return $this->apiRequest("v3/account/commission", 'GET', array_merge($request, $params), true);
3645+
}
3646+
36263647
/**
36273648
* ocoOrder - Create a new OCO order
36283649
*

tests/BinanceLiveTests.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,48 @@ public function testPreventedMatchesSpot()
431431
$this->assertIsArray($res);
432432
}
433433

434+
public function testCommissionRateSpot()
435+
{
436+
$res = $this->spotBinance->commissionRate($this->symbol);
437+
$this->assertIsArray($res);
438+
$this->assertArrayHasKey('symbol', $res);
439+
$this->assertEquals($this->symbol, $res['symbol']);
440+
$this->assertArrayHasKey('standardCommission', $res);
441+
442+
$standardCommission = $res['standardCommission'];
443+
$this->assertIsArray($standardCommission);
444+
$this->assertArrayHasKey('maker', $standardCommission);
445+
$this->assertIsNumeric($standardCommission['maker']);
446+
$this->assertArrayHasKey('taker', $standardCommission);
447+
$this->assertIsNumeric($standardCommission['taker']);
448+
$this->assertArrayHasKey('buyer', $standardCommission);
449+
$this->assertIsNumeric($standardCommission['buyer']);
450+
$this->assertArrayHasKey('seller', $standardCommission);
451+
$this->assertIsNumeric($standardCommission['seller']);
452+
453+
$this->assertArrayHasKey('taxCommission', $res);
454+
$taxCommission = $res['taxCommission'];
455+
$this->assertIsArray($taxCommission);
456+
$this->assertArrayHasKey('maker', $taxCommission);
457+
$this->assertIsNumeric($taxCommission['maker']);
458+
$this->assertArrayHasKey('taker', $taxCommission);
459+
$this->assertIsNumeric($taxCommission['taker']);
460+
$this->assertArrayHasKey('buyer', $taxCommission);
461+
$this->assertIsNumeric($taxCommission['buyer']);
462+
$this->assertArrayHasKey('seller', $taxCommission);
463+
464+
$this->assertArrayHasKey('discount', $res);
465+
$discount = $res['discount'];
466+
$this->assertIsArray($discount);
467+
$this->assertArrayHasKey('enabledForAccount', $discount);
468+
$this->assertIsBool($discount['enabledForAccount']);
469+
$this->assertArrayHasKey('enabledForSymbol', $discount);
470+
$this->assertIsBool($discount['enabledForSymbol']);
471+
$this->assertArrayHasKey('discountAsset', $discount);
472+
$this->assertArrayHasKey('discount', $discount);
473+
$this->assertIsNumeric($discount['discount']);
474+
}
475+
434476
public function testAllocationsSpot()
435477
{
436478
$res = $this->spotBinance->allocations($this->symbol);

tests/BinanceStaticTests.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,6 +1152,24 @@ public function testAllocations()
11521152
$this->assertEquals($this->orderId, $params['orderId']);
11531153
}
11541154

1155+
public function testCommissionRate()
1156+
{
1157+
try {
1158+
$this->binance->commissionRate($this->symbol);
1159+
1160+
} catch (\Throwable $e) {
1161+
1162+
}
1163+
$endpoint = "https://api.binance.com/api/v3/account/commission?";
1164+
$this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint));
1165+
1166+
$queryString = substr(self::$capturedUrl, strlen($endpoint));
1167+
parse_str($queryString, $params);
1168+
1169+
$this->assertEquals($this->symbol, $params['symbol']);
1170+
1171+
}
1172+
11551173
public function testFuturesAccountSnapshot()
11561174
{
11571175
try {

0 commit comments

Comments
 (0)