diff --git a/README.md b/README.md index b47be3c..ef25a42 100644 --- a/README.md +++ b/README.md @@ -122,6 +122,9 @@ $channels = [ $api->subscribePublicChannels($query, $channels, function (array $message, WebSocket $ws, LoopInterface $loop) use ($api) { var_dump($message); + // Subscribe another channel + // $ws->send(json_encode($api->createSubscribeMessage('/market/ticker:LTC-BTC'))); + // Unsubscribe the channel // $ws->send(json_encode($api->createUnsubscribeMessage('/market/ticker:ETH-BTC'))); diff --git a/examples/WebSocketFeed.php b/examples/WebSocketFeed.php index df26569..7b564f8 100644 --- a/examples/WebSocketFeed.php +++ b/examples/WebSocketFeed.php @@ -32,6 +32,9 @@ $api->subscribePublicChannels($query, $channels, function (array $message, WebSocket $ws, LoopInterface $loop) use ($api) { var_dump($message); + // Subscribe another channel + // $ws->send(json_encode($api->createSubscribeMessage('/market/ticker:LTC-BTC'))); + // Unsubscribe the channel // $ws->send(json_encode($api->createUnsubscribeMessage('/market/ticker:ETH-BTC'))); diff --git a/src/Api.php b/src/Api.php index 344804d..37714f6 100644 --- a/src/Api.php +++ b/src/Api.php @@ -16,12 +16,12 @@ abstract class Api /** * @var string SDK Version */ - const VERSION = '1.1.26'; + const VERSION = '1.1.27'; /** * @var string SDK update date */ - const UPDATE_DATE = '2022.02.27'; + const UPDATE_DATE = '2022.03.25'; /** * @var string diff --git a/src/PrivateApi/WebSocketFeed.php b/src/PrivateApi/WebSocketFeed.php index 9fa8557..b3e065e 100644 --- a/src/PrivateApi/WebSocketFeed.php +++ b/src/PrivateApi/WebSocketFeed.php @@ -287,7 +287,7 @@ public function subscribePrivateChannel(array $query, array $channel, callable $ } /** - * Create message for ping + * Create a ping message * @param string $id * @return array */ @@ -297,7 +297,20 @@ public function createPingMessage($id = null) } /** - * Create message for unsubscribe + * Create a subscription message + * @param string $topic + * @param bool $privateChannel + * @param bool $response + * @param string $id + * @return array + */ + public function createSubscribeMessage($topic, $privateChannel = false, $response = true, $id = null) + { + return ['id' => $id ?: uniqid('', true), 'type' => 'subscribe', 'topic' => $topic, 'privateChannel' => $privateChannel, 'response' => $response]; + } + + /** + * Create an unsubscribe message * @param string $topic * @param bool $privateChannel * @param bool $response