Skip to content

Commit e384a70

Browse files
committed
allocations() added
1 parent 390b0bf commit e384a70

File tree

3 files changed

+74
-0
lines changed

3 files changed

+74
-0
lines changed

php-binance-api.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3577,6 +3577,52 @@ public function preventedMatches(string $symbol, ?string $preventedMatchId = nul
35773577
return $this->apiRequest("v3/myPreventedMatches", 'GET', array_merge($request, $params), true);
35783578
}
35793579

3580+
/**
3581+
* allocations - Get the allocations resulting from SOR order placement
3582+
*
3583+
* @link https://developers.binance.com/docs/binance-spot-api-docs/rest-api/account-endpoints#query-allocations-user_data
3584+
*
3585+
* @property int $weight 20
3586+
*
3587+
* @param string $symbol (mandatory) The symbol, e.g. BTCUSDT
3588+
* @param int $startTime (optional) The start time of the query
3589+
* @param int $endTime (optional) The end time of the query
3590+
* @param string $fromAllocationId (optional) The ID of the allocation to start from
3591+
* @param int $limit (optional) The number of results to return (default is 500, max is 1000)
3592+
* @param string $orderId (optional) The ID of the order
3593+
* @param array $params (optional) An array of additional parameters that the API endpoint allows
3594+
*
3595+
* @return array with error message or the rate limit details
3596+
* @throws \Exception
3597+
*/
3598+
public function allocations(string $symbol, ?int $startTime = null, ?int $endTime = null, ?string $fromAllocationId = null, ?int $limit = null, ?string $orderId = null, array $params = []) {
3599+
$request = [
3600+
'symbol' => $symbol,
3601+
];
3602+
3603+
if ($startTime) {
3604+
$request['startTime'] = $startTime;
3605+
}
3606+
3607+
if ($endTime) {
3608+
$request['endTime'] = $endTime;
3609+
}
3610+
3611+
if ($fromAllocationId) {
3612+
$request['fromAllocationId'] = $fromAllocationId;
3613+
}
3614+
3615+
if (!is_null($limit)) {
3616+
$request['limit'] = $limit;
3617+
}
3618+
3619+
if ($orderId) {
3620+
$request['orderId'] = $orderId;
3621+
}
3622+
3623+
return $this->apiRequest("v3/myAllocations", 'GET', array_merge($request, $params), true);
3624+
}
3625+
35803626
/**
35813627
* ocoOrder - Create a new OCO order
35823628
*

tests/BinanceLiveTests.php

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

434+
public function testAllocationsSpot()
435+
{
436+
$res = $this->spotBinance->allocations($this->symbol);
437+
$this->assertIsArray($res);
438+
}
439+
434440
public function testTimeFutures()
435441
{
436442
$res = $this->futuresBinance->futuresTime();

tests/BinanceStaticTests.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,6 +1130,28 @@ public function testPreventedMatches()
11301130

11311131
}
11321132

1133+
public function testAllocations()
1134+
{
1135+
try {
1136+
$this->binance->allocations($this->symbol, $this->startTime, $this->endTime, $this->fromId, $this->limit, $this->orderId);
1137+
1138+
} catch (\Throwable $e) {
1139+
1140+
}
1141+
$endpoint = "https://api.binance.com/api/v3/myAllocations?";
1142+
$this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint));
1143+
1144+
$queryString = substr(self::$capturedUrl, strlen($endpoint));
1145+
parse_str($queryString, $params);
1146+
1147+
$this->assertEquals($this->symbol, $params['symbol']);
1148+
$this->assertEquals($this->startTime, $params['startTime']);
1149+
$this->assertEquals($this->endTime, $params['endTime']);
1150+
$this->assertEquals($this->fromId, $params['fromAllocationId']);
1151+
$this->assertEquals($this->limit, $params['limit']);
1152+
$this->assertEquals($this->orderId, $params['orderId']);
1153+
}
1154+
11331155
public function testFuturesAccountSnapshot()
11341156
{
11351157
try {

0 commit comments

Comments
 (0)