-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathexample_private_api.php
More file actions
31 lines (24 loc) · 967 Bytes
/
Copy pathexample_private_api.php
File metadata and controls
31 lines (24 loc) · 967 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?php
require __DIR__ . '/vendor/autoload.php';
const EXMO_API_KEY = 'api_key_change_me';
const EXMO_API_SECRET = 'api_key_secret_change_me';
\Ratchet\Client\connect('wss://ws-api.exmo.com/v1/private')->then(function ($conn) {
$exmoApi = new \Exmo\WebSocketApi\Client($conn);
$exmoApi->login(EXMO_API_KEY, EXMO_API_SECRET);
$exmoApi->subscribe([
"spot/wallet",
"spot/orders",
"spot/user_trades",
]);
$exmoApi->onMessage(function ($data) {
if ($data['event'] === \Exmo\WebSocketApi\Client::EVENT_ERROR) {
throw new Exception($data['message'], $data['code']);
}
print_r($data);
});
$conn->on('close', function($code = null, $reason = null) use ($exmoApi) {
echo "Connection closed. Code: $code; Reason: {$reason}; Session ID: {$exmoApi->getSessionId()}" . PHP_EOL;
});
}, function (\Exception $e) {
echo "Could not connect: {$e->getMessage()}" . PHP_EOL;
});