-
Notifications
You must be signed in to change notification settings - Fork 21
/
client.php
270 lines (215 loc) · 7.98 KB
/
client.php
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
<?php
/**
* @author lin <[email protected]>
*
* Fill in your key and secret and pass can be directly run
*
* Most of them are unfinished and need your help
* https://github.com/zhouaini528/okex-php.git
* */
use Lin\Okex\OkexWebSocketV5;
require __DIR__ .'../../../vendor/autoload.php';
include 'key_secret.php';
$okex=new OkexWebSocketV5();
$okex->config([
//Do you want to enable local logging,default false
'log'=>true,
//Or set the log name
//'log'=>['filename'=>'okex'],
//Daemons address and port,default 0.0.0.0:22075
'global'=>'127.0.0.1:22075',
//Heartbeat time,default 20 seconds
//'ping_time'=>20,
//Channel subscription monitoring time,2 seconds
//'listen_time'=>2,
//Channel data update time,0.1 seconds
//'data_time'=>0.1,
//Set Demo Trading Services
/*'baseurl'=>[
'public'=>'ws://wspap.okex.com:8443/ws/v5/public?brokerId=9999',
'private'=>'ws://wspap.okex.com:8443/ws/v5/private?brokerId=9999',
],*/
]);
$action=intval($_GET['action'] ?? 0);//http pattern
if(empty($action)) $action=intval($argv[1]);//cli pattern
switch ($action){
//**************public
case 0:{
$okex->subscribe([
["channel"=>"instruments","instType"=>"SPOT"],
["channel"=>"instruments","instType"=>"SWAP"],
["channel"=>"instruments","instType"=>"FUTURES"],
["channel"=>"instruments","instType"=>"OPTION"],
]);
break;
}
//subscribe
case 1:{
$okex->subscribe([
["channel"=>"tickers","instId"=>"BTC-USDT"],
["channel"=>"tickers","instId"=>"BTC-USD-SWAP"],
["channel"=>"tickers","instId"=>"BTC-USD-210924"],
["channel"=>"books","instId"=>"BTC-USDT"],
["channel"=>"books","instId"=>"BTC-USD-SWAP"],
["channel"=>"books","instId"=>"BTC-USD-210924"],
["channel"=>"candle5m","instId"=>"BTC-USDT"],
["channel"=>"candle15m","instId"=>"BTC-USD-SWAP"],
["channel"=>"candle30m","instId"=>"BTC-USD-210924"],
]);
break;
}
//unsubscribe
case 2:{
$okex->unsubscribe([
["channel"=>"tickers","instId"=>"BTC-USDT"],
["channel"=>"tickers","instId"=>"BTC-USD-SWAP"],
["channel"=>"tickers","instId"=>"BTC-USD-210924"],
["channel"=>"books","instId"=>"BTC-USDT"],
["channel"=>"books","instId"=>"BTC-USD-SWAP"],
["channel"=>"books","instId"=>"BTC-USD-210924"],
["channel"=>"candle5m","instId"=>"BTC-USDT"],
["channel"=>"candle15m","instId"=>"BTC-USD-SWAP"],
["channel"=>"candle30m","instId"=>"BTC-USD-210924"],
]);
break;
}
//**************private
//subscribe
case 10:{
$okex->keysecret($key_secret[0]);
$okex->subscribe([
//public
["channel"=>"tickers","instId"=>"BTC-USDT"],
["channel"=>"tickers","instId"=>"BTC-USD-SWAP"],
["channel"=>"tickers","instId"=>"BTC-USD-210924"],
["channel"=>"books","instId"=>"BTC-USDT"],
["channel"=>"books","instId"=>"BTC-USD-SWAP"],
["channel"=>"books","instId"=>"BTC-USD-210924"],
["channel"=>"candle5m","instId"=>"BTC-USDT"],
["channel"=>"candle15m","instId"=>"BTC-USD-SWAP"],
["channel"=>"candle30m","instId"=>"BTC-USD-210924"],
//private
["channel"=>"account","ccy"=>"BTC"],
["channel"=>"positions","instType"=>"FUTURES","uly"=>"BTC-USD","instId"=>"BTC-USD-210924"],
["channel"=>"balance_and_position"],
["channel"=>"orders","instType"=>"FUTURES","uly"=>"BTC-USD","instId"=>"BTC-USD-210924"],
["channel"=>"orders-algo","instType"=>"FUTURES","uly"=>"BTC-USD","instId"=>"BTC-USD-210924"],
]);
break;
}
//unsubscribe
case 11:{
$okex->keysecret($key_secret[0]);
$okex->unsubscribe([
//public
["channel"=>"tickers","instId"=>"BTC-USDT"],
["channel"=>"tickers","instId"=>"BTC-USD-SWAP"],
["channel"=>"tickers","instId"=>"BTC-USD-210924"],
["channel"=>"books","instId"=>"BTC-USDT"],
["channel"=>"books","instId"=>"BTC-USD-SWAP"],
["channel"=>"books","instId"=>"BTC-USD-210924"],
["channel"=>"candle5m","instId"=>"BTC-USDT"],
["channel"=>"candle15m","instId"=>"BTC-USD-SWAP"],
["channel"=>"candle30m","instId"=>"BTC-USD-210924"],
//private
["channel"=>"account","ccy"=>"BTC"],
["channel"=>"positions","instType"=>"FUTURES","uly"=>"BTC-USD","instId"=>"BTC-USD-210924"],
["channel"=>"balance_and_position"],
["channel"=>"orders","instType"=>"FUTURES","uly"=>"BTC-USD","instId"=>"BTC-USD-210924"],
["channel"=>"orders-algo","instType"=>"FUTURES","uly"=>"BTC-USD","instId"=>"BTC-USD-210924"],
]);
break;
}
case 20:{
//****Three ways to get all data
//The first way
$data=$okex->getSubscribes();
print_r(json_encode($data));
//The second way callback
$okex->getSubscribes(function($data){
print_r(json_encode($data));
});
//The third way is to guard the process
$okex->getSubscribes(function($data){
print_r(json_encode($data));
},true);
break;
}
case 21:{
//****Three ways return to the specified channel data
//The first way
$data=$okex->getSubscribe([
["channel"=>"tickers","instId"=>"BTC-USDT"],
["channel"=>"tickers","instId"=>"BTC-USD-SWAP"],
["channel"=>"tickers","instId"=>"BTC-USD-210924"],
]);
//The second way callback
$okex->getSubscribe([
["channel"=>"books","instId"=>"BTC-USDT"],
["channel"=>"books","instId"=>"BTC-USD-SWAP"],
["channel"=>"books","instId"=>"BTC-USD-210924"],
],function($data){
print_r(json_encode($data));
});
//The third way is to guard the process
$okex->getSubscribe([
["channel"=>"candle5m","instId"=>"BTC-USDT"],
["channel"=>"candle15m","instId"=>"BTC-USD-SWAP"],
["channel"=>"candle30m","instId"=>"BTC-USD-210924"],
],function($data){
print_r(json_encode($data));
},true);
break;
}
case 22:{
//****Three ways return to the specified channel data
//The first way
$okex->keysecret($key_secret[0]);
$data=$okex->getSubscribes();
print_r(json_encode($data));
die;
//The second way callback
$okex->keysecret($key_secret[0]);
$okex->getSubscribe([
["channel"=>"books","instId"=>"BTC-USDT"],
["channel"=>"books","instId"=>"BTC-USD-SWAP"],
["channel"=>"account","ccy"=>"BTC"],
["channel"=>"positions","instType"=>"FUTURES","uly"=>"BTC-USD","instId"=>"BTC-USD-210924"],
],function($data){
print_r(json_encode($data));
});
//The third way is to guard the process
$okex->keysecret($key_secret[0]);
$okex->getSubscribe([
["channel"=>"books","instId"=>"BTC-USDT"],
["channel"=>"books","instId"=>"BTC-USD-SWAP"],
["channel"=>"account","ccy"=>"BTC"],
["channel"=>"positions","instType"=>"FUTURES","uly"=>"BTC-USD","instId"=>"BTC-USD-210924"],
],function($data){
print_r(json_encode($data));
},true);
break;
}
case 99:{
$okex->client()->test();
break;
}
case 10004:{
$okex->client()->test2();
break;
}
case 10005:{
$okex->client()->test_reconnection();
break;
}
case 10006:{
$okex->reconPublic();
break;
}
case 10007:{
//private
//print_r($key_secret[0]);
$okex->reconPrivate($key_secret[0]['key']);
break;
}
}