Skip to content

Commit 7160baf

Browse files
Dave XieDave Xie
authored andcommitted
subscribe channel without loop restart
1 parent d0a8f0b commit 7160baf

File tree

4 files changed

+25
-6
lines changed

4 files changed

+25
-6
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,11 @@ $channels = [
126126
$api->subscribePublicChannels($query, $channels, function (array $message, WebSocket $ws, LoopInterface $loop) use ($api) {
127127
var_dump($message);
128128

129+
// Subscribe another channel
130+
// $ws->send(json_encode($api->createSubscribeMessage('/contractMarket/ticker:ETHUSDTM')));
131+
129132
// Unsubscribe the channel
130-
// $ws->send(json_encode($api->createUnsubscribeMessage('/market/ticker:ETH-BTC')));
133+
// $ws->send(json_encode($api->createUnsubscribeMessage('/contractMarket/ticker:XBTUSDM')));
131134

132135
// Stop loop
133136
// $loop->stop();

examples/WebSocketFeed.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,11 @@
3232
$api->subscribePublicChannels($query, $channels, function (array $message, WebSocket $ws, LoopInterface $loop) use ($api) {
3333
var_dump($message);
3434

35+
// Subscribe another channel
36+
// $ws->send(json_encode($api->createSubscribeMessage('/contractMarket/ticker:ETHUSDTM')));
37+
3538
// Unsubscribe the channel
36-
// $ws->send(json_encode($api->createUnsubscribeMessage('/market/ticker:ETH-BTC')));
39+
// $ws->send(json_encode($api->createUnsubscribeMessage('/contractMarket/ticker:XBTUSDM')));
3740

3841
// Stop loop
3942
// $loop->stop();

src/Api.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ abstract class Api
1616
/**
1717
* @var string SDK Version
1818
*/
19-
const VERSION = '1.0.19';
19+
const VERSION = '1.0.20';
2020

2121
/**
2222
* @var string SDK update date
2323
*/
24-
const UPDATE_DATE = '2022.02.27';
24+
const UPDATE_DATE = '2022.03.25';
2525

2626
/**
2727
* @var string

src/PrivateApi/WebSocketFeed.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ public function subscribePrivateChannel(array $query, array $channel, callable $
287287
}
288288

289289
/**
290-
* Create message for ping
290+
* Create a ping message
291291
* @param string $id
292292
* @return array
293293
*/
@@ -297,7 +297,20 @@ public function createPingMessage($id = null)
297297
}
298298

299299
/**
300-
* Create message for unsubscribe
300+
* Create a subscription message
301+
* @param string $topic
302+
* @param bool $privateChannel
303+
* @param bool $response
304+
* @param string $id
305+
* @return array
306+
*/
307+
public function createSubscribeMessage($topic, $privateChannel = false, $response = true, $id = null)
308+
{
309+
return ['id' => $id ?: uniqid('', true), 'type' => 'subscribe', 'topic' => $topic, 'privateChannel' => $privateChannel, 'response' => $response];
310+
}
311+
312+
/**
313+
* Create an unsubscribe message
301314
* @param string $topic
302315
* @param bool $privateChannel
303316
* @param bool $response

0 commit comments

Comments
 (0)