Skip to content
Snippets Groups Projects
Commit 1b817337 authored by nicolasbonnici's avatar nicolasbonnici
Browse files

WS support

parent 80de86e1
No related branches found
No related tags found
1 merge request!4WS support
......@@ -4,7 +4,8 @@
"type": "library",
"require": {
"php": ">=8.0",
"ext-curl": "*"
"ext-curl": "*",
"ratchet/pawl": "dev-master"
},
"license": "GPL-3.0",
"autoload": {
......
This diff is collapsed.
......@@ -9,6 +9,8 @@ class KrakenAPIClient
public const DEFAULT_API_ROOT = 'https://api.kraken.com';
public const DEFAULT_API_VERSION = '0';
public const AUTHENTICATED_ENDPOINTS_URI_PATH = 'private/';
public const WEBSOCKET_PUBLIC_ENDPOINT = 'ws.kraken.com';
public const WEBSOCKET_PRIVATE_ENDPOINT = 'ws-auth.kraken.com';
public function __construct(
private ?string $key = null,
......@@ -72,6 +74,18 @@ class KrakenAPIClient
return $response['result'];
}
public function stream(callable $callback, string $endpoint = self::WEBSOCKET_PUBLIC_ENDPOINT): void
{
\Ratchet\Client\connect(sprintf('wss://%s', $endpoint))->then(
$callback,
function ($e) {
throw new KrakenAPIException(
sprintf('Error while connecting to Kraken API WebSocket: "%s".', $e->getMessage())
);
}
);
}
private function loadClient(): void
{
if ($this->curl === false) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment