Skip to content

How to create User Data Stream for multiple binance accounts using php-binance-api  #487

@oliver809

Description

@oliver809

I have tried to use the below code in foreach loop to set userData websocket to grab new orders and order updates for multiple accounts. but i can only create userdata webocket for first account in the foreach loop as it start $loop->run for the first account and never return back to the foreach loop. Please suggest/help me how can i set the UserData websocket for remaining accounts. here is the code i am using:

$balance_update = function($api, $balances) {
print_r($balances);
echo "Balance update".PHP_EOL;
};

$order_update = function($api, $report) {
echo "Order update".PHP_EOL;
print_r($report);
$price = $report['price'];
$quantity = $report['quantity'];
$symbol = $report['symbol'];
$side = $report['side'];
$orderType = $report['orderType'];
$orderId = $report['orderId'];
$orderStatus = $report['orderStatus'];
$executionType = $report['orderStatus'];
if ( $executionType == "NEW" ) {
if ( $executionType == "REJECTED" ) {
echo "Order Failed! Reason: {$report['rejectReason']}".PHP_EOL;
}
echo "{$symbol} {$side} {$orderType} ORDER #{$orderId} ({$orderStatus})".PHP_EOL;
echo "..price: {$price}, quantity: {$quantity}".PHP_EOL;
return;
}
//NEW, CANCELED, REPLACED, REJECTED, TRADE, EXPIRED
echo "{$symbol} {$side} {$executionType} {$orderType} ORDER #{$orderId}".PHP_EOL;
};
$api->userData($balance_update, $order_update);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions