Skip to content

Static tests #510

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Apr 16, 2025
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 27 additions & 20 deletions php-binance-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -1091,7 +1091,7 @@ public function transfer(string $type, string $asset, string $amount, $fromSymbo
*
* @property int $weight 1
*
* @param string $type (optional) type of transfer, e.g. MAIN_MARGIN (@see transfer())
* @param string $type (mandatory) type of transfer, e.g. MAIN_MARGIN (@see transfer())
* @param string $startTime (optional) start time in milliseconds
* @param string $endTime (optional) end time in milliseconds
* @param int $limit (optional) the number of records to return (default 10, max 100)
Expand Down Expand Up @@ -3112,7 +3112,7 @@ public function accountSnapshot($type, $nbrDays = 5, $startTime = 0, $endTime =
if ($startTime > 0)
$params['startTime'] = $startTime;
if ($endTime > 0)
$params['endTime'] = $startTime;
$params['endTime'] = $endTime;
if ($nbrDays != 5)
$params['limit'] = $nbrDays;

Expand Down Expand Up @@ -3588,12 +3588,12 @@ public function futuresMarkPriceCandlesticks(string $symbol, string $interval =
}

/**
* futuresPremiumIndexKlines get the candles for the given intervals
* futuresPremiumIndexCandlesticks get the candles for the given intervals
* 1m,3m,5m,15m,30m,1h,2h,4h,6h,8h,12h,1d,3d,1w,1M
*
* @link https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Premium-Index-Kline-Data
*
* $candles = $api->futuresPremiumIndexKlines("ETHBTC", "5m");
* $candles = $api->futuresPremiumIndexCandlesticks("ETHBTC", "5m");
*
* @property int $weight 5
* for limit < 100 - weight 1
Expand All @@ -3610,7 +3610,7 @@ public function futuresMarkPriceCandlesticks(string $symbol, string $interval =
* @return array containing the response
* @throws \Exception
*/
public function futuresPremiumIndexKlines(string $symbol, string $interval = '5m', int $limit = null, $startTime = null, $endTime = null)
public function futuresPremiumIndexCandlesticks(string $symbol, string $interval = '5m', int $limit = null, $startTime = null, $endTime = null)
{
return $this->futuresCandlesticksHelper($symbol, $interval, $limit, $startTime, $endTime, 'premiumIndexKlines');
}
Expand Down Expand Up @@ -3943,7 +3943,7 @@ public function futuresOpenInterest(string $symbol): array
* symbolPeriodLimitStartEndRequest
* helper for routing GET methods that require symbol, period, limit, startTime and endTime
*/
private function symbolPeriodLimitStartEndContractTypeRequest($symbol, $period, $limit, $startTime, $endTime, $url, $base = 'fapi', $contractType = null)
private function symbolPeriodLimitStartEndRequest($symbol, $period, $limit, $startTime, $endTime, $url, $base = 'fapi', $contractType = null)
{
$parameters = [
'symbol' => $symbol,
Expand Down Expand Up @@ -4477,7 +4477,7 @@ public function futuresSellTest(string $symbol, $quantity = null, $price = null,
* @return array containing the request
* @throws \Exception
*/
protected function createBatchOrdersRequest(array $orders)
protected function createBatchOrdersRequest(array $orders, bool $edit = false)
{
$formatedOrders = [];
for ($index = 0; $index < count($orders); $index++) {
Expand All @@ -4491,6 +4491,9 @@ protected function createBatchOrdersRequest(array $orders)
if (!isset($order['flags'])) {
$order['flags'] = [];
}
if (!isset($order['type'])) {
$order['type'] = 'LIMIT';
}
$formatedOrder = $this->createFuturesOrderRequest(
$order['side'],
$order['symbol'],
Expand All @@ -4503,11 +4506,15 @@ protected function createBatchOrdersRequest(array $orders)
// remove recvWindow from the order
unset($formatedOrder['recvWindow']);
}
if (isset($order['orderId'])) {
$formatedOrder['orderId'] = $order['orderId'];
}
if (isset($order['origClientOrderId'])) {
$formatedOrder['origClientOrderId'] = $order['origClientOrderId'];
if ($edit) {
if (isset($order['orderId'])) {
$formatedOrder['orderId'] = $order['orderId'];
}
if (isset($order['origClientOrderId'])) {
$formatedOrder['origClientOrderId'] = $order['origClientOrderId'];
}
unset($formatedOrder['type']);
unset($formatedOrder['newClientOrderId']);
}
$formatedOrders[$index] = $formatedOrder;
}
Expand Down Expand Up @@ -4580,6 +4587,7 @@ public function futuresEditOrder(string $symbol, string $side, string $quantity,
$opt['orderId'] = $orderId;
}
unset($opt['type']);
unset($opt['newClientOrderId']);
$opt['fapi'] = true;
return $this->httpRequest("v1/order", 'PUT', $opt, true);
}
Expand All @@ -4601,14 +4609,13 @@ public function futuresEditOrders(array $orders, $recvWindow = null)
$params = [
'fapi' => true,
];
$formatedOrders = $this->createBatchOrdersRequest($orders);
$formatedOrders = $this->createBatchOrdersRequest($orders, true);
if ($recvWindow) {
$params['recvWindow'] = $recvWindow;
}
// current endpoint accepts orders list as a json string in the query string
$encodedOrders = json_encode($formatedOrders);
$url = 'v1/batchOrders?batchOrders=' . $encodedOrders;
return $this->httpRequest($url, 'PUT', $params, true);
$params['batchOrders'] = json_encode($formatedOrders);
return $this->httpRequest("v1/batchOrders", 'PUT', $params, true);
}

/**
Expand Down Expand Up @@ -4710,8 +4717,8 @@ public function futuresCancelBatchOrders(string $symbol, $orderIdList = null, $o
// remove quotes and spaces
$params['orderIdList'] = str_replace(' ', '', str_replace('"', '', str_replace("'", '', $idsString)));
} else if ($origClientOrderIdList) {
// remove spaces
$params['origClientOrderIdList'] = str_replace(' ', '', json_encode($origClientOrderIdList));
// remove spaces between the ids
$params['origClientOrderIdList'] = str_replace(', ', ',', json_encode($origClientOrderIdList));
} else {
throw new \Exception('futuresCancelBatchOrders: either orderIdList or origClientOrderIdList must be set');
}
Expand Down Expand Up @@ -6054,7 +6061,7 @@ public function convertAccept(string $quoteId, int $recvWindow = null, array $pa
$request = [
'quoteId' => $quoteId,
];
return $this->fapiRequest("v1/cconvert/acceptQuote", 'POST', array_merge($request, $params), true, $recvWindow);
return $this->fapiRequest("v1/convert/acceptQuote", 'POST', array_merge($request, $params), true, $recvWindow);
}

/**
Expand Down Expand Up @@ -6098,4 +6105,4 @@ public function convertStatus($orderId = null, $quoteId = null)
}
return $this->httpRequest("v1/convert/orderStatus", 'GET', $params, true);
}
}
}
Loading