├── LICENSE ├── README.md ├── README_CN.md ├── composer.json ├── src ├── Api │ ├── Futures │ │ ├── Contract.php │ │ └── Market.php │ ├── Linear │ │ ├── Account.php │ │ ├── Market.php │ │ └── Trade.php │ ├── Spot │ │ ├── Account.php │ │ ├── AlgoOrder.php │ │ ├── C2c.php │ │ ├── Common.php │ │ ├── CrossMargin.php │ │ ├── Etf.php │ │ ├── Margin.php │ │ ├── Market.php │ │ ├── Order.php │ │ ├── Reference.php │ │ ├── Settings.php │ │ ├── Subuser.php │ │ └── Wallet.php │ ├── Swap │ │ ├── Account.php │ │ ├── Market.php │ │ └── Trade.php │ └── WebSocket │ │ ├── SocketClient.php │ │ ├── SocketFunction.php │ │ ├── SocketGlobal.php │ │ └── SocketServer.php ├── Exceptions │ └── Exception.php ├── HuobiFuture.php ├── HuobiLinear.php ├── HuobiSpot.php ├── HuobiSwap.php ├── HuobiWebSocket.php └── Request.php └── tests ├── future ├── contract.php ├── lightning.php └── market.php ├── linear ├── account.php ├── market.php └── trade.php ├── spot ├── account.php ├── market.php ├── order.php ├── proxy.php ├── subuser.php └── transfer.php ├── swap ├── account.php ├── market.php └── trade.php └── websocket ├── client_future.php ├── client_linear.php ├── client_spot.php ├── client_swap.php ├── server_future.php ├── server_linear.php ├── server_spot.php └── server_swap.php /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 lin 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ### It is recommended that you read the official document first 2 | 3 | Huobi docs [https://huobiapi.github.io/docs/spot/v1/cn/#api](https://huobiapi.github.io/docs/spot/v1/cn/#api) 4 | 5 | All interface methods are initialized the same as those provided by huobi. See details [src/api](https://github.com/zhouaini528/huobi-php/tree/master/src/Api) 6 | 7 | Support [Websocket](https://github.com/zhouaini528/huobi-php/blob/master/README.md#Websocket) 8 | 9 | Most of the interface is now complete, and the user can continue to extend it based on my design, working with me to improve it. 10 | 11 | [中文文档](https://github.com/zhouaini528/huobi-php/blob/master/README_CN.md) 12 | 13 | ### Other exchanges API 14 | 15 | [Exchanges](https://github.com/zhouaini528/exchanges-php) It includes all of the following exchanges and is highly recommended. 16 | 17 | [Bitmex](https://github.com/zhouaini528/bitmex-php) Support [Websocket](https://github.com/zhouaini528/bitmex-php/blob/master/README.md#Websocket) 18 | 19 | [Okex](https://github.com/zhouaini528/okex-php) Support [Websocket](https://github.com/zhouaini528/okex-php/blob/master/README.md#Websocket) 20 | 21 | [Huobi](https://github.com/zhouaini528/huobi-php) Support [Websocket](https://github.com/zhouaini528/huobi-php/blob/master/README.md#Websocket) 22 | 23 | [Binance](https://github.com/zhouaini528/binance-php) Support [Websocket](https://github.com/zhouaini528/binance-php/blob/master/README.md#Websocket) 24 | 25 | [Kucoin](https://github.com/zhouaini528/kucoin-php) 26 | 27 | [Mxc](https://github.com/zhouaini528/Mxc-php) 28 | 29 | [Coinbase](https://github.com/zhouaini528/coinbase-php) 30 | 31 | [ZB](https://github.com/zhouaini528/zb-php) 32 | 33 | [Bitfinex](https://github.com/zhouaini528/bitfinex-php) 34 | 35 | [Bittrex](https://github.com/zhouaini528/bittrex-php) 36 | 37 | [Kraken](https://github.com/zhouaini528/kraken-php) 38 | 39 | [Gate](https://github.com/zhouaini528/gate-php) 40 | 41 | [Bigone](https://github.com/zhouaini528/bigone-php) 42 | 43 | [Crex24](https://github.com/zhouaini528/crex24-php) 44 | 45 | [Bybit](https://github.com/zhouaini528/bybit-php) 46 | 47 | [Coinbene](https://github.com/zhouaini528/coinbene-php) 48 | 49 | [Bitget](https://github.com/zhouaini528/bitget-php) 50 | 51 | [Poloniex](https://github.com/zhouaini528/poloniex-php) 52 | 53 | #### Installation 54 | ``` 55 | composer require linwj/huobi 56 | ``` 57 | 58 | Support for more request Settings [More](https://github.com/zhouaini528/huobi-php/blob/master/tests/spot/proxy.php#L21) 59 | ```php 60 | $huobi=new HuobiSpot(); 61 | 62 | //You can set special needs 63 | $huobi->setOptions([ 64 | //Set the request timeout to 60 seconds by default 65 | 'timeout'=>10, 66 | //https://github.com/guzzle/guzzle 67 | 'proxy'=>[], 68 | //https://www.php.net/manual/en/book.curl.php 69 | 'curl'=>[], 70 | ]); 71 | ``` 72 | 73 | ### Spot Trading API 74 | 75 | Market related API [More](https://github.com/zhouaini528/huobi-php/blob/master/tests/spot/market.php) 76 | 77 | ```php 78 | $huobi=new HuobiSpot(); 79 | 80 | //Get market data. This endpoint provides the snapshots of market data and can be used without verifications. 81 | try { 82 | $result=$huobi->market()->getDepth([ 83 | 'symbol'=>'btcusdt', 84 | //'type'=>'step3' default step0 85 | ]); 86 | print_r($result); 87 | }catch (\Exception $e){ 88 | print_r($e->getMessage()); 89 | } 90 | 91 | //List trading pairs and get the trading limit, price, and more information of different trading pairs. 92 | try { 93 | $result=$huobi->market()->getTickers(); 94 | print_r($result); 95 | }catch (\Exception $e){ 96 | print_r($e->getMessage()); 97 | } 98 | ``` 99 | 100 | Order related API [More](https://github.com/zhouaini528/huobi-php/blob/master/tests/spot/order.php) 101 | 102 | ```php 103 | $huobi=new HuobiSpot($key,$secret); 104 | 105 | //Place an Order 106 | try { 107 | $result=$huobi->order()->postPlace([ 108 | 'account-id'=>$account_id, 109 | 'symbol'=>'btcusdt', 110 | 'type'=>'buy-limit', 111 | 'amount'=>'0.001', 112 | 'price'=>'100', 113 | ]); 114 | print_r($result); 115 | }catch (\Exception $e){ 116 | print_r($e->getMessage()); 117 | } 118 | sleep(1); 119 | 120 | //Get order details by order ID. 121 | try { 122 | $result=$huobi->order()->get([ 123 | 'order-id'=>$result['data'], 124 | ]); 125 | print_r($result); 126 | }catch (\Exception $e){ 127 | print_r($e->getMessage()); 128 | } 129 | sleep(1); 130 | 131 | //Cancelling an unfilled order. 132 | try { 133 | $result=$huobi->order()->postSubmitCancel([ 134 | 'order-id'=>$result['data']['id'], 135 | ]); 136 | print_r($result); 137 | }catch (\Exception $e){ 138 | print_r($e->getMessage()); 139 | } 140 | 141 | //***********************Customize the order ID 142 | //Place an Order 143 | try { 144 | $client_order_id=rand(10000,99999).rand(10000,99999); 145 | $result=$huobi->order()->postPlace([ 146 | 'account-id'=>$account_id, 147 | 'symbol'=>'btcusdt', 148 | 'type'=>'buy-limit', 149 | 'amount'=>'0.001', 150 | 'price'=>'1000', 151 | 'client-order-id'=>$client_order_id, 152 | ]); 153 | print_r($result); 154 | }catch (\Exception $e){ 155 | print_r($e->getMessage()); 156 | } 157 | sleep(1); 158 | 159 | //Get order details by order ID. 160 | try { 161 | $result=$huobi->order()->getClientOrder([ 162 | 'clientOrderId'=>$client_order_id, 163 | ]); 164 | print_r($result); 165 | }catch (\Exception $e){ 166 | print_r($e->getMessage()); 167 | } 168 | sleep(1); 169 | 170 | //Cancelling an unfilled order. 171 | try { 172 | $result=$huobi->order()->postSubmitCancelClientOrder([ 173 | 'client-order-id'=>$client_order_id, 174 | ]); 175 | print_r($result); 176 | }catch (\Exception $e){ 177 | print_r($e->getMessage()); 178 | } 179 | ``` 180 | 181 | Accounts related API [More](https://github.com/zhouaini528/huobi-php/blob/master/tests/spot/account.php) 182 | 183 | ```php 184 | $huobi=new HuobiSpot($key,$secret); 185 | 186 | //get the status of an account 187 | try { 188 | $result=$huobi->account()->get(); 189 | print_r($result); 190 | }catch (\Exception $e){ 191 | print_r($e->getMessage()); 192 | } 193 | 194 | //Get the balance of an account 195 | try { 196 | $result=$huobi->account()->getBalance([ 197 | 'account-id'=>$result['data'][0]['id'] 198 | ]); 199 | print_r($result); 200 | }catch (\Exception $e){ 201 | print_r($e->getMessage()); 202 | } 203 | 204 | ``` 205 | 206 | [More use cases](https://github.com/zhouaini528/huobi-php/tree/master/tests/spot) 207 | 208 | [More API](https://github.com/zhouaini528/huobi-php/tree/master/src/Api/Spot) 209 | 210 | ### Futures Trading API 211 | 212 | Contract related API [More](https://github.com/zhouaini528/huobi-php/blob/master/tests/future/contract.php) 213 | 214 | ```php 215 | $huobi=new HuobiFuture($key,$secret); 216 | 217 | //Place an Order 218 | try { 219 | $result=$huobi->contract()->postOrder([ 220 | 'symbol'=>'BTC',//string false "BTC","ETH"... 221 | 'contract_type'=>'quarter',// string false Contract Type ("this_week": "next_week": "quarter":) 222 | 'contract_code'=>'BTC190628',// string false BTC180914 223 | 'price'=>'100',// decimal true Price 224 | 'volume'=>'1',// long true Numbers of orders (amount) 225 | 'direction'=>'buy',// string true Transaction direction 226 | 'offset'=>'open',// string true "open", "close" 227 | //'client_order_id'=>'',//long false Clients fill and maintain themselves, and this time must be greater than last time 228 | //lever_rate int true Leverage rate [if“Open”is multiple orders in 10 rate, there will be not multiple orders in 20 rate 229 | //order_price_type string true "limit", "opponent" 230 | ]); 231 | print_r($result); 232 | }catch (\Exception $e){ 233 | print_r($e->getMessage()); 234 | } 235 | 236 | //Get Information of an Order 237 | try { 238 | $result=$huobi->contract()->postOrderInfo([ 239 | 'order_id'=>'xxxx',//You can also 'xxxx,xxxx,xxxx' multiple ID 240 | //'client_order_id'=>'xxxx', 241 | 'symbol'=>'BTC' 242 | ]); 243 | print_r($result); 244 | }catch (\Exception $e){ 245 | print_r($e->getMessage()); 246 | } 247 | 248 | //Cancel an Order 249 | try { 250 | $result=$huobi->contract()->postCancel([ 251 | 'order_id'=>'xxxx',//You can also 'xxxx,xxxx,xxxx' multiple ID 252 | //'client_order_id'=>'xxxx', 253 | 'symbol'=>'BTC' 254 | ]); 255 | print_r($result); 256 | }catch (\Exception $e){ 257 | print_r($e->getMessage()); 258 | } 259 | 260 | 261 | 262 | //User`s position Information 263 | try { 264 | $result=$huobi->contract()->postPositionInfo(); 265 | print_r($result); 266 | }catch (\Exception $e){ 267 | print_r($e->getMessage()); 268 | } 269 | 270 | //User`s Account Information 271 | try { 272 | $result=$huobi->contract()->postAccountInfo(); 273 | print_r($result); 274 | }catch (\Exception $e){ 275 | print_r($e->getMessage()); 276 | } 277 | 278 | //Get Contracts Information 279 | try { 280 | $result=$huobi->contract()->getContractInfo(); 281 | print_r($result); 282 | }catch (\Exception $e){ 283 | print_r($e->getMessage()); 284 | } 285 | ``` 286 | 287 | Market related API [More](https://github.com/zhouaini528/huobi-php/blob/master/tests/future/market.php) 288 | 289 | ```php 290 | $huobi=new HuobiFuture(); 291 | 292 | //The Last Trade of a Contract 293 | try { 294 | $result=$huobi->market()->getTrade([ 295 | 'symbol'=>'BTC_CQ' 296 | ]); 297 | print_r($result); 298 | }catch (\Exception $e){ 299 | print_r($e->getMessage()); 300 | } 301 | 302 | //Request a Batch of Trade Records of a Contract 303 | try { 304 | $result=$huobi->market()->getHistoryTrade([ 305 | 'symbol'=>'BTC_CQ', 306 | //'size'=>100 307 | ]); 308 | print_r($result); 309 | }catch (\Exception $e){ 310 | print_r($e->getMessage()); 311 | } 312 | 313 | //Get Market Depth 314 | try { 315 | $result=$huobi->market()->getDepth([ 316 | 'symbol'=>'BTC_CQ', 317 | 'type'=>'step1' 318 | ]); 319 | print_r($result); 320 | }catch (\Exception $e){ 321 | print_r($e->getMessage()); 322 | } 323 | ``` 324 | 325 | [More use cases](https://github.com/zhouaini528/huobi-php/tree/master/tests/future) 326 | 327 | [More API](https://github.com/zhouaini528/huobi-php/tree/master/src/Api/Futures) 328 | 329 | ### Coin Margined Swap API 330 | 331 | ```php 332 | $huobi=new HuobiSwap($key,$secret); 333 | //or new 334 | //$huobi=new HuobiLinear($key,$secret); 335 | 336 | //Place an Order 337 | try { 338 | $result=$huobi->trade()->postOrder([ 339 | 'contract_code'=>'ETH-USD',// string false BTC180914 340 | 'price'=>'100',// decimal true Price 341 | 'volume'=>'1',// long true Numbers of orders (amount) 342 | 'direction'=>'buy',// string true Transaction direction 343 | 'offset'=>'open',// string true "open", "close" 344 | 'order_price_type'=>'limit',//"limit", "opponent" 345 | 'lever_rate'=>20,//int true Leverage rate [if“Open”is multiple orders in 10 rate, there will be not multiple orders in 20 rate 346 | 347 | //'client_order_id'=>'',//long false Clients fill and maintain themselves, and this time must be greater than last time 348 | ]); 349 | print_r($result); 350 | }catch (\Exception $e){ 351 | print_r($e->getMessage()); 352 | } 353 | 354 | //Get Information of an Order 355 | try { 356 | $result=$huobi->trade()->postOrderInfo([ 357 | 'order_id'=>$result['data']['order_id'],//You can also 'xxxx,xxxx,xxxx' multiple ID 358 | //'client_order_id'=>'xxxx', 359 | 'contract_code'=>'ETH-USD' 360 | ]); 361 | print_r($result); 362 | }catch (\Exception $e){ 363 | print_r($e->getMessage()); 364 | } 365 | 366 | //Cancel an Order 367 | try { 368 | $result=$huobi->trade()->postCancel([ 369 | 'order_id'=>$result['data'][0]['order_id'],//You can also 'xxxx,xxxx,xxxx' multiple ID 370 | //'client_order_id'=>'xxxx', 371 | 'contract_code'=>'ETH-USD' 372 | ]); 373 | print_r($result); 374 | }catch (\Exception $e){ 375 | print_r($e->getMessage()); 376 | } 377 | ``` 378 | 379 | [More Test](https://github.com/zhouaini528/huobi-php/tree/master/tests/swap) 380 | 381 | [More Api](https://github.com/zhouaini528/huobi-php/tree/master/src/Api/Swap) 382 | 383 | ### Websocket 384 | 385 | Websocket has two services, server and client. The server is responsible for dealing with the new connection of the exchange, data receiving, authentication and login. Client is responsible for obtaining and processing data.Support 'Spot' and 'Futures' and 'Coin Margined' and 'Swap USDT Margined' and 'Swap Option' 386 | #### Spot Websocket Demo 387 | 388 | Server initialization must be started in Linux CLI mode. 389 | ```php 390 | use \Lin\Huobi\HuobiWebSocket; 391 | require __DIR__ .'./vendor/autoload.php'; 392 | 393 | $huobi=new HuobiWebSocket(); 394 | 395 | $huobi->config([ 396 | //Do you want to enable local logging,default false 397 | //'log'=>true, 398 | //Or set the log name 399 | 'log'=>['filename'=>'spot'], 400 | 401 | //Daemons address and port,default 0.0.0.0:2211 402 | //'global'=>'127.0.0.1:2211', 403 | 404 | //Channel subscription monitoring time,2 seconds 405 | //'listen_time'=>2, 406 | 407 | //Channel data update time,default 0.5 seconds 408 | //'data_time'=>0.5, 409 | 410 | //Number of messages WS queue shuold hold, default 100 411 | //'queue_count'=>100, 412 | 413 | //Set up subscription platform, default 'spot' 414 | 'platform'=>'spot', //options value 'spot' 'future' 'swap' 'linear' 'option' 415 | //Or you can set it like this 416 | 'platform'=>[ 417 | 'type'=>'spot',//options value 'spot' 'future' 'swap' 'linear' 'option' 418 | 'market'=>'ws://api.huobi.pro/ws',//Market Data Request and Subscription 419 | 'order'=>'ws://api.huobi.pro/ws/v2',//Order Push Subscription 420 | 421 | //'market'=>'ws://api-aws.huobi.pro/ws', 422 | //'order'=>'ws://api-aws.huobi.pro/ws/v2', 423 | ], 424 | ]); 425 | 426 | $huobi->start(); 427 | ``` 428 | 429 | If you want to test, you can "php server.php start" immediately outputs the log at the terminal. 430 | 431 | If you want to deploy, you can "php server.php start -d" enables resident process mode, and enables "log=>true" to view logs. 432 | 433 | [More Test](https://github.com/zhouaini528/huobi-php/tree/master/tests/websocket) 434 | 435 | Client side initialization. 436 | ```php 437 | $huobi=new HuobiWebSocket(); 438 | 439 | $huobi->config([ 440 | //Do you want to enable local logging,default false 441 | //'log'=>true, 442 | //Or set the log name 443 | 'log'=>['filename'=>'spot'], 444 | 445 | //Daemons address and port,default 0.0.0.0:2211 446 | //'global'=>'127.0.0.1:2211', 447 | 448 | //Channel subscription monitoring time,2 seconds 449 | //'listen_time'=>2, 450 | 451 | //Channel data update time,default 0.5 seconds 452 | //'data_time'=>0.5, 453 | 454 | //Number of messages WS queue shuold hold, default 100 455 | //'queue_count'=>100, 456 | 457 | //Set up subscription platform, default 'spot' 458 | 'platform'=>'spot', //options value 'spot' 'future' 'swap' 'linear' 'option' 459 | //Or you can set it like this 460 | 'platform'=>[ 461 | 'type'=>'spot',//options value 'spot' 'future' 'swap' 'linear' 'option' 462 | 'market'=>'ws://api.huobi.pro/ws',//Market Data Request and Subscription 463 | 'order'=>'ws://api.huobi.pro/ws/v2',//Order Push Subscription 464 | 465 | //'market'=>'ws://api-aws.huobi.pro/ws', 466 | //'order'=>'ws://api-aws.huobi.pro/ws/v2', 467 | ], 468 | ]); 469 | ``` 470 | 471 | Subscribe 472 | ```php 473 | //You can only subscribe to public channels 474 | $huobi->subscribe([ 475 | 'market.btcusdt.depth.step0', 476 | 'market.bchusdt.depth.step0', 477 | ]); 478 | 479 | //You can also subscribe to both private and public channels.If keysecret() is set, all private channels will be subscribed by default 480 | $huobi->keysecret([ 481 | 'key'=>'xxxxxxxxx', 482 | 'secret'=>'xxxxxxxxx', 483 | ]); 484 | $huobi->subscribe([ 485 | //market 486 | 'market.btcusdt.depth.step0', 487 | 'market.bchusdt.depth.step0', 488 | 489 | //private 490 | 'orders#btcusdt', 491 | 'trade.clearing#btcusdt#1', 492 | 'accounts.update#1', 493 | ]); 494 | ``` 495 | 496 | Unsubscribe 497 | ```php 498 | //Unsubscribe from public channels 499 | $huobi->unsubscribe([ 500 | 'market.btcusdt.depth.step0', 501 | 'market.bchusdt.depth.step0', 502 | ]); 503 | 504 | //Unsubscribe from public and private channels.If keysecret() is set, all private channels will be Unsubscribed by default 505 | $huobi->keysecret([ 506 | 'key'=>'xxxxxxxxx', 507 | 'secret'=>'xxxxxxxxx', 508 | ]); 509 | $huobi->unsubscribe([ 510 | //market 511 | 'market.btcusdt.depth.step0', 512 | 'market.bchusdt.depth.step0', 513 | 514 | //private 515 | 'orders#btcusdt', 516 | 'trade.clearing#btcusdt#1', 517 | 'accounts.update#1', 518 | ]); 519 | ``` 520 | 521 | Get all channel subscription data 522 | ```php 523 | //The first way 524 | $data=$huobi->getSubscribe(); 525 | print_r(json_encode($data)); 526 | 527 | //The second way callback 528 | $huobi->getSubscribe(function($data){ 529 | print_r(json_encode($data)); 530 | }); 531 | 532 | //The third way is to guard the process 533 | $huobi->getSubscribe(function($data){ 534 | print_r(json_encode($data)); 535 | },true); 536 | ``` 537 | 538 | Get partial channel subscription data 539 | ```php 540 | //The first way 541 | $data=$huobi->getSubscribe([ 542 | 'market.btcusdt.depth.step0', 543 | 'market.bchusdt.depth.step0', 544 | ]); 545 | print_r(json_encode($data)); 546 | 547 | //The second way callback 548 | $huobi->getSubscribe([ 549 | 'market.btcusdt.depth.step0', 550 | 'market.bchusdt.depth.step0', 551 | ],function($data){ 552 | print_r(json_encode($data)); 553 | }); 554 | 555 | //The third way is to guard the process 556 | $huobi->getSubscribe([ 557 | 'market.btcusdt.depth.step0', 558 | 'market.bchusdt.depth.step0', 559 | ],function($data){ 560 | print_r(json_encode($data)); 561 | },true); 562 | ``` 563 | 564 | Get partial private channel subscription data 565 | ```php 566 | //The first way 567 | $huobi->keysecret($key_secret); 568 | $data=$huobi->getSubscribe();//Return all data of private channel 569 | print_r(json_encode($data)); 570 | 571 | //The second way callback 572 | $huobi->keysecret($key_secret); 573 | $huobi->getSubscribe([//Return data private and market 574 | //market 575 | 'market.btcusdt.depth.step0', 576 | 'market.bchusdt.depth.step0', 577 | 578 | //private 579 | 'orders#btcusdt', 580 | 'trade.clearing#btcusdt#1', 581 | 'accounts.update#1', 582 | ],function($data){ 583 | print_r(json_encode($data)); 584 | }); 585 | 586 | //The third way is to guard the process 587 | $huobi->keysecret($key_secret); 588 | $huobi->getSubscribe([//Resident process to get data return frequency $huobi->config['data_time']=0.5s 589 | //market 590 | 'market.btcusdt.depth.step0', 591 | 'market.bchusdt.depth.step0', 592 | 593 | //private 594 | 'orders#btcusdt', 595 | 'trade.clearing#btcusdt#1', 596 | 'accounts.update#1', 597 | ],function($data){ 598 | print_r(json_encode($data)); 599 | },true); 600 | ``` 601 | 602 | [Spot Websocket More Test](https://github.com/zhouaini528/huobi-php/tree/master/tests/websocket/client_spot.php) 603 | 604 | [Futures Websocket More Test](https://github.com/zhouaini528/huobi-php/tree/master/tests/websocket/client_future.php) 605 | 606 | [Coin Margined Websocket More Test](https://github.com/zhouaini528/huobi-php/tree/master/tests/websocket/client_swap.php) 607 | 608 | [Swap USDT Margined Websocket More Test](https://github.com/zhouaini528/huobi-php/tree/master/tests/websocket/client_linear.php) 609 | 610 | -------------------------------------------------------------------------------- /README_CN.md: -------------------------------------------------------------------------------- 1 | ### 建议您先阅读官方文档 2 | 3 | Huobi 文档地址 [https://huobiapi.github.io/docs/spot/v1/cn/#api](https://huobiapi.github.io/docs/spot/v1/cn/#api) 4 | 5 | 所有接口方法的初始化都与huobi提供的方法相同。更多细节 [src/api](https://github.com/zhouaini528/huobi-php/tree/master/src/Api) 6 | 7 | 支持[Websocket](https://github.com/zhouaini528/huobi-php/blob/master/README_CN.md#Websocket) 8 | 9 | 大部分的接口已经完成,使用者可以根据我的设计方案继续扩展,欢迎与我一起迭代它。 10 | 11 | [English Document](https://github.com/zhouaini528/huobi-php/blob/master/README.md) 12 | 13 | QQ交流群:668421169 14 | 15 | ### 其他交易所API 16 | 17 | [Exchanges](https://github.com/zhouaini528/exchanges-php) 它包含以下所有交易所,强烈推荐使用该SDK。 18 | 19 | [Bitmex](https://github.com/zhouaini528/bitmex-php) 支持[Websocket](https://github.com/zhouaini528/bitmex-php/blob/master/README_CN.md#Websocket) 20 | 21 | [Okex](https://github.com/zhouaini528/okex-php) 支持[Websocket](https://github.com/zhouaini528/okex-php/blob/master/README_CN.md#Websocket) 22 | 23 | [Huobi](https://github.com/zhouaini528/huobi-php) 支持[Websocket](https://github.com/zhouaini528/huobi-php/blob/master/README_CN.md#Websocket) 24 | 25 | [Binance](https://github.com/zhouaini528/binance-php) 支持[Websocket](https://github.com/zhouaini528/binance-php/blob/master/README_CN.md#Websocket) 26 | 27 | [Kucoin](https://github.com/zhouaini528/kucoin-php) 28 | 29 | [Mxc](https://github.com/zhouaini528/mxc-php) 30 | 31 | [Coinbase](https://github.com/zhouaini528/coinbase-php) 32 | 33 | [ZB](https://github.com/zhouaini528/zb-php) 34 | 35 | [Bitfinex](https://github.com/zhouaini528/zb-php) 36 | 37 | [Bittrex](https://github.com/zhouaini528/bittrex-php) 38 | 39 | [Kraken](https://github.com/zhouaini528/kraken-php) 40 | 41 | [Gate](https://github.com/zhouaini528/gate-php) 42 | 43 | [Bigone](https://github.com/zhouaini528/bigone-php) 44 | 45 | [Crex24](https://github.com/zhouaini528/crex24-php) 46 | 47 | [Bybit](https://github.com/zhouaini528/bybit-php) 48 | 49 | [Coinbene](https://github.com/zhouaini528/coinbene-php) 50 | 51 | [Bitget](https://github.com/zhouaini528/bitget-php) 52 | 53 | [Poloniex](https://github.com/zhouaini528/poloniex-php) 54 | 55 | #### 安装方式 56 | ``` 57 | composer require linwj/huobi 58 | ``` 59 | 60 | 支持更多的请求设置 [More](https://github.com/zhouaini528/huobi-php/blob/master/tests/spot/proxy.php#L21) 61 | ```php 62 | $huobi=new HuobiSpot(); 63 | 64 | //You can set special needs 65 | $huobi->setOptions([ 66 | //Set the request timeout to 60 seconds by default 67 | 'timeout'=>10, 68 | //https://github.com/guzzle/guzzle 69 | 'proxy'=>[], 70 | //https://www.php.net/manual/en/book.curl.php 71 | 'curl'=>[], 72 | ]); 73 | ``` 74 | 75 | ### 现货交易 API 76 | 77 | Market related API [More](https://github.com/zhouaini528/huobi-php/blob/master/tests/spot/market.php) 78 | ```php 79 | $huobi=new HuobiSpot(); 80 | 81 | //Get market data. This endpoint provides the snapshots of market data and can be used without verifications. 82 | try { 83 | $result=$huobi->market()->getDepth([ 84 | 'symbol'=>'btcusdt', 85 | //'type'=>'step3' default step0 86 | ]); 87 | print_r($result); 88 | }catch (\Exception $e){ 89 | print_r($e->getMessage()); 90 | } 91 | 92 | //List trading pairs and get the trading limit, price, and more information of different trading pairs. 93 | try { 94 | $result=$huobi->market()->getTickers(); 95 | print_r($result); 96 | }catch (\Exception $e){ 97 | print_r($e->getMessage()); 98 | } 99 | ``` 100 | 101 | Order related API [More](https://github.com/zhouaini528/huobi-php/blob/master/tests/spot/order.php) 102 | ```php 103 | $huobi=new HuobiSpot($key,$secret); 104 | 105 | //Place an Order 106 | try { 107 | $result=$huobi->order()->postPlace([ 108 | 'account-id'=>$account_id, 109 | 'symbol'=>'btcusdt', 110 | 'type'=>'buy-limit', 111 | 'amount'=>'0.001', 112 | 'price'=>'100', 113 | ]); 114 | print_r($result); 115 | }catch (\Exception $e){ 116 | print_r($e->getMessage()); 117 | } 118 | sleep(1); 119 | 120 | //Get order details by order ID. 121 | try { 122 | $result=$huobi->order()->get([ 123 | 'order-id'=>$result['data'], 124 | ]); 125 | print_r($result); 126 | }catch (\Exception $e){ 127 | print_r($e->getMessage()); 128 | } 129 | sleep(1); 130 | 131 | //Cancelling an unfilled order. 132 | try { 133 | $result=$huobi->order()->postSubmitCancel([ 134 | 'order-id'=>$result['data']['id'], 135 | ]); 136 | print_r($result); 137 | }catch (\Exception $e){ 138 | print_r($e->getMessage()); 139 | } 140 | 141 | //***********************Customize the order ID 142 | //Place an Order 143 | try { 144 | $client_order_id=rand(10000,99999).rand(10000,99999); 145 | $result=$huobi->order()->postPlace([ 146 | 'account-id'=>$account_id, 147 | 'symbol'=>'btcusdt', 148 | 'type'=>'buy-limit', 149 | 'amount'=>'0.001', 150 | 'price'=>'1000', 151 | 'client-order-id'=>$client_order_id, 152 | ]); 153 | print_r($result); 154 | }catch (\Exception $e){ 155 | print_r($e->getMessage()); 156 | } 157 | sleep(1); 158 | 159 | //Get order details by order ID. 160 | try { 161 | $result=$huobi->order()->getClientOrder([ 162 | 'clientOrderId'=>$client_order_id, 163 | ]); 164 | print_r($result); 165 | }catch (\Exception $e){ 166 | print_r($e->getMessage()); 167 | } 168 | sleep(1); 169 | 170 | //Cancelling an unfilled order. 171 | try { 172 | $result=$huobi->order()->postSubmitCancelClientOrder([ 173 | 'client-order-id'=>$client_order_id, 174 | ]); 175 | print_r($result); 176 | }catch (\Exception $e){ 177 | print_r($e->getMessage()); 178 | } 179 | ``` 180 | 181 | Accounts related API [More](https://github.com/zhouaini528/huobi-php/blob/master/tests/spot/account.php) 182 | ```php 183 | $huobi=new HuobiSpot($key,$secret); 184 | 185 | //get the status of an account 186 | try { 187 | $result=$huobi->account()->get(); 188 | print_r($result); 189 | }catch (\Exception $e){ 190 | print_r($e->getMessage()); 191 | } 192 | 193 | //Get the balance of an account 194 | try { 195 | $result=$huobi->account()->getBalance([ 196 | 'account-id'=>$result['data'][0]['id'] 197 | ]); 198 | print_r($result); 199 | }catch (\Exception $e){ 200 | print_r($e->getMessage()); 201 | } 202 | 203 | ``` 204 | 205 | [更多用例](https://github.com/zhouaini528/huobi-php/tree/master/tests/spot) 206 | 207 | [更多API](https://github.com/zhouaini528/huobi-php/tree/master/src/Api/Spot) 208 | 209 | ### 期货交割合约 API 210 | 211 | Contract related API [More](https://github.com/zhouaini528/huobi-php/blob/master/tests/future/contract.php) 212 | 213 | ```php 214 | $huobi=new HuobiFuture($key,$secret); 215 | 216 | //Place an Order 217 | try { 218 | $result=$huobi->contract()->postOrder([ 219 | 'symbol'=>'BTC',//string false "BTC","ETH"... 220 | 'contract_type'=>'quarter',// string false Contract Type ("this_week": "next_week": "quarter":) 221 | 'contract_code'=>'BTC190628',// string false BTC180914 222 | 'price'=>'100',// decimal true Price 223 | 'volume'=>'1',// long true Numbers of orders (amount) 224 | 'direction'=>'buy',// string true Transaction direction 225 | 'offset'=>'open',// string true "open", "close" 226 | //'client_order_id'=>'',//long false Clients fill and maintain themselves, and this time must be greater than last time 227 | //lever_rate int true Leverage rate [if“Open”is multiple orders in 10 rate, there will be not multiple orders in 20 rate 228 | //order_price_type string true "limit", "opponent" 229 | ]); 230 | print_r($result); 231 | }catch (\Exception $e){ 232 | print_r($e->getMessage()); 233 | } 234 | 235 | //Get Information of an Order 236 | try { 237 | $result=$huobi->contract()->postOrderInfo([ 238 | 'order_id'=>'xxxx',//You can also 'xxxx,xxxx,xxxx' multiple ID 239 | //'client_order_id'=>'xxxx', 240 | 'symbol'=>'BTC' 241 | ]); 242 | print_r($result); 243 | }catch (\Exception $e){ 244 | print_r($e->getMessage()); 245 | } 246 | 247 | //Cancel an Order 248 | try { 249 | $result=$huobi->contract()->postCancel([ 250 | 'order_id'=>'xxxx',//You can also 'xxxx,xxxx,xxxx' multiple ID 251 | //'client_order_id'=>'xxxx', 252 | 'symbol'=>'BTC' 253 | ]); 254 | print_r($result); 255 | }catch (\Exception $e){ 256 | print_r($e->getMessage()); 257 | } 258 | 259 | 260 | 261 | //User`s position Information 262 | try { 263 | $result=$huobi->contract()->postPositionInfo(); 264 | print_r($result); 265 | }catch (\Exception $e){ 266 | print_r($e->getMessage()); 267 | } 268 | 269 | //User`s Account Information 270 | try { 271 | $result=$huobi->contract()->postAccountInfo(); 272 | print_r($result); 273 | }catch (\Exception $e){ 274 | print_r($e->getMessage()); 275 | } 276 | 277 | //Get Contracts Information 278 | try { 279 | $result=$huobi->contract()->getContractInfo(); 280 | print_r($result); 281 | }catch (\Exception $e){ 282 | print_r($e->getMessage()); 283 | } 284 | ``` 285 | 286 | Market related API [More](https://github.com/zhouaini528/huobi-php/blob/master/tests/future/market.php) 287 | ```php 288 | $huobi=new HuobiFuture(); 289 | 290 | //The Last Trade of a Contract 291 | try { 292 | $result=$huobi->market()->getTrade([ 293 | 'symbol'=>'BTC_CQ' 294 | ]); 295 | print_r($result); 296 | }catch (\Exception $e){ 297 | print_r($e->getMessage()); 298 | } 299 | 300 | //Request a Batch of Trade Records of a Contract 301 | try { 302 | $result=$huobi->market()->getHistoryTrade([ 303 | 'symbol'=>'BTC_CQ', 304 | //'size'=>100 305 | ]); 306 | print_r($result); 307 | }catch (\Exception $e){ 308 | print_r($e->getMessage()); 309 | } 310 | 311 | //Get Market Depth 312 | try { 313 | $result=$huobi->market()->getDepth([ 314 | 'symbol'=>'BTC_CQ', 315 | 'type'=>'step1' 316 | ]); 317 | print_r($result); 318 | }catch (\Exception $e){ 319 | print_r($e->getMessage()); 320 | } 321 | ``` 322 | 323 | [更多用例](https://github.com/zhouaini528/huobi-php/tree/master/tests/future) 324 | 325 | [更多API](https://github.com/zhouaini528/huobi-php/tree/master/src/Api/Futures) 326 | 327 | 328 | ### 期货永续合约 API 329 | 330 | ```php 331 | $huobi=new HuobiSwap($key,$secret); 332 | //or new 333 | //$huobi=new HuobiLinear($key,$secret); 334 | 335 | //Place an Order 336 | try { 337 | $result=$huobi->trade()->postOrder([ 338 | 'contract_code'=>'ETH-USD',// string false BTC180914 339 | 'price'=>'100',// decimal true Price 340 | 'volume'=>'1',// long true Numbers of orders (amount) 341 | 'direction'=>'buy',// string true Transaction direction 342 | 'offset'=>'open',// string true "open", "close" 343 | 'order_price_type'=>'limit',//"limit", "opponent" 344 | 'lever_rate'=>20,//int true Leverage rate [if“Open”is multiple orders in 10 rate, there will be not multiple orders in 20 rate 345 | 346 | //'client_order_id'=>'',//long false Clients fill and maintain themselves, and this time must be greater than last time 347 | ]); 348 | print_r($result); 349 | }catch (\Exception $e){ 350 | print_r($e->getMessage()); 351 | } 352 | 353 | //Get Information of an Order 354 | try { 355 | $result=$huobi->trade()->postOrderInfo([ 356 | 'order_id'=>$result['data']['order_id'],//You can also 'xxxx,xxxx,xxxx' multiple ID 357 | //'client_order_id'=>'xxxx', 358 | 'contract_code'=>'ETH-USD' 359 | ]); 360 | print_r($result); 361 | }catch (\Exception $e){ 362 | print_r($e->getMessage()); 363 | } 364 | 365 | //Cancel an Order 366 | try { 367 | $result=$huobi->trade()->postCancel([ 368 | 'order_id'=>$result['data'][0]['order_id'],//You can also 'xxxx,xxxx,xxxx' multiple ID 369 | //'client_order_id'=>'xxxx', 370 | 'contract_code'=>'ETH-USD' 371 | ]); 372 | print_r($result); 373 | }catch (\Exception $e){ 374 | print_r($e->getMessage()); 375 | } 376 | ``` 377 | 378 | [更多用例](https://github.com/zhouaini528/huobi-php/tree/master/tests/swap) 379 | 380 | [更多API](https://github.com/zhouaini528/huobi-php/tree/master/src/Api/Swap) 381 | 382 | ### Websocket 383 | 384 | Websocket有两个服务server和client,server负责处理交易所新连接、数据接收、认证登陆等等。client负责获取数据、处理数据。支持现货(spot)、交割合约(future)、永续合约(swap)、USDT永续合约(linear) 385 | 386 | Server端初始化,必须在Linux cli模式下开启。[Websocket行情应用举例](https://github.com/zhouaini528/websocket-market) 387 | 388 | #### 现货websocket为例 389 | 390 | Server端初始化,必须在cli模式下开启。 391 | ```php 392 | use \Lin\Huobi\HuobiWebSocket; 393 | require __DIR__ .'./vendor/autoload.php'; 394 | 395 | $huobi=new HuobiWebSocket(); 396 | 397 | $huobi->config([ 398 | //是否开启日志,默认未开启 false 399 | //'log'=>true, 400 | //可以设置日志名称,默认开启日志 401 | 'log'=>['filename'=>'spot'], 402 | 403 | //进程服务端口地址,默认 0.0.0.0:2211 404 | //'global'=>'127.0.0.1:2211', 405 | 406 | //频道数据更新时间,默认 0.5 秒 407 | //'data_time'=>0.5, 408 | 409 | //私有数据队列默认保存100条 410 | //'queue_count'=>100, 411 | 412 | //设置订阅平台, 默认 'spot' 413 | 'platform'=>'spot', //参数值为 'spot' 'future' 'swap' 'linear' 'option' 414 | //或者也可以这样更灵活的设置 415 | 'platform'=>[ 416 | 'type'=>'spot',//参数值为 'spot' 'future' 'swap' 'linear' 'option' 417 | 'market'=>'ws://api.huobi.pro/ws',//行情地址 418 | 'order'=>'ws://api.huobi.pro/ws/v2',//订单地址 419 | 420 | //'market'=>'ws://api-aws.huobi.pro/ws', 421 | //'order'=>'ws://api-aws.huobi.pro/ws/v2', 422 | ], 423 | ]); 424 | 425 | $huobi->start(); 426 | ``` 427 | 428 | 如果你要测试,你可以 php server.php start 可以在终端即时输出日志。 429 | 430 | 如果你要部署,你可以 php server.php start -d 开启常驻进程模式,并开启'log'=>true 查看日志。 431 | 432 | [更多用例请查看](https://github.com/zhouaini528/huobi-php/tree/master/tests/websocket) 433 | 434 | 435 | Client端初始化。 436 | ```php 437 | $huobi=new HuobiWebSocket(); 438 | 439 | $huobi->config([ 440 | //是否开启日志,默认未开启 false 441 | //'log'=>true, 442 | //可以设置日志名称,默认开启日志 443 | 'log'=>['filename'=>'spot'], 444 | 445 | //进程服务端口地址,默认 0.0.0.0:2211 446 | //'global'=>'127.0.0.1:2211', 447 | 448 | //频道数据更新时间,默认 0.5 秒 449 | //'data_time'=>0.5, 450 | 451 | //私有数据队列默认保存100条 452 | //'queue_count'=>100, 453 | 454 | //设置订阅平台, 默认 'spot' 455 | 'platform'=>'spot', //参数值为 'spot' 'future' 'swap' 'linear' 'option' 456 | //或者也可以这样更灵活的设置 457 | 'platform'=>[ 458 | 'type'=>'spot',//参数值为 'spot' 'future' 'swap' 'linear' 'option' 459 | 'market'=>'ws://api.huobi.pro/ws',//行情地址 460 | 'order'=>'ws://api.huobi.pro/ws/v2',//订单地址 461 | 462 | //'market'=>'ws://api-aws.huobi.pro/ws', 463 | //'order'=>'ws://api-aws.huobi.pro/ws/v2', 464 | ], 465 | ]); 466 | ``` 467 | 468 | 频道订阅 469 | ```php 470 | //你可以只订阅公共频道 471 | $huobi->subscribe([ 472 | 'market.btcusdt.depth.step0', 473 | 'market.bchusdt.depth.step0', 474 | ]); 475 | 476 | //你也可以私人频道与公共频道混合订阅,设置了keysecret默认会订阅私人所有频道 477 | $huobi->keysecret([ 478 | 'key'=>'xxxxxxxxx', 479 | 'secret'=>'xxxxxxxxx', 480 | ]); 481 | $huobi->subscribe([ 482 | //market 483 | 'market.btcusdt.depth.step0', 484 | 'market.bchusdt.depth.step0', 485 | 486 | //private 487 | 'orders#btcusdt', 488 | 'trade.clearing#btcusdt#1', 489 | 'accounts.update#1', 490 | ]); 491 | ``` 492 | 493 | 频道订阅取消 494 | ```php 495 | //取消订阅公共频道 496 | $huobi->unsubscribe([ 497 | 'market.btcusdt.depth.step0', 498 | 'market.bchusdt.depth.step0', 499 | ]); 500 | 501 | //取消私人频道与公共频道混合订阅,设置了keysecret默认会取消订阅私人所有频道 502 | $huobi->keysecret([ 503 | 'key'=>'xxxxxxxxx', 504 | 'secret'=>'xxxxxxxxx', 505 | ]); 506 | $huobi->unsubscribe([ 507 | //market 508 | 'market.btcusdt.depth.step0', 509 | 'market.bchusdt.depth.step0', 510 | 511 | //private 512 | 'orders#btcusdt', 513 | 'trade.clearing#btcusdt#1', 514 | 'accounts.update#1', 515 | ]); 516 | ``` 517 | 518 | 获取全部频道订阅数据 519 | ```php 520 | //第一种方式,直接获取当前最新数据 521 | $data=$huobi->getSubscribes(); 522 | print_r(json_encode($data)); 523 | 524 | 525 | //第二种方式,通过回调函数,获取当前最新数据 526 | $huobi->getSubscribes(function($data){ 527 | print_r(json_encode($data)); 528 | }); 529 | 530 | //第二种方式,通过回调函数并开启常驻进程,获取当前最新数据 531 | $huobi->getSubscribes(function($data){ 532 | print_r(json_encode($data)); 533 | },true); 534 | ``` 535 | 536 | 获取部分频道订阅数据 537 | ```php 538 | //The first way 539 | $data=$huobi->getSubscribe([ 540 | 'market.btcusdt.depth.step0', 541 | 'market.bchusdt.depth.step0', 542 | ]); 543 | print_r(json_encode($data)); 544 | 545 | //The second way callback 546 | $huobi->getSubscribe([ 547 | 'market.btcusdt.depth.step0', 548 | 'market.bchusdt.depth.step0', 549 | ],function($data){ 550 | print_r(json_encode($data)); 551 | }); 552 | 553 | //The third way is to guard the process 554 | $huobi->getSubscribe([ 555 | 'market.btcusdt.depth.step0', 556 | 'market.bchusdt.depth.step0', 557 | ],function($data){ 558 | print_r(json_encode($data)); 559 | },true); 560 | ``` 561 | 562 | 获取私有频道订阅数据 563 | ```php 564 | //The first way 565 | $huobi->keysecret($key_secret); 566 | $data=$huobi->getSubscribe();//返回私有频道所有数据 567 | print_r(json_encode($data)); 568 | 569 | //The second way callback 570 | $huobi->keysecret($key_secret); 571 | $huobi->getSubscribe([//以回调方法返回数据 572 | //market 573 | 'market.btcusdt.depth.step0', 574 | 'market.bchusdt.depth.step0', 575 | 576 | //private 577 | 'orders#btcusdt', 578 | 'trade.clearing#btcusdt#1', 579 | 'accounts.update#1', 580 | ],function($data){ 581 | print_r(json_encode($data)); 582 | }); 583 | 584 | //The third way is to guard the process 585 | $huobi->keysecret($key_secret); 586 | $huobi->getSubscribe([//以开启常驻进程方法获取数据,数据返回频率 $huobi->config['data_time']=0.5s 587 | //market 588 | 'market.btcusdt.depth.step0', 589 | 'market.bchusdt.depth.step0', 590 | 591 | //private 592 | 'orders#btcusdt', 593 | 'trade.clearing#btcusdt#1', 594 | 'accounts.update#1', 595 | ],function($data){ 596 | print_r(json_encode($data)); 597 | },true); 598 | ``` 599 | 600 | [现货websocket(spot)更多用例](https://github.com/zhouaini528/huobi-php/tree/master/tests/websocket/client_spot.php) 601 | 602 | [交割合约websocket(future)更多用例](https://github.com/zhouaini528/huobi-php/tree/master/tests/websocket/client_future.php) 603 | 604 | [永续合约websocket(swap)更多用例](https://github.com/zhouaini528/huobi-php/tree/master/tests/websocket/client_swap.php) 605 | 606 | [USDT永续合约websocket(linear)更多用例](https://github.com/zhouaini528/huobi-php/tree/master/tests/websocket/client_linear.php) 607 | 608 | **如果你觉得对你有帮助,谢谢你的打赏** 609 | 610 | ![zhifubao](https://user-images.githubusercontent.com/5442664/122150914-303fcf00-ce91-11eb-91bd-7f7a24c9ab03.jpg) 611 | 612 | ![weixin](https://user-images.githubusercontent.com/5442664/122150967-4a79ad00-ce91-11eb-866f-4e5f6c859269.jpg) 613 | 614 | 615 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "linwj/huobi", 3 | "type": "library", 4 | "description": "Huobi API Like the official document interface, Support for arbitrary extension.", 5 | "license": "MIT", 6 | "keywords": ["bitmex", "binance", "okex", "huobi","kucoin","kumex"], 7 | "authors": [ 8 | { 9 | "name": "linwenjun", 10 | "email": "465382251@qq.com" 11 | } 12 | ], 13 | "autoload": { 14 | "psr-4": { 15 | "Lin\\Huobi\\": "./src/" 16 | } 17 | }, 18 | "require": { 19 | "php": ">=7.0", 20 | "guzzlehttp/guzzle": "*", 21 | "workerman/workerman": "*", 22 | "workerman/globaldata": "*" 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/Api/Futures/Contract.php: -------------------------------------------------------------------------------- 1 | 4 | * */ 5 | 6 | namespace Lin\Huobi\Api\Futures; 7 | 8 | 9 | 10 | use Lin\Huobi\Request; 11 | 12 | class Contract extends Request 13 | { 14 | /** 15 | * Restful 基础信息接口 api/v1/contract_contract_info GET 获取合约信息 否 16 | * 17 | * symbol string false "BTC","ETH"... 18 | contract_type string false 合约类型: (this_week:当周 next_week:下周 quarter:季度) 19 | contract_code string false BTC180914 20 | * */ 21 | public function getContractInfo(array $data=[]){ 22 | $this->type='GET'; 23 | $this->path='/api/v1/contract_contract_info'; 24 | $this->data=$data; 25 | return $this->exec(); 26 | } 27 | 28 | /** 29 | * GET api/v1/contract_index 30 | * */ 31 | public function getIndex(array $data=[]){ 32 | $this->type='GET'; 33 | $this->path='/api/v1/contract_index'; 34 | $this->data=$data; 35 | return $this->exec(); 36 | } 37 | 38 | /** 39 | * GET api/v1/contract_price_limit 40 | * */ 41 | public function getPriceLimit(array $data=[]){ 42 | $this->type='GET'; 43 | $this->path='/api/v1/contract_price_limit'; 44 | $this->data=$data; 45 | return $this->exec(); 46 | } 47 | 48 | /** 49 | * GET api/v1/contract_open_interest 50 | * */ 51 | public function getOpenInterest(array $data=[]){ 52 | $this->type='GET'; 53 | $this->path='/api/v1/contract_open_interest'; 54 | $this->data=$data; 55 | return $this->exec(); 56 | } 57 | 58 | /** 59 | *GET api/v1/contract_delivery_price 60 | * */ 61 | public function getDeliveryPrice(array $data=[]){ 62 | $this->type='GET'; 63 | $this->path='/api/v1/contract_delivery_price'; 64 | $this->data=$data; 65 | return $this->exec(); 66 | } 67 | 68 | /** 69 | *GET api/v1/contract_risk_info 70 | * */ 71 | public function getRiskInfo(array $data=[]){ 72 | $this->type='GET'; 73 | $this->path='/api/v1/contract_risk_info'; 74 | $this->data=$data; 75 | return $this->exec(); 76 | } 77 | 78 | /** 79 | *GET `api/v1/contract_insurance_fund 80 | * */ 81 | public function getInsuranceFund(array $data=[]){ 82 | $this->type='GET'; 83 | $this->path='/api/v1/contract_insurance_fund'; 84 | $this->data=$data; 85 | return $this->exec(); 86 | } 87 | 88 | /** 89 | *GET api/v1/contract_adjustfactor 90 | * */ 91 | public function getAdjustfactor(array $data=[]){ 92 | $this->type='GET'; 93 | $this->path='/api/v1/contract_adjustfactor'; 94 | $this->data=$data; 95 | return $this->exec(); 96 | } 97 | 98 | /** 99 | *GET api/v1/contract_his_open_interest 100 | * */ 101 | public function getHisOpenInterest(array $data=[]){ 102 | $this->type='GET'; 103 | $this->path='/api/v1/contract_his_open_interest'; 104 | $this->data=$data; 105 | return $this->exec(); 106 | } 107 | 108 | 109 | /** 110 | *GET api/v1/contract_elite_account_ratio 111 | * */ 112 | public function getEliteAccountRatio(array $data=[]){ 113 | $this->type='GET'; 114 | $this->path='/api/v1/contract_elite_account_ratio'; 115 | $this->data=$data; 116 | return $this->exec(); 117 | } 118 | 119 | /** 120 | *GET api/v1/contract_elite_position_ratio 121 | * */ 122 | public function getElitePositionRatio(array $data=[]){ 123 | $this->type='GET'; 124 | $this->path='/api/v1/contract_elite_position_ratio'; 125 | $this->data=$data; 126 | return $this->exec(); 127 | } 128 | 129 | /** 130 | *GET api/v1/contract_liquidation_orders 131 | * */ 132 | public function getLiquidationOrders(array $data=[]){ 133 | $this->type='GET'; 134 | $this->path='/api/v1/contract_liquidation_orders'; 135 | $this->data=$data; 136 | return $this->exec(); 137 | } 138 | 139 | /** 140 | * 141 | * */ 142 | /* public function get(array $data=[]){ 143 | $this->type='GET'; 144 | $this->path=''; 145 | $this->data=$data; 146 | return $this->exec(); 147 | } */ 148 | 149 | 150 | /** 151 | * 获取用户账户信息 152 | * symbol false string 品种代码 "BTC","ETH"...如果缺省,默认返回所有品种 153 | * */ 154 | public function postAccountInfo(array $data=[]){ 155 | $this->type='POST'; 156 | $this->path='/api/v1/contract_account_info'; 157 | $this->data=$data; 158 | return $this->exec(); 159 | } 160 | 161 | /** 162 | * 获取用户持仓信息 163 | * symbol false string 品种代码 "BTC","ETH"...如果缺省,默认返回所有品种 164 | * */ 165 | public function postPositionInfo(array $data=[]){ 166 | $this->type='POST'; 167 | $this->path='/api/v1/contract_position_info'; 168 | $this->data=$data; 169 | return $this->exec(); 170 | } 171 | 172 | /** 173 | * POST api/v1/contract_sub_account_list 174 | * */ 175 | public function postSubAccountList(array $data=[]){ 176 | $this->type='POST'; 177 | $this->path='/api/v1/contract_sub_account_list'; 178 | $this->data=$data; 179 | return $this->exec(); 180 | } 181 | 182 | /** 183 | *POST api/v1/contract_sub_account_info 184 | * */ 185 | public function postSubAccountInfo(array $data=[]){ 186 | $this->type='POST'; 187 | $this->path='api/v1/contract_sub_account_info'; 188 | $this->data=$data; 189 | return $this->exec(); 190 | } 191 | 192 | /** 193 | *POST api/v1/contract_sub_position_info 194 | * */ 195 | public function postSubPositionInfo(array $data=[]){ 196 | $this->type='POST'; 197 | $this->path='/api/v1/contract_sub_position_info'; 198 | $this->data=$data; 199 | return $this->exec(); 200 | } 201 | 202 | /** 203 | *POST api/v1/contract_financial_record 204 | * */ 205 | public function postFinancialRecord(array $data=[]){ 206 | $this->type='POST'; 207 | $this->path='/api/v1/contract_financial_record'; 208 | $this->data=$data; 209 | return $this->exec(); 210 | } 211 | 212 | /** 213 | *POST api/v1/contract_order_limit 214 | * */ 215 | public function postOrderLimit(array $data=[]){ 216 | $this->type='POST'; 217 | $this->path='/api/v1/contract_order_limit'; 218 | $this->data=$data; 219 | return $this->exec(); 220 | } 221 | 222 | /** 223 | *POST api/v1/contract_fee 224 | * */ 225 | public function postFee(array $data=[]){ 226 | $this->type='POST'; 227 | $this->path='/api/v1/contract_fee'; 228 | $this->data=$data; 229 | return $this->exec(); 230 | } 231 | 232 | /** 233 | *POST api/v1/contract_transfer_limit 234 | * */ 235 | public function postTransferLimit(array $data=[]){ 236 | $this->type='POST'; 237 | $this->path='/api/v1/contract_transfer_limit'; 238 | $this->data=$data; 239 | return $this->exec(); 240 | } 241 | 242 | /** 243 | *post api/v1/contract_position_limit 244 | * */ 245 | public function postPositionLimit(array $data=[]){ 246 | $this->type='POST'; 247 | $this->path='/api/v1/contract_position_limit'; 248 | $this->data=$data; 249 | return $this->exec(); 250 | } 251 | 252 | /** 253 | *post api/v1/contract_account_position_info 254 | * */ 255 | public function postAccountPositionInfo(array $data=[]){ 256 | $this->type='POST'; 257 | $this->path='/api/v1/contract_account_position_info'; 258 | $this->data=$data; 259 | return $this->exec(); 260 | } 261 | 262 | /** 263 | * 合约下单 264 | * 参数名 参数类型 必填 描述 265 | symbol string true "BTC","ETH"... 266 | contract_type string true 合约类型 ("this_week":当周 "next_week":下周 "quarter":季度) 267 | contract_code string true BTC180914 268 | client_order_id long false 客户自己填写和维护,这次一定要大于上一次 269 | price decimal true 价格 270 | volume long true 委托数量(张) 271 | direction string true "buy":买 "sell":卖 272 | offset string true "open":开 "close":平 273 | lever_rate int true 杠杆倍数[“开仓”若有10倍多单,就不能再下20倍多单] 274 | order_price_type string true 订单报价类型 "limit":限价 "opponent":对手价 275 | * */ 276 | public function postOrder(array $data=[]){ 277 | $this->type='POST'; 278 | $this->path='/api/v1/contract_order'; 279 | 280 | $data['lever_rate']=$data['lever_rate'] ?? 10; 281 | $data['order_price_type']=$data['order_price_type'] ?? 'limit'; 282 | 283 | $this->data=$data; 284 | return $this->exec(); 285 | } 286 | 287 | /** 288 | * 289 | * */ 290 | public function postBatchOrder(array $data=[]){ 291 | $this->type='POST'; 292 | $this->path='/api/v1/contract_batchorder'; 293 | $this->data=$data; 294 | return $this->exec(); 295 | } 296 | 297 | /** 298 | * 撤销订单 299 | URL api/v1/contract_cancel 300 | 301 | 参数名称 是否必须 类型 描述 302 | order_id false string 订单ID( 多个订单ID中间以","分隔,一次最多允许撤消50个订单 ) 303 | client_order_id false string 客户订单ID(多个订单ID中间以","分隔,一次最多允许撤消50个订单) 304 | symbol true string "BTC","ETH"... 305 | * */ 306 | public function postCancel(array $data=[]){ 307 | $this->type='POST'; 308 | $this->path='/api/v1/contract_cancel'; 309 | $this->data=$data; 310 | return $this->exec(); 311 | } 312 | 313 | /** 314 | * symbol true string 品种代码,如"BTC","ETH"... 315 | * */ 316 | public function postCancelAll(array $data=[]){ 317 | $this->type='POST'; 318 | $this->path='/api/v1/contract_cancelall'; 319 | $this->data=$data; 320 | return $this->exec(); 321 | } 322 | 323 | /** 324 | * 获取合约订单信息 325 | * order_id false string 订单ID( 多个订单ID中间以","分隔,一次最多允许查询20个订单 ) 326 | client_order_id false string 客户订单ID(多个订单ID中间以","分隔,一次最多允许查询20个订单) 327 | symbol true string "BTC","ETH"... 328 | 329 | order_id 与 client_order_id 必须至少存在一个 330 | * */ 331 | public function postOrderInfo(array $data=[]){ 332 | $this->type='POST'; 333 | $this->path='/api/v1/contract_order_info'; 334 | $this->data=$data; 335 | return $this->exec(); 336 | } 337 | 338 | /** 339 | *POST api/v1/contract_order_detail 340 | * */ 341 | public function postOrderDetail(array $data=[]){ 342 | $this->type='POST'; 343 | $this->path='/api/v1/contract_order_detail'; 344 | $this->data=$data; 345 | return $this->exec(); 346 | } 347 | 348 | /** 349 | * POST api/v1/contract_openorders 350 | * */ 351 | public function postOpenOrders(array $data=[]){ 352 | $this->type='POST'; 353 | $this->path='/api/v1/contract_openorders'; 354 | $this->data=$data; 355 | return $this->exec(); 356 | } 357 | 358 | /** 359 | *POST api/v1/contract_hisorders 360 | * */ 361 | public function postHisorders(array $data=[]){ 362 | $this->type='POST'; 363 | $this->path='/api/v1/contract_hisorders'; 364 | $this->data=$data; 365 | return $this->exec(); 366 | } 367 | 368 | /** 369 | *POST api/v1/contract_matchresults 370 | * */ 371 | public function postMatchresults(array $data=[]){ 372 | $this->type='POST'; 373 | $this->path='/api/v1/contract_matchresults'; 374 | $this->data=$data; 375 | return $this->exec(); 376 | } 377 | 378 | /** 379 | * POST api/v1/contract_trigger_order 380 | * */ 381 | public function postTriggerOrder(array $data=[]){ 382 | $this->type='POST'; 383 | $this->path='/api/v1/contract_trigger_order'; 384 | $this->data=$data; 385 | return $this->exec(); 386 | } 387 | 388 | /** 389 | *POST api/v1/contract_trigger_cancel 390 | * */ 391 | public function postTriggerCancel(array $data=[]){ 392 | $this->type='POST'; 393 | $this->path='/api/v1/contract_trigger_cancel'; 394 | $this->data=$data; 395 | return $this->exec(); 396 | } 397 | 398 | /** 399 | *POST api/v1/contract_trigger_cancelall 400 | * */ 401 | public function postTriggerCancelall(array $data=[]){ 402 | $this->type='POST'; 403 | $this->path='/api/v1/contract_trigger_cancelall'; 404 | $this->data=$data; 405 | return $this->exec(); 406 | } 407 | 408 | /** 409 | *POST api/v1/contract_trigger_openorders 410 | * */ 411 | public function postTriggerOpenorders(array $data=[]){ 412 | $this->type='POST'; 413 | $this->path='/api/v1/contract_trigger_openorders'; 414 | $this->data=$data; 415 | return $this->exec(); 416 | } 417 | 418 | /** 419 | *POST api/v1/contract_trigger_hisorders 420 | * */ 421 | public function postTriggerHisorders(array $data=[]){ 422 | $this->type='POST'; 423 | $this->path='/api/v1/contract_trigger_hisorders'; 424 | $this->data=$data; 425 | return $this->exec(); 426 | } 427 | 428 | /** 429 | * POST api/v1/lightning_close_position 430 | * */ 431 | public function postLightningClosePosition(array $data=[]){ 432 | $this->type='POST'; 433 | $this->path='/api/v1/lightning_close_position'; 434 | 435 | $this->data=$data; 436 | return $this->exec(); 437 | } 438 | 439 | /** 440 | * 441 | * */ 442 | /* public function post(array $data=[]){ 443 | $this->type='POST'; 444 | $this->path=''; 445 | $this->data=$data; 446 | return $this->exec(); 447 | } */ 448 | } 449 | -------------------------------------------------------------------------------- /src/Api/Futures/Market.php: -------------------------------------------------------------------------------- 1 | 4 | * */ 5 | 6 | namespace Lin\Huobi\Api\Futures; 7 | 8 | 9 | 10 | use Lin\Huobi\Request; 11 | 12 | class Market extends Request 13 | { 14 | /** 15 | * 获取行情深度数据 16 | * symbol string true 如"BTC_CW"表示BTC当周合约,"BTC_NW"表示BTC次周合约,"BTC_CQ"表示BTC季度合约 17 | type string true (150档数据) step0, step1, step2, step3, step4, step5(合并深度1-5); 18 | step0时,不合并深度, (20档数据) step6, step7, step8, step9, step10, step11(合并深度7-11); 19 | step6时,不合并深度 20 | * */ 21 | public function getDepth(array $data=[]){ 22 | $this->type='GET'; 23 | $this->path='/market/depth'; 24 | 25 | $data['type'] = $data['type'] ?? ''; 26 | 27 | $this->data=$data; 28 | return $this->exec(); 29 | } 30 | 31 | /** 32 | * GET /market/history/kline 33 | * */ 34 | public function getHistoryKline(array $data=[]){ 35 | $this->type='GET'; 36 | $this->path='/market/history/kline'; 37 | $this->data=$data; 38 | return $this->exec(); 39 | } 40 | 41 | /** 42 | * GET /market/detail/merged 43 | * */ 44 | public function getDetailMerged(array $data=[]){ 45 | $this->type='GET'; 46 | $this->path='/market/detail/merged'; 47 | $this->data=$data; 48 | return $this->exec(); 49 | } 50 | 51 | /** 52 | * 获取市场最近成交记录 53 | * symbol true string 合约名称 如"BTC_CW"表示BTC当周合约,"BTC_NW"表示BTC次周合约,"BTC_CQ"表示BTC季度合约 54 | * */ 55 | public function getTrade(array $data=[]){ 56 | $this->type='GET'; 57 | $this->path='/market/trade'; 58 | $this->data=$data; 59 | return $this->exec(); 60 | } 61 | 62 | /** 63 | * 批量获取最近的交易记录 64 | * symbol true string 合约名称 如"BTC_CW"表示BTC当周合约,"BTC_NW"表示BTC次周合约,"BTC_CQ"表示BTC季度合约 65 | size false number 获取交易记录的数量 1 [1, 2000] 66 | * */ 67 | public function getHistoryTrade(array $data=[]){ 68 | $this->type='GET'; 69 | $this->path='/market/history/trade'; 70 | 71 | $data['size'] = $data['size'] ?? 200; 72 | 73 | $this->data=$data; 74 | return $this->exec(); 75 | } 76 | } -------------------------------------------------------------------------------- /src/Api/Linear/Account.php: -------------------------------------------------------------------------------- 1 | 4 | * */ 5 | 6 | namespace Lin\Huobi\Api\Linear; 7 | 8 | 9 | 10 | use Lin\Huobi\Request; 11 | 12 | class Account extends Request 13 | { 14 | /** 15 | *POST linear-swap-api/v1/swap_balance_valuation 16 | * */ 17 | public function postAccountValuation(array $data=[]){ 18 | $this->type='POST'; 19 | $this->path='/linear-swap-api/v1/swap_balance_valuation'; 20 | 21 | $this->data=$data; 22 | return $this->exec(); 23 | } 24 | 25 | /** 26 | *POST linear-swap-api/v1/swap_account_info 27 | * */ 28 | public function postAccountInfo(array $data=[]){ 29 | $this->type='POST'; 30 | $this->path='/linear-swap-api/v1/swap_account_info'; 31 | 32 | $this->data=$data; 33 | return $this->exec(); 34 | } 35 | 36 | /** 37 | *POST linear-swap-api/v1/swap_position_info 38 | * */ 39 | public function postPositionInfo(array $data=[]){ 40 | $this->type='POST'; 41 | $this->path='/linear-swap-api/v1/swap_position_info'; 42 | 43 | $this->data=$data; 44 | return $this->exec(); 45 | } 46 | 47 | /** 48 | *post linear-swap-api/v1/swap_account_position_info 49 | * */ 50 | public function postAccountPositionInfo(array $data=[]){ 51 | $this->type='POST'; 52 | $this->path='/linear-swap-api/v1/swap_account_position_info'; 53 | 54 | $this->data=$data; 55 | return $this->exec(); 56 | } 57 | 58 | /** 59 | *POST linear-swap-api/v1/swap_sub_account_list 60 | * */ 61 | public function postSubAccountList(array $data=[]){ 62 | $this->type='POST'; 63 | $this->path='/linear-swap-api/v1/swap_sub_account_list'; 64 | 65 | $this->data=$data; 66 | return $this->exec(); 67 | } 68 | 69 | /** 70 | *POST linear-swap-api/v1/swap_sub_account_info 71 | * */ 72 | public function postSubAccountInfo(array $data=[]){ 73 | $this->type='POST'; 74 | $this->path='/linear-swap-api/v1/swap_sub_account_info'; 75 | 76 | $this->data=$data; 77 | return $this->exec(); 78 | } 79 | 80 | /** 81 | *POST linear-swap-api/v1/swap_sub_position_info 82 | * */ 83 | public function postSubPositionInfo(array $data=[]){ 84 | $this->type='POST'; 85 | $this->path='/linear-swap-api/v1/swap_sub_position_info'; 86 | 87 | $this->data=$data; 88 | return $this->exec(); 89 | } 90 | 91 | /** 92 | *POST linear-swap-api/v1/swap_financial_record 93 | * */ 94 | public function postFinancialRecord(array $data=[]){ 95 | $this->type='POST'; 96 | $this->path='/linear-swap-api/v1/swap_financial_record'; 97 | 98 | $this->data=$data; 99 | return $this->exec(); 100 | } 101 | 102 | /** 103 | *POST linear-swap-api/v1/swap_available_level_rate 104 | * */ 105 | public function postAvailableLevelRate(array $data=[]){ 106 | $this->type='POST'; 107 | $this->path='/linear-swap-api/v1/swap_available_level_rate'; 108 | 109 | $this->data=$data; 110 | return $this->exec(); 111 | } 112 | 113 | /** 114 | *POST linear-swap-api/v1/swap_order_limit 115 | * */ 116 | public function postOrderLimit(array $data=[]){ 117 | $this->type='POST'; 118 | $this->path='/linear-swap-api/v1/swap_order_limit'; 119 | 120 | $this->data=$data; 121 | return $this->exec(); 122 | } 123 | 124 | /** 125 | *POST linear-swap-api/v1/swap_fee 126 | * */ 127 | public function postFee(array $data=[]){ 128 | $this->type='POST'; 129 | $this->path='/linear-swap-api/v1/swap_fee'; 130 | 131 | $this->data=$data; 132 | return $this->exec(); 133 | } 134 | 135 | /** 136 | *POST linear-swap-api/v1/swap_transfer_limit 137 | * */ 138 | public function postTransferLimit(array $data=[]){ 139 | $this->type='POST'; 140 | $this->path='/linear-swap-api/v1/swap_transfer_limit'; 141 | 142 | $this->data=$data; 143 | return $this->exec(); 144 | } 145 | 146 | /** 147 | *post linear-swap-api/v1/swap_position_limit 148 | * */ 149 | public function postPositionLimit(array $data=[]){ 150 | $this->type='POST'; 151 | $this->path='/linear-swap-api/v1/swap_position_limit'; 152 | 153 | $this->data=$data; 154 | return $this->exec(); 155 | } 156 | 157 | /** 158 | *post linear-swap-api/v1/swap_master_sub_transfer 159 | * */ 160 | public function postMasterSubTransfer(array $data=[]){ 161 | $this->type='POST'; 162 | $this->path='/linear-swap-api/v1/swap_master_sub_transfer'; 163 | 164 | $this->data=$data; 165 | return $this->exec(); 166 | } 167 | 168 | /** 169 | *post linear-swap-api/v1/swap_master_sub_transfer_record 170 | * */ 171 | public function postMasterSubTransferRecord(array $data=[]){ 172 | $this->type='POST'; 173 | $this->path='/linear-swap-api/v1/swap_master_sub_transfer_record'; 174 | 175 | $this->data=$data; 176 | return $this->exec(); 177 | } 178 | 179 | /** 180 | *post linear-swap-api/v1/swap_transfer_inner 181 | * */ 182 | public function postTransferInner(array $data=[]){ 183 | $this->type='POST'; 184 | $this->path='/linear-swap-api/v1/swap_transfer_inner'; 185 | 186 | $this->data=$data; 187 | return $this->exec(); 188 | } 189 | 190 | /** 191 | *get linear-swap-api/v1/swap_api_trading_status 192 | * */ 193 | public function getApiTradingStatus(array $data=[]){ 194 | $this->type='GET'; 195 | $this->path='/linear-swap-api/v1/swap_api_trading_status'; 196 | 197 | $this->data=$data; 198 | return $this->exec(); 199 | } 200 | 201 | } 202 | -------------------------------------------------------------------------------- /src/Api/Linear/Market.php: -------------------------------------------------------------------------------- 1 | 4 | * */ 5 | 6 | namespace Lin\Huobi\Api\Linear; 7 | 8 | 9 | 10 | use Lin\Huobi\Request; 11 | 12 | class Market extends Request 13 | { 14 | 15 | /** 16 | *GET linear-swap-api/v1/swap_contract_info 17 | * */ 18 | public function getContractInfo(array $data=[]){ 19 | $this->type='GET'; 20 | $this->path='/linear-swap-api/v1/swap_contract_info'; 21 | 22 | $this->data=$data; 23 | return $this->exec(); 24 | } 25 | 26 | /** 27 | *GET linear-swap-api/v1/swap_index 28 | * */ 29 | public function getIndex(array $data=[]){ 30 | $this->type='GET'; 31 | $this->path='/linear-swap-api/v1/swap_index'; 32 | 33 | $this->data=$data; 34 | return $this->exec(); 35 | } 36 | 37 | /** 38 | *GET linear-swap-api/v1/swap_price_limit 39 | * */ 40 | public function getPriceLimit(array $data=[]){ 41 | $this->type='GET'; 42 | $this->path='/linear-swap-api/v1/swap_price_limit'; 43 | 44 | $this->data=$data; 45 | return $this->exec(); 46 | } 47 | 48 | /** 49 | *GET linear-swap-api/v1/swap_open_interest 50 | * */ 51 | public function getOpenInterest(array $data=[]){ 52 | $this->type='GET'; 53 | $this->path='/linear-swap-api/v1/swap_open_interest'; 54 | 55 | $this->data=$data; 56 | return $this->exec(); 57 | } 58 | 59 | /** 60 | *GET linear-swap-ex/market/depth 61 | * */ 62 | public function getDepth(array $data=[]){ 63 | $this->type='GET'; 64 | $this->path='/linear-swap-ex/market/depth'; 65 | 66 | $this->data=$data; 67 | return $this->exec(); 68 | } 69 | 70 | /** 71 | *GET linear-swap-ex/market/history/kline 72 | * */ 73 | public function getHistoryKline(array $data=[]){ 74 | $this->type='GET'; 75 | $this->path='/linear-swap-ex/market/history/kline'; 76 | 77 | $this->data=$data; 78 | return $this->exec(); 79 | } 80 | 81 | /** 82 | *GET linear-swap-ex/market/detail/merged 83 | * */ 84 | public function getDetailMerged(array $data=[]){ 85 | $this->type='GET'; 86 | $this->path='/linear-swap-ex/market/detail/merged'; 87 | 88 | $this->data=$data; 89 | return $this->exec(); 90 | } 91 | 92 | /** 93 | *GET linear-swap-ex/market/trade 94 | * */ 95 | public function getTrade(array $data=[]){ 96 | $this->type='GET'; 97 | $this->path='/linear-swap-ex/market/trade'; 98 | 99 | $this->data=$data; 100 | return $this->exec(); 101 | } 102 | 103 | /** 104 | *GET linear-swap-ex/market/history/trade 105 | * */ 106 | public function getHistoryTrade(array $data=[]){ 107 | $this->type='GET'; 108 | $this->path='/linear-swap-ex/market/history/trade'; 109 | 110 | $this->data=$data; 111 | return $this->exec(); 112 | } 113 | 114 | /** 115 | *GET linear-swap-api/v1/swap_risk_info 116 | * */ 117 | public function getRiskInfo(array $data=[]){ 118 | $this->type='GET'; 119 | $this->path='/linear-swap-api/v1/swap_risk_info'; 120 | 121 | $this->data=$data; 122 | return $this->exec(); 123 | } 124 | 125 | /** 126 | *GET linear-swap-api/v1/swap_insurance_fund 127 | * */ 128 | public function getInsuranceFund(array $data=[]){ 129 | $this->type='GET'; 130 | $this->path='/linear-swap-api/v1/swap_insurance_fund'; 131 | 132 | $this->data=$data; 133 | return $this->exec(); 134 | } 135 | 136 | /** 137 | *GET linear-swap-api/v1/swap_adjustfactor 138 | * */ 139 | public function getAdjustfactor(array $data=[]){ 140 | $this->type='GET'; 141 | $this->path='/linear-swap-api/v1/swap_adjustfactor'; 142 | 143 | $this->data=$data; 144 | return $this->exec(); 145 | } 146 | 147 | /** 148 | *GET linear-swap-api/v1/swap_his_open_interest 149 | * */ 150 | public function getHisOpenInterest(array $data=[]){ 151 | $this->type='GET'; 152 | $this->path='/linear-swap-api/v1/swap_his_open_interest'; 153 | 154 | $this->data=$data; 155 | return $this->exec(); 156 | } 157 | 158 | /** 159 | *GET linear-swap-api/v1/swap_elite_account_ratio 160 | * */ 161 | public function getEliteAccountRatio(array $data=[]){ 162 | $this->type='GET'; 163 | $this->path='/linear-swap-api/v1/swap_elite_account_ratio'; 164 | 165 | $this->data=$data; 166 | return $this->exec(); 167 | } 168 | 169 | /** 170 | *GET linear-swap-api/v1/swap_elite_position_ratio 171 | * */ 172 | public function getElitePositionRatio(array $data=[]){ 173 | $this->type='GET'; 174 | $this->path='/linear-swap-api/v1/swap_elite_position_ratio'; 175 | 176 | $this->data=$data; 177 | return $this->exec(); 178 | } 179 | 180 | /** 181 | *GET linear-swap-api/v1/swap_api_state 182 | * */ 183 | public function getApiState(array $data=[]){ 184 | $this->type='GET'; 185 | $this->path='/linear-swap-api/v1/swap_api_state'; 186 | 187 | $this->data=$data; 188 | return $this->exec(); 189 | } 190 | 191 | /** 192 | *GET linear-swap-api/v1/swap_funding_rate 193 | * */ 194 | public function getFundingRate(array $data=[]){ 195 | $this->type='GET'; 196 | $this->path='/linear-swap-api/v1/swap_funding_rate'; 197 | 198 | $this->data=$data; 199 | return $this->exec(); 200 | } 201 | 202 | /** 203 | *GET linear-swap-api/v1/swap_batch_funding_rate 204 | * */ 205 | public function getBatchFundingRate(array $data=[]){ 206 | $this->type='GET'; 207 | $this->path='/linear-swap-api/v1/swap_batch_funding_rate'; 208 | $this->data=$data; 209 | return $this->exec(); 210 | } 211 | 212 | /** 213 | *GET linear-swap-api/v1/swap_historical_funding_rate 214 | * */ 215 | public function getHistoricalFundingRate(array $data=[]){ 216 | $this->type='GET'; 217 | $this->path='/linear-swap-api/v1/swap_historical_funding_rate'; 218 | $this->data=$data; 219 | return $this->exec(); 220 | } 221 | 222 | /** 223 | *GET linear-swap-api/v1/swap_liquidation_orders 224 | * */ 225 | public function getLiquidationOrders(array $data=[]){ 226 | $this->type='GET'; 227 | $this->path='/linear-swap-api/v1/swap_liquidation_orders'; 228 | 229 | $this->data=$data; 230 | return $this->exec(); 231 | } 232 | 233 | /** 234 | *GET /index/market/history/linear_swap_premium_index_kline 235 | * */ 236 | public function getHistoryLinearSwapPremiumIndexKline(array $data=[]){ 237 | $this->type='GET'; 238 | $this->path='/index/market/history/linear_swap_premium_index_kline'; 239 | 240 | $this->data=$data; 241 | return $this->exec(); 242 | } 243 | 244 | /** 245 | *GET /index/market/history/linear_swap_estimated_rate_kline 246 | * */ 247 | public function getHistoryLinearSwapEstimatedRateKline(array $data=[]){ 248 | $this->type='GET'; 249 | $this->path='/index/market/history/linear_swap_estimated_rate_kline'; 250 | 251 | $this->data=$data; 252 | return $this->exec(); 253 | } 254 | 255 | /** 256 | *GET index/market/history/linear_swap_basis 257 | * */ 258 | public function getHistoryLinearSwapBasis(array $data=[]){ 259 | $this->type='GET'; 260 | $this->path='/index/market/history/linear_swap_basis'; 261 | 262 | $this->data=$data; 263 | return $this->exec(); 264 | } 265 | } 266 | -------------------------------------------------------------------------------- /src/Api/Linear/Trade.php: -------------------------------------------------------------------------------- 1 | 4 | * */ 5 | 6 | namespace Lin\Huobi\Api\Linear; 7 | 8 | use Lin\Huobi\Request; 9 | 10 | class Trade extends Request 11 | { 12 | /** 13 | *POST linear-swap-api/v1/swap_order 14 | * */ 15 | public function postOrder(array $data=[]){ 16 | $this->type='POST'; 17 | $this->path='/linear-swap-api/v1/swap_order'; 18 | 19 | $this->data=$data; 20 | return $this->exec(); 21 | } 22 | 23 | /** 24 | *POST linear-swap-api/v1/swap_batchorder 25 | * */ 26 | public function postBatchOrder(array $data=[]){ 27 | $this->type='POST'; 28 | $this->path='/linear-swap-api/v1/swap_batchorder'; 29 | 30 | $this->data=$data; 31 | return $this->exec(); 32 | } 33 | 34 | /** 35 | *POST linear-swap-api/v1/swap_cancel 36 | * */ 37 | public function postCancel(array $data=[]){ 38 | $this->type='POST'; 39 | $this->path='/linear-swap-api/v1/swap_cancel'; 40 | 41 | $this->data=$data; 42 | return $this->exec(); 43 | } 44 | 45 | /** 46 | *POST linear-swap-api/v1/swap_cancelall 47 | * */ 48 | public function postCancelAll(array $data=[]){ 49 | $this->type='POST'; 50 | $this->path='/linear-swap-api/v1/swap_cancelall'; 51 | 52 | $this->data=$data; 53 | return $this->exec(); 54 | } 55 | 56 | /** 57 | *POST linear-swap-api/v1/swap_switch_lever_rate 58 | * */ 59 | public function postSwitchLeverRate(array $data=[]){ 60 | $this->type='POST'; 61 | $this->path='/linear-swap-api/v1/swap_switch_lever_rate'; 62 | 63 | $this->data=$data; 64 | return $this->exec(); 65 | } 66 | 67 | /** 68 | *POST linear-swap-api/v1/swap_order_info 69 | * */ 70 | public function postOrderInfo(array $data=[]){ 71 | $this->type='POST'; 72 | $this->path='/linear-swap-api/v1/swap_order_info'; 73 | 74 | $this->data=$data; 75 | return $this->exec(); 76 | } 77 | 78 | /** 79 | *POST linear-swap-api/v1/swap_order_detail 80 | * */ 81 | public function postOrderDetail(array $data=[]){ 82 | $this->type='POST'; 83 | $this->path='/linear-swap-api/v1/swap_order_detail'; 84 | 85 | $this->data=$data; 86 | return $this->exec(); 87 | } 88 | 89 | /** 90 | *POST linear-swap-api/v1/swap_openorders 91 | * */ 92 | public function postOpenOrders(array $data=[]){ 93 | $this->type='POST'; 94 | $this->path='/linear-swap-api/v1/swap_openorders'; 95 | 96 | $this->data=$data; 97 | return $this->exec(); 98 | } 99 | 100 | /** 101 | *POST linear-swap-api/v1/swap_hisorders 102 | * */ 103 | public function postHisorders(array $data=[]){ 104 | $this->type='POST'; 105 | $this->path='/linear-swap-api/v1/swap_hisorders'; 106 | 107 | $this->data=$data; 108 | return $this->exec(); 109 | } 110 | 111 | /** 112 | *POST linear-swap-api/v1/swap_matchresults 113 | * */ 114 | public function postMatchResults(array $data=[]){ 115 | $this->type='POST'; 116 | $this->path='/linear-swap-api/v1/swap_matchresults'; 117 | 118 | $this->data=$data; 119 | return $this->exec(); 120 | } 121 | 122 | /** 123 | *POST linear-swap-api/v1/swap_lightning_close_position 124 | * */ 125 | public function postLightningClosePosition(array $data=[]){ 126 | $this->type='POST'; 127 | $this->path='/linear-swap-api/v1/swap_lightning_close_position'; 128 | 129 | $this->data=$data; 130 | return $this->exec(); 131 | } 132 | 133 | /** 134 | *POST linear-swap-api/v1/swap_trigger_order 135 | * */ 136 | public function postTriggerOrder(array $data=[]){ 137 | $this->type='POST'; 138 | $this->path='/linear-swap-api/v1/swap_trigger_order'; 139 | 140 | $this->data=$data; 141 | return $this->exec(); 142 | } 143 | 144 | /** 145 | *POST linear-swap-api/v1/swap_trigger_cancel 146 | * */ 147 | public function postTriggerCancel(array $data=[]){ 148 | $this->type='POST'; 149 | $this->path='/linear-swap-api/v1/swap_trigger_cancel'; 150 | 151 | $this->data=$data; 152 | return $this->exec(); 153 | } 154 | 155 | /** 156 | *POST linear-swap-api/v1/swap_trigger_cancelall 157 | * */ 158 | public function postTriggerCancelall(array $data=[]){ 159 | $this->type='POST'; 160 | $this->path='/linear-swap-api/v1/swap_trigger_cancelall'; 161 | 162 | $this->data=$data; 163 | return $this->exec(); 164 | } 165 | 166 | /** 167 | *POST linear-swap-api/v1/swap_trigger_openorders 168 | * */ 169 | public function postTriggerOpenorders(array $data=[]){ 170 | $this->type='POST'; 171 | $this->path='/linear-swap-api/v1/swap_trigger_openorders'; 172 | 173 | $this->data=$data; 174 | return $this->exec(); 175 | } 176 | 177 | /** 178 | *POST linear-swap-api/v1/swap_trigger_hisorders 179 | * */ 180 | public function postTriggerHisorders(array $data=[]){ 181 | $this->type='POST'; 182 | $this->path='/linear-swap-api/v1/swap_trigger_hisorders'; 183 | 184 | $this->data=$data; 185 | return $this->exec(); 186 | } 187 | } 188 | -------------------------------------------------------------------------------- /src/Api/Spot/Account.php: -------------------------------------------------------------------------------- 1 | 4 | * */ 5 | 6 | namespace Lin\Huobi\Api\Spot; 7 | 8 | 9 | 10 | use Lin\Huobi\Request; 11 | 12 | class Account extends Request 13 | { 14 | /** 15 | * 16 | * */ 17 | public function get(array $data=[]){ 18 | $this->type='GET'; 19 | $this->path='/v1/account/accounts'; 20 | $this->data=$data; 21 | return $this->exec(); 22 | } 23 | 24 | /** 25 | * /v1/account/accounts/{account-id}/balance 26 | * */ 27 | public function getBalance(array $data=[]){ 28 | $this->type='GET'; 29 | $this->path='/v1/account/accounts/'.$data['account-id'].'/balance'; 30 | $this->data=$data; 31 | return $this->exec(); 32 | } 33 | 34 | 35 | /** 36 | *POST /v1/account/transfer 37 | * */ 38 | public function postTransfer(array $data=[]){ 39 | $this->type='POST'; 40 | $this->path='/v1/account/transfer'; 41 | $this->data=$data; 42 | return $this->exec(); 43 | } 44 | 45 | /** 46 | *GET /v1/account/history 47 | * */ 48 | public function getHistory(array $data=[]){ 49 | $this->type='GET'; 50 | $this->path='/v1/account/history'; 51 | $this->data=$data; 52 | return $this->exec(); 53 | } 54 | 55 | /** 56 | *GET /v2/account/ledger 57 | * */ 58 | public function getLedger(array $data=[]){ 59 | $this->type='GET'; 60 | $this->path='/v2/account/ledger'; 61 | $this->data=$data; 62 | return $this->exec(); 63 | } 64 | 65 | /** 66 | *POST /v1/futures/transfer 67 | * */ 68 | public function postFuturesTransfer(array $data=[]){ 69 | $this->type='POST'; 70 | $this->path='/v1/futures/transfer'; 71 | $this->data=$data; 72 | return $this->exec(); 73 | } 74 | } -------------------------------------------------------------------------------- /src/Api/Spot/AlgoOrder.php: -------------------------------------------------------------------------------- 1 | 4 | * */ 5 | 6 | namespace Lin\Huobi\Api\Spot; 7 | 8 | 9 | 10 | use Lin\Huobi\Request; 11 | 12 | class AlgoOrder extends Request 13 | { 14 | 15 | /** 16 | * POST /v2/algo-orders 17 | * */ 18 | public function post(array $data=[]){ 19 | $this->type='POST'; 20 | $this->path='/v2/algo-orders'; 21 | $this->data=$data; 22 | return $this->exec(); 23 | } 24 | 25 | /** 26 | * POST /v2/algo-orders/cancellation 27 | * */ 28 | public function postCancellation(array $data=[]){ 29 | $this->type='POST'; 30 | $this->path='/v2/algo-orders/cancellation'; 31 | $this->data=$data; 32 | return $this->exec(); 33 | } 34 | 35 | /** 36 | * GET /v2/algo-orders/opening 37 | * */ 38 | public function getOpening(array $data=[]){ 39 | $this->type='GET'; 40 | $this->path='/v2/algo-orders/opening'; 41 | $this->data=$data; 42 | return $this->exec(); 43 | } 44 | 45 | /** 46 | * GET /v2/algo-orders/history 47 | * */ 48 | public function getHistory(array $data=[]){ 49 | $this->type='GET'; 50 | $this->path='/v2/algo-orders/history'; 51 | $this->data=$data; 52 | return $this->exec(); 53 | } 54 | } -------------------------------------------------------------------------------- /src/Api/Spot/C2c.php: -------------------------------------------------------------------------------- 1 | 4 | * */ 5 | 6 | namespace Lin\Huobi\Api\Spot; 7 | 8 | 9 | 10 | use Lin\Huobi\Request; 11 | 12 | class C2c extends Request 13 | { 14 | /** 15 | * POST /v2/c2c/offer 16 | * */ 17 | public function postOffer(array $data=[]){ 18 | $this->type='POST'; 19 | $this->path=' /v2/c2c/offer'; 20 | $this->data=$data; 21 | return $this->exec(); 22 | } 23 | 24 | /** 25 | *POST /v2/c2c/cancellation 26 | * */ 27 | public function postCancellation(array $data=[]){ 28 | $this->type='POST'; 29 | $this->path='/v2/c2c/cancellation'; 30 | $this->data=$data; 31 | return $this->exec(); 32 | } 33 | 34 | /** 35 | *POST /v2/c2c/cancel-all 36 | * */ 37 | public function postCancelAll(array $data=[]){ 38 | $this->type='POST'; 39 | $this->path='/v2/c2c/cancel-all'; 40 | $this->data=$data; 41 | return $this->exec(); 42 | } 43 | 44 | /** 45 | *GET /v2/c2c/offers 46 | * */ 47 | public function getOffers(array $data=[]){ 48 | $this->type='GET'; 49 | $this->path='/v2/c2c/offers'; 50 | $this->data=$data; 51 | return $this->exec(); 52 | } 53 | 54 | /** 55 | *GET /v2/c2c/offer 56 | * */ 57 | public function getoffer(array $data=[]){ 58 | $this->type='GET'; 59 | $this->path='/v2/c2c/offer'; 60 | $this->data=$data; 61 | return $this->exec(); 62 | } 63 | 64 | /** 65 | *GET /v2/c2c/transactions 66 | * */ 67 | public function getTransactions(array $data=[]){ 68 | $this->type='GET'; 69 | $this->path='/v2/c2c/transactions'; 70 | $this->data=$data; 71 | return $this->exec(); 72 | } 73 | 74 | /** 75 | *POST /v2/c2c/repayment 76 | * */ 77 | public function postRepayment(array $data=[]){ 78 | $this->type='POST'; 79 | $this->path='/v2/c2c/repayment'; 80 | $this->data=$data; 81 | return $this->exec(); 82 | } 83 | 84 | /** 85 | *GET /v2/c2c/repayment 86 | * */ 87 | public function getRepayment(array $data=[]){ 88 | $this->type='GET'; 89 | $this->path='/v2/c2c/repayment'; 90 | $this->data=$data; 91 | return $this->exec(); 92 | } 93 | 94 | /** 95 | *POST /v2/c2c/transfer 96 | * */ 97 | public function getTransfer(array $data=[]){ 98 | $this->type='GET'; 99 | $this->path='/v2/c2c/transfer'; 100 | $this->data=$data; 101 | return $this->exec(); 102 | } 103 | 104 | /** 105 | *GET /v2/c2c/account 106 | * */ 107 | public function getAccount(array $data=[]){ 108 | $this->type='GET'; 109 | $this->path='/v2/c2c/account'; 110 | $this->data=$data; 111 | return $this->exec(); 112 | } 113 | } -------------------------------------------------------------------------------- /src/Api/Spot/Common.php: -------------------------------------------------------------------------------- 1 | 4 | * */ 5 | 6 | namespace Lin\Huobi\Api\Spot; 7 | 8 | 9 | 10 | use Lin\Huobi\Request; 11 | 12 | class Common extends Request 13 | { 14 | /** 15 | * 16 | * */ 17 | public function getSymbols(array $data=[]){ 18 | $this->type='GET'; 19 | $this->path='/v1/common/symbols'; 20 | $this->data=$data; 21 | return $this->exec(); 22 | } 23 | 24 | /** 25 | * 26 | * */ 27 | public function getCurrencys(array $data=[]){ 28 | $this->type='GET'; 29 | $this->path='/v1/common/currencys'; 30 | $this->data=$data; 31 | return $this->exec(); 32 | } 33 | 34 | /** 35 | *GET /v1/common/timestamp 36 | * */ 37 | public function getTimestamp(array $data=[]){ 38 | $this->type='GET'; 39 | $this->path='/v1/common/timestamp'; 40 | $this->data=$data; 41 | return $this->exec(); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/Api/Spot/CrossMargin.php: -------------------------------------------------------------------------------- 1 | 4 | * */ 5 | 6 | namespace Lin\Huobi\Api\Spot; 7 | 8 | 9 | 10 | use Lin\Huobi\Request; 11 | 12 | class CrossMargin extends Request 13 | { 14 | /** 15 | *POST /v1/cross-margin/transfer-in 16 | * */ 17 | public function postTransferIn(array $data=[]){ 18 | $this->type='POST'; 19 | $this->path='/v1/cross-margin/transfer-in'; 20 | $this->data=$data; 21 | return $this->exec(); 22 | } 23 | 24 | /** 25 | *POST /v1/cross-margin/transfer-out 26 | * */ 27 | public function postTransferOut(array $data=[]){ 28 | $this->type='POST'; 29 | $this->path='/v1/cross-margin/transfer-out'; 30 | $this->data=$data; 31 | return $this->exec(); 32 | } 33 | 34 | /** 35 | *GET /v1/cross-margin/loan-info 36 | * */ 37 | public function get(array $data=[]){ 38 | $this->type='GET'; 39 | $this->path='/v1/cross-margin/loan-info'; 40 | $this->data=$data; 41 | return $this->exec(); 42 | } 43 | 44 | /** 45 | *POST /v1/cross-margin/orders 46 | * */ 47 | public function postOrders(array $data=[]){ 48 | $this->type='POST'; 49 | $this->path='/v1/cross-margin/orders'; 50 | $this->data=$data; 51 | return $this->exec(); 52 | } 53 | 54 | /** 55 | *POST /v1/cross-margin/orders/{order-id}/repay 56 | * */ 57 | public function postOrdersRepay(array $data=[]){ 58 | $this->type='POST'; 59 | $this->path='/v1/cross-margin/orders/'.$data['order_id'].'/repay'; 60 | $this->data=$data; 61 | return $this->exec(); 62 | } 63 | 64 | /** 65 | *GET /v1/cross-margin/loan-orders 66 | * */ 67 | public function getLoanOrders(array $data=[]){ 68 | $this->type='GET'; 69 | $this->path='/v1/cross-margin/loan-orders'; 70 | $this->data=$data; 71 | return $this->exec(); 72 | } 73 | 74 | /** 75 | *GET /v1/cross-margin/accounts/balance 76 | * */ 77 | public function getAccountsBalance(array $data=[]){ 78 | $this->type='GET'; 79 | $this->path='/v1/cross-margin/accounts/balance'; 80 | $this->data=$data; 81 | return $this->exec(); 82 | } 83 | } -------------------------------------------------------------------------------- /src/Api/Spot/Etf.php: -------------------------------------------------------------------------------- 1 | 4 | * */ 5 | 6 | namespace Lin\Huobi\Api\Spot; 7 | 8 | 9 | 10 | use Lin\Huobi\Request; 11 | 12 | class Etf extends Request 13 | { 14 | /** 15 | *GET /etf/swap/config 16 | * */ 17 | public function getSwapConfig(array $data=[]){ 18 | $this->type='GET'; 19 | $this->path='/etf/swap/config'; 20 | $this->data=$data; 21 | return $this->exec(); 22 | } 23 | 24 | /** 25 | *POST /etf/swap/in 26 | * */ 27 | public function postSwapIn(array $data=[]){ 28 | $this->type='POST'; 29 | $this->path='/etf/swap/in'; 30 | $this->data=$data; 31 | return $this->exec(); 32 | } 33 | 34 | /** 35 | *POST /etf/swap/out 36 | * */ 37 | public function postSwapOut(array $data=[]){ 38 | $this->type='POST'; 39 | $this->path='/etf/swap/out'; 40 | $this->data=$data; 41 | return $this->exec(); 42 | } 43 | 44 | /** 45 | *GET /etf/swap/list 46 | * */ 47 | public function getList(array $data=[]){ 48 | $this->type='GET'; 49 | $this->path='/etf/swap/list'; 50 | $this->data=$data; 51 | return $this->exec(); 52 | } 53 | } -------------------------------------------------------------------------------- /src/Api/Spot/Margin.php: -------------------------------------------------------------------------------- 1 | 4 | * */ 5 | 6 | namespace Lin\Huobi\Api\Spot; 7 | 8 | 9 | 10 | use Lin\Huobi\Request; 11 | 12 | class Margin extends Request 13 | { 14 | /** 15 | *POST /v1/dw/transfer-in/margin 16 | * */ 17 | public function postTransferIn(array $data=[]){ 18 | $this->type='POST'; 19 | $this->path='/v1/dw/transfer-in/margin'; 20 | $this->data=$data; 21 | return $this->exec(); 22 | } 23 | 24 | /** 25 | *POST /v1/dw/transfer-out/margin 26 | * */ 27 | public function postTransferOut(array $data=[]){ 28 | $this->type='POST'; 29 | $this->path='/v1/dw/transfer-out/margin'; 30 | $this->data=$data; 31 | return $this->exec(); 32 | } 33 | 34 | /** 35 | *GET /v1/margin/loan-info 36 | * */ 37 | public function getLoanInfo(array $data=[]){ 38 | $this->type='GET'; 39 | $this->path='/v1/margin/loan-info'; 40 | $this->data=$data; 41 | return $this->exec(); 42 | } 43 | 44 | /** 45 | *POST /v1/margin/orders 46 | * */ 47 | public function postOrders(array $data=[]){ 48 | $this->type='POST'; 49 | $this->path='/v1/margin/orders'; 50 | $this->data=$data; 51 | return $this->exec(); 52 | } 53 | 54 | /** 55 | *POST /v1/margin/orders/{order-id}/repay 56 | * */ 57 | public function postOrdersRepay(array $data=[]){ 58 | $this->type='POST'; 59 | $this->path='/v1/margin/orders/'.$data['order_id'].'/repay'; 60 | $this->data=$data; 61 | return $this->exec(); 62 | } 63 | 64 | /** 65 | *GET /v1/margin/loan-orders 66 | * */ 67 | public function getLoanOrders(array $data=[]){ 68 | $this->type='GET'; 69 | $this->path='/v1/margin/loan-orders'; 70 | $this->data=$data; 71 | return $this->exec(); 72 | } 73 | 74 | /** 75 | *GET /v1/margin/accounts/balance 76 | * */ 77 | public function getAccountsBalance(array $data=[]){ 78 | $this->type='GET'; 79 | $this->path='/v1/margin/accounts/balance'; 80 | $this->data=$data; 81 | return $this->exec(); 82 | } 83 | } -------------------------------------------------------------------------------- /src/Api/Spot/Market.php: -------------------------------------------------------------------------------- 1 | 4 | * */ 5 | 6 | namespace Lin\Huobi\Api\Spot; 7 | 8 | 9 | 10 | use Lin\Huobi\Request; 11 | 12 | class Market extends Request 13 | { 14 | /** 15 | *GET /market/history/kline 16 | * */ 17 | public function getHistoryKline(array $data=[]){ 18 | $this->type='GET'; 19 | $this->path='/market/history/kline'; 20 | $this->data=$data; 21 | return $this->exec(); 22 | } 23 | 24 | /** 25 | *GET /market/detail/merged 26 | * */ 27 | public function getDetailMerged(array $data=[]){ 28 | $this->type='GET'; 29 | $this->path='/market/detail/merged'; 30 | $this->data=$data; 31 | return $this->exec(); 32 | } 33 | 34 | /** 35 | *GET /market/tickers 36 | * */ 37 | public function getTickers(){ 38 | $this->type='GET'; 39 | $this->path='/market/tickers'; 40 | return $this->exec(); 41 | } 42 | 43 | /** 44 | * GET /market/depth 45 | * */ 46 | public function getDepth(array $data=[]){ 47 | $this->type='GET'; 48 | $this->path='/market/depth'; 49 | 50 | $data['type'] = $data['type'] ?? 'step0'; 51 | 52 | $this->data=$data; 53 | return $this->exec(); 54 | } 55 | 56 | /** 57 | *GET /market/trade 58 | * */ 59 | public function getTrade(array $data=[]){ 60 | $this->type='GET'; 61 | $this->path='/market/trade'; 62 | $this->data=$data; 63 | return $this->exec(); 64 | } 65 | 66 | /** 67 | *GET /market/history/trade 68 | * */ 69 | public function getHistoryTrade(array $data=[]){ 70 | $this->type='GET'; 71 | $this->path='/market/history/trade'; 72 | $this->data=$data; 73 | return $this->exec(); 74 | } 75 | 76 | /** 77 | * GET /market/detail 78 | * */ 79 | public function getDetail(array $data=[]){ 80 | $this->type='GET'; 81 | $this->path='/market/detail'; 82 | $this->data=$data; 83 | return $this->exec(); 84 | } 85 | } -------------------------------------------------------------------------------- /src/Api/Spot/Order.php: -------------------------------------------------------------------------------- 1 | 4 | * */ 5 | 6 | namespace Lin\Huobi\Api\Spot; 7 | 8 | 9 | 10 | use Lin\Huobi\Request; 11 | 12 | class Order extends Request 13 | { 14 | /** 15 | *POST /v1/order/orders/place 16 | * */ 17 | public function postPlace(array $data=[]){ 18 | $this->type='POST'; 19 | $this->path='/v1/order/orders/place'; 20 | $this->data=$data; 21 | return $this->exec(); 22 | } 23 | 24 | /** 25 | *POST /v1/order/batch-orders 26 | * */ 27 | public function postBatchOrders(array $data=[]){ 28 | $this->type='POST'; 29 | $this->path='/v1/order/batch-orders'; 30 | $this->data=$data; 31 | return $this->exec(); 32 | } 33 | 34 | /** 35 | * POST /v1/order/orders/{order-id}/submitcancel 36 | * */ 37 | public function postSubmitCancel(array $data=[]){ 38 | $this->type='POST'; 39 | $this->path='/v1/order/orders/'.$data['order-id'].'/submitcancel'; 40 | $this->data=$data; 41 | return $this->exec(); 42 | } 43 | 44 | /** 45 | * POST /v1/order/orders/submitCancelClientOrder 46 | * */ 47 | public function postSubmitCancelClientOrder(array $data=[]){ 48 | $this->type='POST'; 49 | $this->path='/v1/order/orders/submitCancelClientOrder'; 50 | $this->data=$data; 51 | return $this->exec(); 52 | } 53 | 54 | /** 55 | *GET /v1/order/openOrders 56 | * */ 57 | public function getOpenOrders(array $data=[]){ 58 | $this->type='GET'; 59 | $this->path='/v1/order/openOrders'; 60 | $this->data=$data; 61 | return $this->exec(); 62 | } 63 | 64 | /** 65 | *POST /v1/order/orders/batchCancelOpenOrders 66 | * */ 67 | public function postBatchCancelOpenOrders(array $data=[]){ 68 | $this->type='POST'; 69 | $this->path='/v1/order/orders/batchCancelOpenOrders'; 70 | $this->data=$data; 71 | return $this->exec(); 72 | } 73 | 74 | /** 75 | *POST /v1/order/orders/batchcancel 76 | * */ 77 | public function postBatchCancel(array $data=[]){ 78 | $this->type='GET'; 79 | $this->path='/v1/order/orders/batchcancel'; 80 | $this->data=$data; 81 | return $this->exec(); 82 | } 83 | 84 | /** 85 | *GET /v1/order/orders/{order-id} 86 | * */ 87 | public function get(array $data=[]){ 88 | $this->type='GET'; 89 | $this->path='/v1/order/orders/'.$data['order-id']; 90 | $this->data=$data; 91 | return $this->exec(); 92 | } 93 | 94 | /** 95 | * GET /v1/order/orders/getClientOrder 96 | * */ 97 | public function getClientOrder(array $data=[]){ 98 | $this->type='GET'; 99 | $this->path='/v1/order/orders/getClientOrder'; 100 | $this->data=$data; 101 | return $this->exec(); 102 | } 103 | 104 | /** 105 | * GET /v1/order/orders/{order-id}/matchresults 106 | * */ 107 | public function getMatchresults(array $data=[]){ 108 | $this->type='GET'; 109 | $this->path='/v1/order/orders/'.$data['order-id'].'/matchresults'; 110 | $this->data=$data; 111 | return $this->exec(); 112 | } 113 | 114 | /** 115 | * GET /v1/order/orders 116 | * */ 117 | public function getOrders(array $data=[]){ 118 | $this->type='GET'; 119 | $this->path='/v1/order/orders'; 120 | $this->data=$data; 121 | return $this->exec(); 122 | } 123 | 124 | /** 125 | * GET /v1/order/history 126 | * */ 127 | public function getHistory(array $data=[]){ 128 | $this->type='GET'; 129 | $this->path='/v1/order/history'; 130 | $this->data=$data; 131 | return $this->exec(); 132 | } 133 | 134 | /** 135 | * GET /v1/order/matchresults 136 | * */ 137 | public function getMatchresultsAll(array $data=[]){ 138 | $this->type='GET'; 139 | $this->path='/v1/order/matchresults'; 140 | $this->data=$data; 141 | return $this->exec(); 142 | } 143 | } 144 | -------------------------------------------------------------------------------- /src/Api/Spot/Reference.php: -------------------------------------------------------------------------------- 1 | type='GET'; 14 | $this->path='/v2/reference/currencies'; 15 | $this->data=$data; 16 | return $this->exec(); 17 | } 18 | 19 | /** 20 | * 21 | * */ 22 | public function getTransactFeeRate(array $data=[]){ 23 | $this->type='GET'; 24 | $this->path='/v2/reference/transact-fee-rate'; 25 | $this->data=$data; 26 | return $this->exec(); 27 | } 28 | } -------------------------------------------------------------------------------- /src/Api/Spot/Settings.php: -------------------------------------------------------------------------------- 1 | type='GET'; 14 | $this->path='/v1/settings/common/chains'; 15 | $this->data=$data; 16 | return $this->exec(); 17 | } 18 | 19 | /** 20 | * 21 | * */ 22 | public function getCurrencies(array $data=[]){ 23 | $this->type='GET'; 24 | $this->path='/v2/settings/common/currencies'; 25 | $this->data=$data; 26 | return $this->exec(); 27 | } 28 | 29 | /** 30 | * 31 | * */ 32 | public function getSymbols(array $data=[]){ 33 | $this->type='GET'; 34 | $this->path='/v2/settings/common/symbols'; 35 | $this->data=$data; 36 | return $this->exec(); 37 | } 38 | } -------------------------------------------------------------------------------- /src/Api/Spot/Subuser.php: -------------------------------------------------------------------------------- 1 | 4 | * */ 5 | 6 | namespace Lin\Huobi\Api\Spot; 7 | 8 | 9 | 10 | use Lin\Huobi\Request; 11 | 12 | class Subuser extends Request 13 | { 14 | /** 15 | *POST /v2/sub-user/deduct-mode 16 | * */ 17 | public function postDeductMode(array $data=[]){ 18 | $this->type='POST'; 19 | $this->path='/v2/sub-user/deduct-mode'; 20 | $this->data=$data; 21 | return $this->exec(); 22 | } 23 | 24 | /** 25 | * 26 | * */ 27 | public function post(array $data=[]){ 28 | $this->type='POST'; 29 | $this->path=''; 30 | $this->data=$data; 31 | return $this->exec(); 32 | } 33 | 34 | /** 35 | *POST /v2/sub-user/creation 36 | * */ 37 | public function postCreation(array $data=[]){ 38 | $this->type='POST'; 39 | $this->path='/v2/sub-user/creation'; 40 | $this->data=$data; 41 | return $this->exec(); 42 | } 43 | 44 | /** 45 | *GET /v2/sub-user/user-list 46 | * */ 47 | public function getUserList(array $data=[]){ 48 | $this->type='GET'; 49 | $this->path='/v2/sub-user/user-list'; 50 | $this->data=$data; 51 | return $this->exec(); 52 | } 53 | 54 | /** 55 | *POST /v2/sub-user/management 56 | * */ 57 | public function getManagement(array $data=[]){ 58 | $this->type='POST'; 59 | $this->path='/v2/sub-user/management'; 60 | $this->data=$data; 61 | return $this->exec(); 62 | } 63 | 64 | /** 65 | *GET /v2/sub-user/user-state 66 | * */ 67 | public function getUserState(array $data=[]){ 68 | $this->type='GET'; 69 | $this->path='/v2/sub-user/user-state'; 70 | $this->data=$data; 71 | return $this->exec(); 72 | } 73 | 74 | /** 75 | *POST /v2/sub-user/tradable-market 76 | * */ 77 | public function postTradableMarket(array $data=[]){ 78 | $this->type='POST'; 79 | $this->path='/v2/sub-user/tradable-market'; 80 | $this->data=$data; 81 | return $this->exec(); 82 | } 83 | 84 | /** 85 | *POST /v2/sub-user/transferability 86 | * */ 87 | public function postTransferability(array $data=[]){ 88 | $this->type='POST'; 89 | $this->path='/v2/sub-user/transferability'; 90 | $this->data=$data; 91 | return $this->exec(); 92 | } 93 | 94 | /** 95 | *GET /v2/sub-user/account-list 96 | * */ 97 | public function getAccountList(array $data=[]){ 98 | $this->type='GET'; 99 | $this->path='/v2/sub-user/account-list'; 100 | $this->data=$data; 101 | return $this->exec(); 102 | } 103 | 104 | /** 105 | *POST /v2/sub-user/api-key-generation 106 | * */ 107 | public function postApiKeyGeneration(array $data=[]){ 108 | $this->type='POST'; 109 | $this->path='/v2/sub-user/api-key-generation'; 110 | $this->data=$data; 111 | return $this->exec(); 112 | } 113 | 114 | /** 115 | *GET /v2/user/uid 116 | * */ 117 | public function getUid(array $data=[]){ 118 | $this->type='GET'; 119 | $this->path='/v2/user/uid'; 120 | $this->data=$data; 121 | return $this->exec(); 122 | } 123 | 124 | /** 125 | *GET /v2/user/api-key 126 | * */ 127 | public function getApiKey(array $data=[]){ 128 | $this->type='GET'; 129 | $this->path='/v2/user/api-key'; 130 | $this->data=$data; 131 | return $this->exec(); 132 | } 133 | 134 | /** 135 | *POST /v2/sub-user/api-key-modification 136 | * */ 137 | public function postApiKeyModification(array $data=[]){ 138 | $this->type='POST'; 139 | $this->path='/v2/sub-user/api-key-modification'; 140 | $this->data=$data; 141 | return $this->exec(); 142 | } 143 | 144 | /** 145 | *POST /v2/sub-user/api-key-deletion 146 | * */ 147 | public function getApiKeyDeletion(array $data=[]){ 148 | $this->type='POST'; 149 | $this->path='/v2/sub-user/api-key-deletion'; 150 | $this->data=$data; 151 | return $this->exec(); 152 | } 153 | 154 | /** 155 | *POST /v1/subuser/transfer 156 | * */ 157 | public function postTransfer(array $data=[]){ 158 | $this->type='POST'; 159 | $this->path='/v1/subuser/transfer'; 160 | $this->data=$data; 161 | return $this->exec(); 162 | } 163 | 164 | /** 165 | *GET /v2/sub-user/deposit-address 166 | * */ 167 | public function getDepositAddress(array $data=[]){ 168 | $this->type='GET'; 169 | $this->path='/v2/sub-user/deposit-address'; 170 | $this->data=$data; 171 | return $this->exec(); 172 | } 173 | 174 | /** 175 | *GET /v2/sub-user/query-deposit 176 | * */ 177 | public function getQueryDeposit(array $data=[]){ 178 | $this->type='GET'; 179 | $this->path='/v2/sub-user/query-deposit'; 180 | $this->data=$data; 181 | return $this->exec(); 182 | } 183 | 184 | /** 185 | *GET /v1/subuser/aggregate-balance 186 | * */ 187 | public function getAggregateBalance(array $data=[]){ 188 | $this->type='GET'; 189 | $this->path='/v1/subuser/aggregate-balance'; 190 | $this->data=$data; 191 | return $this->exec(); 192 | } 193 | 194 | /** 195 | *GET /v1/account/accounts/{sub-uid} 196 | * */ 197 | public function getAccounts(array $data=[]){ 198 | $this->type='GET'; 199 | $this->path='/v1/account/accounts/'.$data['sub_uid']; 200 | $this->data=$data; 201 | return $this->exec(); 202 | } 203 | } 204 | -------------------------------------------------------------------------------- /src/Api/Spot/Wallet.php: -------------------------------------------------------------------------------- 1 | 4 | * */ 5 | 6 | namespace Lin\Huobi\Api\Spot; 7 | 8 | 9 | 10 | use Lin\Huobi\Request; 11 | 12 | class Wallet extends Request 13 | { 14 | /** 15 | * GET /v2/account/deposit/address 16 | * */ 17 | public function getDepositAddress(array $data=[]){ 18 | $this->type='GET'; 19 | $this->path='/v2/account/deposit/address'; 20 | $this->data=$data; 21 | return $this->exec(); 22 | } 23 | 24 | /** 25 | *GET /v2/account/withdraw/quota 26 | * */ 27 | public function getWithdrawQuota(array $data=[]){ 28 | $this->type='GET'; 29 | $this->path='/v2/account/withdraw/quota'; 30 | $this->data=$data; 31 | return $this->exec(); 32 | } 33 | 34 | /** 35 | *GET /v2/account/withdraw/address 36 | * */ 37 | public function getWithdrawAddress(array $data=[]){ 38 | $this->type='GET'; 39 | $this->path='/v2/account/withdraw/address'; 40 | $this->data=$data; 41 | return $this->exec(); 42 | } 43 | 44 | /** 45 | *POST /v1/dw/withdraw/api/create 46 | * */ 47 | public function postWithdrawApiCreate(array $data=[]){ 48 | $this->type='POST'; 49 | $this->path='/v1/dw/withdraw/api/create'; 50 | $this->data=$data; 51 | return $this->exec(); 52 | } 53 | 54 | /** 55 | *POST /v1/dw/withdraw-virtual/{withdraw-id}/cancel 56 | * */ 57 | public function postWithdrawCancel(array $data=[]){ 58 | $this->type='POST'; 59 | $this->path='/v1/dw/withdraw-virtual/'.$data['withdraw_id'].'/cancel'; 60 | $this->data=$data; 61 | return $this->exec(); 62 | } 63 | 64 | /** 65 | *GET /v1/query/deposit-withdraw 66 | * */ 67 | public function getDepositWithdraw(array $data=[]){ 68 | $this->type='GET'; 69 | $this->path='/v1/query/deposit-withdraw'; 70 | $this->data=$data; 71 | return $this->exec(); 72 | } 73 | } -------------------------------------------------------------------------------- /src/Api/Swap/Account.php: -------------------------------------------------------------------------------- 1 | 4 | * */ 5 | 6 | namespace Lin\Huobi\Api\Swap; 7 | 8 | 9 | 10 | use Lin\Huobi\Request; 11 | 12 | class Account extends Request 13 | { 14 | /** 15 | *POST swap-api/v1/swap_account_info 16 | * */ 17 | public function postAccountInfo(array $data=[]){ 18 | $this->type='POST'; 19 | $this->path='/swap-api/v1/swap_account_info'; 20 | 21 | $this->data=$data; 22 | return $this->exec(); 23 | } 24 | 25 | /** 26 | *POST swap-api/v1/swap_position_info 27 | * */ 28 | public function postPositionInfo(array $data=[]){ 29 | $this->type='POST'; 30 | $this->path='/swap-api/v1/swap_position_info'; 31 | 32 | $this->data=$data; 33 | return $this->exec(); 34 | } 35 | 36 | /** 37 | *post swap-api/v1/swap_account_position_info 38 | * */ 39 | public function postAccountPositionInfo(array $data=[]){ 40 | $this->type='POST'; 41 | $this->path='/swap-api/v1/swap_account_position_info'; 42 | 43 | $this->data=$data; 44 | return $this->exec(); 45 | } 46 | 47 | /** 48 | *POST swap-api/v1/swap_sub_account_list 49 | * */ 50 | public function postSubAccountList(array $data=[]){ 51 | $this->type='POST'; 52 | $this->path='/swap-api/v1/swap_sub_account_list'; 53 | 54 | $this->data=$data; 55 | return $this->exec(); 56 | } 57 | 58 | /** 59 | *POST swap-api/v1/swap_sub_account_info 60 | * */ 61 | public function postSubAccountInfo(array $data=[]){ 62 | $this->type='POST'; 63 | $this->path='/swap-api/v1/swap_sub_account_info'; 64 | 65 | $this->data=$data; 66 | return $this->exec(); 67 | } 68 | 69 | /** 70 | *POST swap-api/v1/swap_sub_position_info 71 | * */ 72 | public function postSubPositionInfo(array $data=[]){ 73 | $this->type='POST'; 74 | $this->path='/swap-api/v1/swap_sub_position_info'; 75 | 76 | $this->data=$data; 77 | return $this->exec(); 78 | } 79 | 80 | /** 81 | *POST swap-api/v1/swap_financial_record 82 | * */ 83 | public function postFinancialRecord(array $data=[]){ 84 | $this->type='POST'; 85 | $this->path='/swap-api/v1/swap_financial_record'; 86 | 87 | $this->data=$data; 88 | return $this->exec(); 89 | } 90 | 91 | /** 92 | *POST swap-api/v1/swap_user_settlement_records 93 | * */ 94 | public function postUserSettlementRecords(array $data=[]){ 95 | $this->type='POST'; 96 | $this->path='/swap-api/v1/swap_user_settlement_records'; 97 | 98 | $this->data=$data; 99 | return $this->exec(); 100 | } 101 | 102 | /** 103 | *POST swap-api/v1/swap_available_level_rate 104 | * */ 105 | public function postAvailableLevelRate(array $data=[]){ 106 | $this->type='POST'; 107 | $this->path='/swap-api/v1/swap_available_level_rate'; 108 | 109 | $this->data=$data; 110 | return $this->exec(); 111 | } 112 | 113 | /** 114 | *POST swap-api/v1/swap_order_limit 115 | * */ 116 | public function postOrderLimit(array $data=[]){ 117 | $this->type='POST'; 118 | $this->path='/swap-api/v1/swap_order_limit'; 119 | 120 | $this->data=$data; 121 | return $this->exec(); 122 | } 123 | 124 | /** 125 | *POST swap-api/v1/swap_fee 126 | * */ 127 | public function postFee(array $data=[]){ 128 | $this->type='POST'; 129 | $this->path='/swap-api/v1/swap_fee'; 130 | 131 | $this->data=$data; 132 | return $this->exec(); 133 | } 134 | 135 | 136 | /** 137 | *POST swap-api/v1/swap_transfer_limit 138 | * */ 139 | public function postTransferLimit(array $data=[]){ 140 | $this->type='POST'; 141 | $this->path='/swap-api/v1/swap_transfer_limit'; 142 | 143 | $this->data=$data; 144 | return $this->exec(); 145 | } 146 | 147 | /** 148 | *post swap-api/v1/swap_position_limit 149 | * */ 150 | public function postPositionLimit(array $data=[]){ 151 | $this->type='POST'; 152 | $this->path='/swap-api/v1/swap_position_limit'; 153 | 154 | $this->data=$data; 155 | return $this->exec(); 156 | } 157 | 158 | /** 159 | *post /swap-api/v1/swap_master_sub_transfer 160 | * */ 161 | public function postMasterSubTransfer(array $data=[]){ 162 | $this->type='POST'; 163 | $this->path='/swap-api/v1/swap_master_sub_transfer'; 164 | 165 | $this->data=$data; 166 | return $this->exec(); 167 | } 168 | 169 | /** 170 | *post /swap-api/v1/swap_master_sub_transfer_record 171 | * */ 172 | public function postMasterSubTransferRecord(array $data=[]){ 173 | $this->type='POST'; 174 | $this->path='/swap-api/v1/swap_master_sub_transfer_record'; 175 | 176 | $this->data=$data; 177 | return $this->exec(); 178 | } 179 | 180 | /** 181 | *get /swap-api/v1/swap_api_trading_status 182 | * */ 183 | public function getApiTradingStatus(array $data=[]){ 184 | $this->type='GET'; 185 | $this->path='/swap-api/v1/swap_api_trading_status'; 186 | 187 | $this->data=$data; 188 | return $this->exec(); 189 | } 190 | } 191 | -------------------------------------------------------------------------------- /src/Api/Swap/Market.php: -------------------------------------------------------------------------------- 1 | 4 | * */ 5 | 6 | namespace Lin\Huobi\Api\Swap; 7 | 8 | 9 | 10 | use Lin\Huobi\Request; 11 | 12 | class Market extends Request 13 | { 14 | /** 15 | * 读取 基础行情接口 swap-api/v1/swap_contract_info GET 获取合约信息 否 16 | * */ 17 | public function getContractInfo(array $data=[]){ 18 | $this->type='GET'; 19 | $this->path='/swap-api/v1/swap_contract_info'; 20 | 21 | $this->data=$data; 22 | return $this->exec(); 23 | } 24 | 25 | 26 | /** 27 | * 读取 基础行情接口 swap-api/v1/swap_index GET 获取合约指数信息 否 28 | * */ 29 | public function getIndex(array $data=[]){ 30 | $this->type='GET'; 31 | $this->path='/swap-api/v1/swap_index'; 32 | 33 | $this->data=$data; 34 | return $this->exec(); 35 | } 36 | 37 | /** 38 | * 读取 基础行情接口 swap-api/v1/swap_price_limit GET 获取合约最高限价和最低限价 否 39 | * */ 40 | public function getPriceLimit(array $data=[]){ 41 | $this->type='GET'; 42 | $this->path='/swap-api/v1/swap_price_limit'; 43 | 44 | $this->data=$data; 45 | return $this->exec(); 46 | } 47 | 48 | /** 49 | *读取 基础行情接口 swap-api/v1/swap_open_interest GET 获取当前可用合约总持仓量 否 50 | * */ 51 | public function getOpenInterest(array $data=[]){ 52 | $this->type='GET'; 53 | $this->path='/swap-api/v1/swap_open_interest'; 54 | 55 | $this->data=$data; 56 | return $this->exec(); 57 | } 58 | 59 | /** 60 | *读取 市场行情接口 swap-ex/market/depth GET 获取行情深度数据 否 61 | * */ 62 | public function getDepth(array $data=[]){ 63 | $this->type='GET'; 64 | $this->path='/swap-ex/market/depth'; 65 | 66 | $this->data=$data; 67 | return $this->exec(); 68 | } 69 | 70 | /** 71 | *读取 市场行情接口 swap-ex/market/history/kline GET 获取K线数据 否 72 | * */ 73 | public function getHistorykline(array $data=[]){ 74 | $this->type='GET'; 75 | $this->path='/swap-ex/market/history/kline'; 76 | 77 | $this->data=$data; 78 | return $this->exec(); 79 | } 80 | 81 | /** 82 | *读取 市场行情接口 swap-ex/market/detail/merged GET 获取聚合行情 否 83 | * */ 84 | public function getDetailMerged(array $data=[]){ 85 | $this->type='GET'; 86 | $this->path='/swap-ex/market/detail/merged'; 87 | 88 | $this->data=$data; 89 | return $this->exec(); 90 | } 91 | 92 | /** 93 | *读取 市场行情接口 swap-ex/market/trade GET 获取市场最近成交记录 否 94 | * */ 95 | public function getTrade(array $data=[]){ 96 | $this->type='GET'; 97 | $this->path='/swap-ex/market/trade'; 98 | 99 | $this->data=$data; 100 | return $this->exec(); 101 | } 102 | 103 | /** 104 | *读取 市场行情接口 swap-api/v1/swap_risk_info GET 查询合约风险准备金余额和预估分摊比例 否 105 | * */ 106 | public function getRiskInfo(array $data=[]){ 107 | $this->type='GET'; 108 | $this->path='/swap-api/v1/swap_risk_info'; 109 | 110 | $this->data=$data; 111 | return $this->exec(); 112 | } 113 | 114 | /** 115 | *读取 市场行情接口 swap-api/v1/swap_insurance_fund GET 查询合约风险准备金余额历史数据 否 116 | * */ 117 | public function getIinsuranceFund(array $data=[]){ 118 | $this->type='GET'; 119 | $this->path='/swap-api/v1/swap_insurance_fund'; 120 | 121 | $this->data=$data; 122 | return $this->exec(); 123 | } 124 | 125 | /** 126 | *读取 市场行情接口 swap-api/v1/swap_adjustfactor GET 查询平台阶梯调整系数 否 127 | * */ 128 | public function getAdjustfactor(array $data=[]){ 129 | $this->type='GET'; 130 | $this->path='/swap-api/v1/swap_adjustfactor'; 131 | 132 | $this->data=$data; 133 | return $this->exec(); 134 | } 135 | 136 | /** 137 | *读取 市场行情接口 swap-api/v1/swap_his_open_interest GET 平台持仓量的查询 否 138 | * */ 139 | public function getHisOpenInterest(array $data=[]){ 140 | $this->type='GET'; 141 | $this->path='/swap-api/v1/swap_his_open_interest'; 142 | 143 | $this->data=$data; 144 | return $this->exec(); 145 | } 146 | 147 | /** 148 | *读取 市场行情接口 swap-api/v1/swap_elite_account_ratio GET 精英账户多空持仓对比-账户数 否 149 | * */ 150 | public function getEliteAccountRatio(array $data=[]){ 151 | $this->type='GET'; 152 | $this->path='/swap-api/v1/swap_elite_account_ratio'; 153 | 154 | $this->data=$data; 155 | return $this->exec(); 156 | } 157 | 158 | /** 159 | *读取 市场行情接口 swap-api/v1/swap_elite_position_ratio GET 精英账户多空持仓对比-持仓量 否 160 | * */ 161 | public function getElitePositionRatio(array $data=[]){ 162 | $this->type='GET'; 163 | $this->path='/swap-api/v1/swap_elite_position_ratio'; 164 | 165 | $this->data=$data; 166 | return $this->exec(); 167 | } 168 | 169 | /** 170 | *读取 市场行情接口 swap-api/v1/swap_api_state GET 查询系统状态 否 171 | * */ 172 | public function getApiState(array $data=[]){ 173 | $this->type='GET'; 174 | $this->path='/swap-api/v1/swap_api_state'; 175 | 176 | $this->data=$data; 177 | return $this->exec(); 178 | } 179 | 180 | /** 181 | *读取 市场行情接口 swap-api/v1/swap_funding_rate GET 获取合约的资金费率 否 182 | * */ 183 | public function getFundingRate(array $data=[]){ 184 | $this->type='GET'; 185 | $this->path='/swap-api/v1/swap_funding_rate'; 186 | 187 | $this->data=$data; 188 | return $this->exec(); 189 | } 190 | 191 | /** 192 | *读取 市场行情接口 swap-api/v1/swap_historical_funding_rate GET 获取合约的历史资金费率 否 193 | * */ 194 | public function getHistoricalFundingRate(array $data=[]){ 195 | $this->type='GET'; 196 | $this->path='/swap-api/v1/swap_historical_funding_rate'; 197 | 198 | $this->data=$data; 199 | return $this->exec(); 200 | } 201 | 202 | /** 203 | *读取 市场行情接口 /heartbeat GET 查询系统是否可用 否 204 | * */ 205 | public function getHeartbeat(array $data=[]){ 206 | $this->type='GET'; 207 | $this->path='/heartbeat'; 208 | 209 | $this->data=$data; 210 | return $this->exec(); 211 | } 212 | 213 | /** 214 | * 215 | * */ 216 | /* public function get(array $data=[]){ 217 | $this->type='GET'; 218 | $this->path=''; 219 | 220 | $this->data=$data; 221 | return $this->exec(); 222 | } */ 223 | } -------------------------------------------------------------------------------- /src/Api/Swap/Trade.php: -------------------------------------------------------------------------------- 1 | 4 | * */ 5 | 6 | namespace Lin\Huobi\Api\Swap; 7 | 8 | use Lin\Huobi\Request; 9 | 10 | class Trade extends Request 11 | { 12 | /** 13 | *POST swap-api/v1/swap_order 14 | * */ 15 | public function postOrder(array $data=[]){ 16 | $this->type='POST'; 17 | $this->path='/swap-api/v1/swap_order'; 18 | 19 | $this->data=$data; 20 | return $this->exec(); 21 | } 22 | 23 | /** 24 | *POST swap-api/v1/swap_batchorder 25 | * */ 26 | public function postBatchOrder(array $data=[]){ 27 | $this->type='POST'; 28 | $this->path='/swap-api/v1/swap_batchorder'; 29 | 30 | $this->data=$data; 31 | return $this->exec(); 32 | } 33 | 34 | /** 35 | *POST swap-api/v1/swap_cancel 36 | * */ 37 | public function postCancel(array $data=[]){ 38 | $this->type='POST'; 39 | $this->path='/swap-api/v1/swap_cancel'; 40 | 41 | $this->data=$data; 42 | return $this->exec(); 43 | } 44 | 45 | /** 46 | *POST swap-api/v1/swap_cancelall 47 | * */ 48 | public function postCancelAll(array $data=[]){ 49 | $this->type='POST'; 50 | $this->path='/swap-api/v1/swap_cancelall'; 51 | 52 | $this->data=$data; 53 | return $this->exec(); 54 | } 55 | 56 | /** 57 | *POST swap-api/v1/swap_switch_lever_rate 58 | * */ 59 | public function postSwitchLeverRate(array $data=[]){ 60 | $this->type='POST'; 61 | $this->path='/swap-api/v1/swap_switch_lever_rate'; 62 | 63 | $this->data=$data; 64 | return $this->exec(); 65 | } 66 | 67 | /** 68 | *POST swap-api/v1/swap_order_info 69 | * */ 70 | public function postOrderInfo(array $data=[]){ 71 | $this->type='POST'; 72 | $this->path='/swap-api/v1/swap_order_info'; 73 | 74 | $this->data=$data; 75 | return $this->exec(); 76 | } 77 | 78 | /** 79 | *POST swap-api/v1/swap_order_detail 80 | * */ 81 | public function postOrderDetail(array $data=[]){ 82 | $this->type='POST'; 83 | $this->path='/swap-api/v1/swap_order_detail'; 84 | 85 | $this->data=$data; 86 | return $this->exec(); 87 | } 88 | 89 | /** 90 | *POST swap-api/v1/swap_openorders 91 | * */ 92 | public function postOpenOrders(array $data=[]){ 93 | $this->type='POST'; 94 | $this->path='/swap-api/v1/swap_openorders'; 95 | 96 | $this->data=$data; 97 | return $this->exec(); 98 | } 99 | 100 | /** 101 | *POST swap-api/v1/swap_hisorders 102 | * */ 103 | public function postHisorders(array $data=[]){ 104 | $this->type='POST'; 105 | $this->path='/swap-api/v1/swap_hisorders'; 106 | 107 | $this->data=$data; 108 | return $this->exec(); 109 | } 110 | 111 | /** 112 | *POST swap-api/v1/swap_matchresults 113 | * */ 114 | public function postMatchResults(array $data=[]){ 115 | $this->type='POST'; 116 | $this->path='/swap-api/v1/swap_matchresults'; 117 | 118 | $this->data=$data; 119 | return $this->exec(); 120 | } 121 | 122 | /** 123 | *POST swap-api/v1/swap_lightning_close_position 124 | * */ 125 | public function postLightningClosePosition(array $data=[]){ 126 | $this->type='POST'; 127 | $this->path='/swap-api/v1/swap_lightning_close_position'; 128 | 129 | $this->data=$data; 130 | return $this->exec(); 131 | } 132 | 133 | /** 134 | *POST swap-api/v1/swap_trigger_order 135 | * */ 136 | public function postTriggerOrder(array $data=[]){ 137 | $this->type='POST'; 138 | $this->path='/swap-api/v1/swap_trigger_order'; 139 | 140 | $this->data=$data; 141 | return $this->exec(); 142 | } 143 | 144 | /** 145 | *POST swap-api/v1/swap_trigger_cancel 146 | * */ 147 | public function postTriggerCancel(array $data=[]){ 148 | $this->type='POST'; 149 | $this->path='/swap-api/v1/swap_trigger_cancel'; 150 | 151 | $this->data=$data; 152 | return $this->exec(); 153 | } 154 | 155 | /** 156 | *POST swap-api/v1/swap_trigger_cancelall 157 | * */ 158 | public function postTriggerCancelall(array $data=[]){ 159 | $this->type='POST'; 160 | $this->path='/swap-api/v1/swap_trigger_cancelall'; 161 | 162 | $this->data=$data; 163 | return $this->exec(); 164 | } 165 | 166 | /** 167 | *POST swap-api/v1/swap_trigger_openorders 168 | * */ 169 | public function postTriggerOpenorders(array $data=[]){ 170 | $this->type='POST'; 171 | $this->path='/swap-api/v1/swap_trigger_openorders'; 172 | 173 | $this->data=$data; 174 | return $this->exec(); 175 | } 176 | 177 | /** 178 | *POST swap-api/v1/swap_trigger_hisorders 179 | * */ 180 | public function postTriggerHisorders(array $data=[]){ 181 | $this->type='POST'; 182 | $this->path='/swap-api/v1/swap_trigger_hisorders'; 183 | 184 | $this->data=$data; 185 | return $this->exec(); 186 | } 187 | } 188 | -------------------------------------------------------------------------------- /src/Api/WebSocket/SocketClient.php: -------------------------------------------------------------------------------- 1 | 4 | * */ 5 | 6 | namespace Lin\Huobi\Api\WebSocket; 7 | 8 | use Lin\Huobi\Api\WebSocket\SocketGlobal; 9 | use Lin\Huobi\Api\WebSocket\SocketFunction; 10 | 11 | use Workerman\Lib\Timer; 12 | use Workerman\Worker; 13 | 14 | class SocketClient 15 | { 16 | use SocketGlobal; 17 | use SocketFunction; 18 | 19 | private $config=[]; 20 | private $keysecret=[]; 21 | 22 | 23 | function __construct(array $config=[]) 24 | { 25 | $this->config=$config; 26 | 27 | $this->client(); 28 | 29 | $this->init(); 30 | } 31 | 32 | protected function init(){ 33 | //初始化全局变量 34 | $this->add('global_key',[]);//保存全局变量key 35 | 36 | $this->add('all_sub',[]);//目前总共订阅的频道 37 | 38 | $this->add('add_sub',[]);//正在订阅的频道 39 | 40 | $this->add('del_sub',[]);//正在删除的频道 41 | 42 | $this->add('keysecret',[]);//目前总共key 43 | 44 | $this->add('global_local',[]);//临时存储数据 45 | 46 | $this->add('debug',[]); 47 | } 48 | 49 | function keysecret(array $keysecret=[]){ 50 | $this->keysecret=$keysecret; 51 | return $this; 52 | } 53 | 54 | /** 55 | * @param array $sub 56 | */ 57 | public function subscribe(array $sub=[]){ 58 | // 是否又私有频道订阅 59 | if(!empty($this->keysecret)) { 60 | $keysecret=$this->get('keysecret'); 61 | 62 | if(!isset($keysecret[$this->keysecret['key']]['connection'])) 63 | $this->keysecretInit($this->keysecret,[ 64 | 'connection'=>0, 65 | ]); 66 | } 67 | 68 | $add_sub=$this->get('add_sub'); 69 | if(empty($add_sub)) $this->save('add_sub',$this->resub($sub)); 70 | else $this->save('add_sub',array_merge($this->resub($sub),$add_sub)); 71 | } 72 | 73 | /** 74 | * @param array $sub 75 | */ 76 | public function unsubscribe(array $sub=[]){ 77 | // 是否又私有频道订阅 78 | /*if(!empty($this->keysecret)) { 79 | if(!isset($keysecret[$this->keysecret['key']]['connection'])) 80 | $this->keysecretInit($this->keysecret,[ 81 | 'connection_close'=>1, 82 | ]); 83 | }*/ 84 | 85 | $this->save('del_sub',$this->resub($sub)); 86 | } 87 | 88 | /** 89 | * @param array $sub 默认获取所有public订阅的数据,private数据需要设置keysecret 90 | * @param null $callback 91 | * @param bool $daemon 92 | * @return mixed 93 | */ 94 | public function getSubscribe(array $sub,$callback=null,$daemon=false){ 95 | if($daemon) $this->daemon($callback,$sub); 96 | 97 | return $this->getData($this,$callback,$sub); 98 | } 99 | 100 | /** 101 | * 返回订阅的所有数据 102 | * @param null $callback 103 | * @param bool $daemon 104 | * @return array 105 | */ 106 | public function getSubscribes($callback=null,$daemon=false){ 107 | if($daemon) $this->daemon($callback); 108 | 109 | return $this->getData($this,$callback); 110 | } 111 | 112 | protected function daemon($callback=null,$sub=[]){ 113 | $worker = new Worker(); 114 | $worker->onWorkerStart = function() use($callback,$sub) { 115 | $global = $this->client(); 116 | 117 | $time=isset($this->config['data_time']) ? $this->config['data_time'] : 0.5 ; 118 | 119 | Timer::add($time, function() use ($global,$callback,$sub){ 120 | $this->getData($global,$callback,$sub); 121 | }); 122 | }; 123 | Worker::runAll(); 124 | } 125 | 126 | /** 127 | * @param $global 128 | * @param null $callback 129 | * @param array $sub 返回规定的频道 130 | * @return array 131 | */ 132 | protected function getData($global,$callback=null,$sub=[]){ 133 | $all_sub=$global->get('all_sub'); 134 | if(empty($all_sub)) return []; 135 | 136 | $global_local=$global->get('global_local'); 137 | $temp=[]; 138 | 139 | //默认返回所有数据 140 | if(empty($sub)){ 141 | foreach ($all_sub as $k=>$v){ 142 | if(is_array($v)){ 143 | if(empty($this->keysecret) || $this->keysecret['key']!=$k) continue; 144 | 145 | foreach ($v as $vv){ 146 | $data=$global->getQueue(strtolower($vv)); 147 | $temp[strtolower($vv)]=$data; 148 | } 149 | }else{ 150 | //$data=$global->get(strtolower($v)); 151 | //$temp[strtolower($v)]=$data; 152 | $k_strtolower=strtolower($v); 153 | if(isset($global_local['public'][$k_strtolower])) $temp[$k_strtolower]=$global_local['public'][$k_strtolower]; 154 | } 155 | } 156 | }else{ 157 | //返回规定的数据 158 | if(!empty($this->keysecret)) { 159 | //是否有私有数据 160 | if(isset($all_sub[$this->keysecret['key']])) $sub=array_merge($sub,$all_sub[$this->keysecret['key']]); 161 | } 162 | 163 | //现货 maket数据key 无法对应。默认返回全部maket?? 164 | /*if($this->getPlatform()=='spot'){ 165 | 166 | }*/ 167 | 168 | //print_r($sub); 169 | foreach ($sub as $k=>$v){ 170 | //判断私有数据是否需要走队列数据 171 | $temp_v=explode(self::$USER_DELIMITER,$v); 172 | if(count($temp_v)>1){ 173 | //private 174 | $data=$global->getQueue(strtolower($v)); 175 | }else{ 176 | //public 177 | //$data=$global->get(strtolower($v)); 178 | $t=strtolower($v); 179 | if(isset($global_local['public'][$t])) $data=$global_local['public'][$t]; 180 | } 181 | 182 | if(empty($data)) continue; 183 | 184 | $temp[$v]=$data; 185 | } 186 | } 187 | 188 | if($callback!==null){ 189 | call_user_func_array($callback, array($temp)); 190 | } 191 | 192 | return $temp; 193 | } 194 | 195 | /* 196 | * 197 | * */ 198 | function reconPrivate(string $key){ 199 | $debug=$this->client->debug; 200 | if(empty($debug)){ 201 | $this->client->debug=[ 202 | 'private'=>[$key=>$key], 203 | ]; 204 | }else{ 205 | $this->client->debug=['private'=>array_merge($this->client->debug['private'],[$key=>$key])]; 206 | } 207 | } 208 | 209 | function reconPublic(){ 210 | $this->client->debug=[ 211 | 'public'=>['market'=>'close','kline'=>'close'], 212 | ]; 213 | } 214 | 215 | 216 | function test(){ 217 | print_r($this->client->all_sub); 218 | print_r($this->client->add_sub); 219 | print_r($this->client->del_sub); 220 | print_r($this->client->keysecret); 221 | print_r($this->client->global_key); 222 | } 223 | 224 | function test2(){ 225 | //print_r($this->client->global_key); 226 | $global_key=$this->client->global_key; 227 | foreach ($global_key as $k=>$v){ 228 | echo count($this->client->$v).'----'.$k.PHP_EOL; 229 | echo json_encode($this->client->$v).PHP_EOL; 230 | } 231 | } 232 | 233 | function test_reconnection(){ 234 | $this->reconPublic(); 235 | } 236 | 237 | function test_reconnection2($key){ 238 | $this->reconPrivate($key); 239 | } 240 | } 241 | -------------------------------------------------------------------------------- /src/Api/WebSocket/SocketFunction.php: -------------------------------------------------------------------------------- 1 | 4 | * */ 5 | 6 | namespace Lin\Huobi\Api\WebSocket; 7 | 8 | 9 | trait SocketFunction 10 | { 11 | //标记分隔符 12 | static $USER_DELIMITER='==='; 13 | 14 | /** 15 | * @param array $sub 16 | * @return array 17 | */ 18 | protected function resub(array $sub=[]){ 19 | $new_sub=[]; 20 | 21 | $temp1=[ 22 | 'account', 23 | 'position', 24 | 'order', 25 | 'trade.clearing',//spot 26 | 27 | //免加密 但是需要走用户通道 28 | 'contract_info', 29 | 'funding_rate' 30 | ]; 31 | 32 | foreach ($sub as $v) { 33 | $temp2=[$v]; 34 | foreach ($temp1 as $tv){ 35 | if(strpos($v, $tv) !== false){ 36 | array_push($temp2,empty($this->keysecret)? [] : $this->keysecret); 37 | } 38 | } 39 | array_push($new_sub,$temp2); 40 | } 41 | 42 | return $new_sub; 43 | } 44 | 45 | protected function log($message){ 46 | if (!is_string($message)) $message=json_encode($message); 47 | 48 | $time=time(); 49 | $tiemdate=date('Y-m-d H:i:s',$time); 50 | 51 | $message=$tiemdate.' '.$message.PHP_EOL; 52 | 53 | if(isset($this->config['log'])){ 54 | if(is_array($this->config['log']) && isset($this->config['log']['filename'])){ 55 | $filename=$this->config['log']['filename'].'-'.date('Y-m-d',$time).'.txt'; 56 | }else{ 57 | $filename=date('Y-m-d',$time).'.txt'; 58 | } 59 | 60 | file_put_contents($filename,$message,FILE_APPEND); 61 | } 62 | 63 | echo $message; 64 | } 65 | 66 | /** 67 | * 设置用户key 68 | * @param $keysecret 69 | */ 70 | protected function userKey(array $keysecret,string $sub){ 71 | return $keysecret['key'].self::$USER_DELIMITER.$sub; 72 | } 73 | 74 | /** 75 | * 根据huobi规则排序 76 | * */ 77 | protected function sort($param) 78 | { 79 | $u = []; 80 | $sort_rank = []; 81 | foreach ($param as $k => $v) { 82 | if(is_array($v)) $v=json_encode($v); 83 | $u[] = $k . "=" . urlencode($v); 84 | $sort_rank[] = ord($k); 85 | } 86 | asort($u); 87 | 88 | return $u; 89 | } 90 | 91 | private function auth(string $host,array $keysecret){ 92 | $platform=$this->getPlatform(); 93 | 94 | if($platform=='spot'){ 95 | $param = [ 96 | 'accessKey' => $keysecret['key'], 97 | 'signatureMethod' => 'HmacSHA256', 98 | 'signatureVersion' => '2.1', 99 | 'timestamp' => gmdate('Y-m-d\TH:i:s'), 100 | ]; 101 | //accessKey,signatureMethod,signatureVersion,timestamp 102 | $param_tmp=$this->sort($param); 103 | $host_tmp=explode('/', $host); 104 | if(isset($host_tmp[1])) $temp="GET\n" . $host_tmp[2] . "\n" . '/ws/v2' . "\n" . implode('&', $param_tmp); 105 | 106 | $signature=base64_encode(hash_hmac('sha256', $temp ?? '', $keysecret['secret'], true)); 107 | 108 | $param['signature']=$signature; 109 | return array_merge(["authType"=>"api"],$param); 110 | }else{ 111 | $param = [ 112 | 'AccessKeyId' => $keysecret['key'], 113 | 'SignatureMethod' => 'HmacSHA256', 114 | 'SignatureVersion' => '2', 115 | 'Timestamp' => gmdate('Y-m-d\TH:i:s'), 116 | ]; 117 | 118 | $param_tmp=$this->sort($param); 119 | 120 | $host_tmp=explode('/', $host); 121 | if(isset($host_tmp[1])) $temp="GET\n" . $host_tmp[2] . "\n/" . $host_tmp[3] . "\n" . implode('&', $param_tmp); 122 | 123 | $signature=base64_encode(hash_hmac('sha256', $temp ?? '', $keysecret['secret'], true)); 124 | 125 | return array_merge($param,[ 126 | "Signature"=> $signature 127 | ]); 128 | } 129 | } 130 | 131 | private function getPlatform(){ 132 | $platform='spot'; 133 | if(is_array($this->config['platform'])) $platform=$this->config['platform']['type']; 134 | else $platform=$this->config['platform']; 135 | 136 | return $platform; 137 | } 138 | 139 | /** 140 | * @param $tag 141 | * @param $data 142 | * @return array 143 | */ 144 | private function getDecodeData($tag,$data){ 145 | $platform=$this->getPlatform(); 146 | 147 | if($tag != 'market' && $platform=='spot') return json_decode($data,true); 148 | 149 | $data=gzdecode($data); 150 | return json_decode($data,true); 151 | } 152 | 153 | /** 154 | * @param $sub 155 | * @return array 156 | */ 157 | private function channelType($sub){ 158 | $temp=['market'=>[],'kline'=>[],'private'=>[]]; 159 | foreach ($sub as $k=>$v){ 160 | if(count($v)>1) array_push($temp['private'],$v); 161 | else { 162 | //检测是否是kline 数据通道 163 | $kline_data=false; 164 | $kline_key=['index','basis','estimated_rate']; 165 | foreach ($kline_key as $kv){ 166 | if(strpos($v[0], $kv) !== false){ 167 | array_push($temp['kline'],$v); 168 | $kline_data=true; 169 | } 170 | } 171 | 172 | if(!$kline_data) array_push($temp['market'],$v); 173 | } 174 | } 175 | 176 | return $temp; 177 | } 178 | 179 | /** 180 | * 重新订阅 181 | */ 182 | private function reconnection($global,$type='public',array $keysecret=[]){ 183 | $all_sub=$global->get('all_sub'); 184 | if(empty($all_sub)) return; 185 | 186 | if($type=='public'){ 187 | $temp=[]; 188 | foreach ($all_sub as $v){ 189 | if(!is_array($v)) $temp[]=$v; 190 | } 191 | }else{ 192 | $this->keysecret=$keysecret; 193 | 194 | $temp=[]; 195 | foreach ($all_sub[$keysecret['key']] as $v){ 196 | $t=explode(self::$USER_DELIMITER,$v); 197 | $temp[]=$t[1]; 198 | } 199 | } 200 | 201 | $add_sub=$global->get('add_sub'); 202 | if(empty($add_sub)) $global->save('add_sub',$this->resub($temp)); 203 | else $global->save('add_sub',array_merge($this->resub($temp),$add_sub)); 204 | } 205 | } 206 | -------------------------------------------------------------------------------- /src/Api/WebSocket/SocketGlobal.php: -------------------------------------------------------------------------------- 1 | 4 | * */ 5 | 6 | namespace Lin\Huobi\Api\WebSocket; 7 | 8 | use GlobalData\Server; 9 | use GlobalData\Client; 10 | 11 | trait SocketGlobal 12 | { 13 | protected $server; 14 | protected $client; 15 | 16 | private $config=[]; 17 | 18 | private function port(){ 19 | $temp=is_array($this->config['platform']) ? $this->config['platform']['type'] : $this->config['platform']; 20 | 21 | switch ($temp){ 22 | case 'option':{ 23 | return '2215'; 24 | } 25 | case 'linear':{ 26 | return '2214'; 27 | } 28 | case 'swap':{ 29 | return '2213'; 30 | } 31 | case 'future':{ 32 | return '2212'; 33 | } 34 | default:{//spot 35 | return '2211'; 36 | } 37 | } 38 | } 39 | 40 | protected function server(){ 41 | $address=isset($this->config['global']) ? explode(':',$this->config['global']) : ['0.0.0.0',$this->port()]; 42 | $this->server=new Server($address[0],$address[1]); 43 | return $this; 44 | } 45 | 46 | protected function client(){ 47 | $address=isset($this->config['global']) ? $this->config['global'] : '0.0.0.0:'.$this->port(); 48 | $this->client=new Client($address); 49 | return $this; 50 | } 51 | 52 | protected function add($key,$value){ 53 | $this->client->add($key,$value); 54 | 55 | $this->saveGlobalKey($key); 56 | } 57 | 58 | protected function get($key){ 59 | if(!isset($this->client->$key) || empty($this->client->$key)) return []; 60 | return $this->client->$key; 61 | } 62 | 63 | protected function save($key,$value){ 64 | if(!isset($this->client->$key)) $this->add($key,$value); 65 | else $this->client->$key=$value; 66 | } 67 | 68 | /** 69 | * 对了获取数据 70 | * @param $key 71 | * @return array 72 | */ 73 | protected function getQueue($key){ 74 | if(!isset($this->client->$key) || empty($this->client->$key)) return []; 75 | 76 | do{ 77 | $old_value=$new_value=$this->client->$key; 78 | 79 | if(empty($new_value)) return []; 80 | //队列先进先出。 81 | $value=array_shift($new_value); 82 | } 83 | while(!$this->client->cas($key, $old_value, $new_value)); 84 | 85 | return $value; 86 | } 87 | 88 | /** 89 | * 队列保存数据 90 | * @param $key 91 | * @param $value 92 | */ 93 | protected function saveQueue($key,$value){ 94 | //最大存储数据量,超过后保留一条最新的数据,其余数据全部删除。 95 | $max= isset($this->config['queue_count']) ? $this->config['queue_count'] : 100; 96 | 97 | if(!isset($this->client->$key)) $this->add($key,[$value]); 98 | else { 99 | do{ 100 | $old_value=$new_value=$this->client->$key; 101 | 102 | //超过最大数据量,保留最新数据 103 | if(count($new_value)>$max){ 104 | $new_value=[$value]; 105 | }else{ 106 | array_push($new_value,$value); 107 | } 108 | } 109 | while(!$this->client->cas($key, $old_value, $new_value)); 110 | } 111 | } 112 | 113 | protected function addSubUpdate($data=[]){ 114 | 115 | do{ 116 | $old_value=$new_value=$this->client->add_sub; 117 | 118 | if(empty($data)){ 119 | foreach ($new_value as $k=>$v){ 120 | unset($new_value[$k]); 121 | } 122 | }else{ 123 | foreach ($new_value as $k=>$v){ 124 | foreach ($data as $dk=>$dv){ 125 | if($v[0]==$dv[0]){ 126 | if(isset($v[1]['key']) && $v[1]['key']!=$dv[1]['key']) continue; 127 | unset($data[$dk]); 128 | unset($new_value[$k]); 129 | } 130 | } 131 | } 132 | } 133 | } 134 | while(!$this->client->cas('add_sub', $old_value, $new_value)); 135 | } 136 | 137 | protected function delSubUpdate($data=[]){ 138 | do{ 139 | $old_value=$new_value=$this->client->del_sub; 140 | /*print_r($old_value); 141 | print_r($data);*/ 142 | foreach ($data as $k=>$v){ 143 | if(count($v)>1){ 144 | foreach ($new_value as $ok=>$ov){ 145 | if($v[0]==$ov[0] && $v[1]['key']==$ov[1]['key']) { 146 | unset($new_value[$ok]); 147 | } 148 | } 149 | }else{ 150 | foreach ($new_value as $ok=>$ov) { 151 | if ($v[0] == $ov[0]) unset($new_value[$ok]); 152 | } 153 | } 154 | } 155 | } 156 | while(!$this->client->cas('del_sub', $old_value, $new_value)); 157 | } 158 | 159 | protected function allSubUpdate($data,$type='add'){ 160 | do{ 161 | $old_value=$new_value=$this->client->all_sub; 162 | /*print_r($old_value); 163 | print_r($data);*/ 164 | foreach ($data as $v){ 165 | switch ($type){ 166 | case 'add':{ 167 | if(count($v)>1){ 168 | //数据格式 169 | /*$v=[ 170 | [ 171 | 'orders.btc', 172 | ['key','keysecret'] 173 | ] 174 | ];*/ 175 | $key=$v[1]['key']; 176 | $value=[$this->userKey($v[1],strtolower($v[0]))]; 177 | if(!isset($new_value[$key])) $new_value[$key]=$value; 178 | else $new_value[$key]=array_unique(array_merge($new_value[$key],$value)); 179 | }else{ 180 | $new_value[$v[0]]=$v[0]; 181 | } 182 | break; 183 | } 184 | case 'del':{ 185 | if(count($v)>1){ 186 | $key=$v[1]['key']; 187 | $value=$this->userKey($v[1],strtolower($v[0])); 188 | 189 | //删除单个用户订阅删除 190 | foreach ($new_value[$key] as $k=>$v){ 191 | if($v==$value) unset($new_value[$key][$k]); 192 | } 193 | 194 | //如果该用户没有删除数据 则直接删除整个数据 195 | if(empty($new_value[$key])) unset($new_value[$key]); 196 | }else{ 197 | unset($new_value[$v[0]]); 198 | } 199 | break; 200 | } 201 | } 202 | } 203 | 204 | } 205 | while(!$this->client->cas('all_sub', $old_value, $new_value)); 206 | } 207 | 208 | protected function keysecretInit($keysecret,$data=[]){ 209 | do { 210 | $old_value = $new_value = $this->client->keysecret; 211 | 212 | if(empty($data)) { 213 | $new_value[$keysecret['key']]=[]; 214 | }else{ 215 | if(isset($new_value[$keysecret['key']])) $new_value[$keysecret['key']]=array_merge($new_value[$keysecret['key']],$keysecret); 216 | else $new_value[$keysecret['key']]=$keysecret; 217 | 218 | if(!empty($data)){ 219 | foreach ($data as $k=>$v){ 220 | $new_value[$keysecret['key']][$k]=$v; 221 | } 222 | } 223 | } 224 | } 225 | while(!$this->client->cas('keysecret', $old_value, $new_value)); 226 | } 227 | 228 | protected function saveGlobalKey($key){ 229 | do { 230 | $old_value = $new_value = $this->client->global_key; 231 | $new_value[$key]=$key; 232 | } 233 | while(!$this->client->cas('global_key', $old_value, $new_value)); 234 | } 235 | 236 | /** 237 | * Huobi 238 | */ 239 | protected function getId(){ 240 | list($msec, $sec) = explode(' ', microtime()); 241 | return (float)sprintf('%.0f', (floatval($msec) + floatval($sec)) * 1000).rand(1000,9999); 242 | } 243 | } 244 | -------------------------------------------------------------------------------- /src/Exceptions/Exception.php: -------------------------------------------------------------------------------- 1 | 4 | * */ 5 | 6 | namespace Lin\Huobi; 7 | 8 | 9 | 10 | use Lin\Huobi\Api\Futures\Contract; 11 | use Lin\Huobi\Api\Futures\Market; 12 | use Lin\Huobi\Api\Futures\Lightning; 13 | 14 | class HuobiFuture 15 | { 16 | protected $key; 17 | protected $secret; 18 | protected $host; 19 | 20 | protected $options=[]; 21 | 22 | function __construct(string $key='',string $secret='',string $host='https://api.hbdm.com'){ 23 | $this->key=$key; 24 | $this->secret=$secret; 25 | $this->host=$host; 26 | } 27 | 28 | /** 29 | * 30 | * */ 31 | private function init(){ 32 | return [ 33 | 'key'=>$this->key, 34 | 'secret'=>$this->secret, 35 | 'host'=>$this->host, 36 | 'options'=>$this->options, 37 | ]; 38 | } 39 | 40 | /** 41 | * 42 | * */ 43 | function setOptions(array $options=[]){ 44 | $this->options=$options; 45 | } 46 | 47 | /** 48 | * 49 | * */ 50 | public function contract(){ 51 | return new Contract($this->init()); 52 | } 53 | 54 | /** 55 | * 56 | * */ 57 | public function market(){ 58 | return new Market($this->init()); 59 | } 60 | 61 | /** 62 | * 63 | * */ 64 | public function lightning(){ 65 | return new Lightning($this->init()); 66 | } 67 | } -------------------------------------------------------------------------------- /src/HuobiLinear.php: -------------------------------------------------------------------------------- 1 | 4 | * */ 5 | 6 | namespace Lin\Huobi; 7 | 8 | use Lin\Huobi\Api\Linear\Market; 9 | use Lin\Huobi\Api\Linear\Account; 10 | use Lin\Huobi\Api\Linear\Trade; 11 | 12 | class HuobiLinear 13 | { 14 | protected $key; 15 | protected $secret; 16 | protected $host; 17 | 18 | protected $options=[]; 19 | 20 | function __construct(string $key='',string $secret='',string $host='https://api.hbdm.com'){ 21 | $this->key=$key; 22 | $this->secret=$secret; 23 | $this->host=$host; 24 | } 25 | 26 | /** 27 | * 28 | * */ 29 | private function init(){ 30 | return [ 31 | 'key'=>$this->key, 32 | 'secret'=>$this->secret, 33 | 'host'=>$this->host, 34 | 'options'=>$this->options, 35 | ]; 36 | } 37 | 38 | /** 39 | * 40 | * */ 41 | function setOptions(array $options=[]){ 42 | $this->options=$options; 43 | } 44 | 45 | /** 46 | * 47 | * */ 48 | public function account(){ 49 | return new Account($this->init()); 50 | } 51 | 52 | /** 53 | * 54 | * */ 55 | public function market(){ 56 | return new Market($this->init()); 57 | } 58 | 59 | /** 60 | * 61 | * */ 62 | public function trade(){ 63 | return new Trade($this->init()); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/HuobiSpot.php: -------------------------------------------------------------------------------- 1 | 4 | * */ 5 | 6 | namespace Lin\Huobi; 7 | 8 | use Lin\Huobi\Api\Spot\Reference; 9 | use Lin\Huobi\Api\Spot\Settings; 10 | use Lin\Huobi\Api\Spot\Subuser; 11 | use Lin\Huobi\Api\Spot\Order; 12 | use Lin\Huobi\Api\Spot\Market; 13 | use Lin\Huobi\Api\Spot\Margin; 14 | use Lin\Huobi\Api\Spot\Etf; 15 | use Lin\Huobi\Api\Spot\Common; 16 | use Lin\Huobi\Api\Spot\Account; 17 | use Lin\Huobi\Api\Spot\Wallet; 18 | use Lin\Huobi\Api\Spot\AlgoOrder; 19 | use Lin\Huobi\Api\Spot\C2c; 20 | use Lin\Huobi\Api\Spot\CrossMargin; 21 | 22 | class HuobiSpot 23 | { 24 | protected $key; 25 | protected $secret; 26 | protected $host; 27 | 28 | protected $options=[]; 29 | 30 | function __construct(string $key='',string $secret='',string $host='https://api.huobi.pro'){ 31 | $this->key=$key; 32 | $this->secret=$secret; 33 | $this->host=$host; 34 | } 35 | 36 | /** 37 | * 38 | * */ 39 | private function init(){ 40 | return [ 41 | 'key'=>$this->key, 42 | 'secret'=>$this->secret, 43 | 'host'=>$this->host, 44 | 'options'=>$this->options, 45 | ]; 46 | } 47 | 48 | /** 49 | * 50 | * */ 51 | function setOptions(array $options=[]){ 52 | $this->options=$options; 53 | } 54 | 55 | /** 56 | * 57 | * */ 58 | public function account(){ 59 | return new Account($this->init()); 60 | } 61 | 62 | /** 63 | * 64 | * */ 65 | public function algoorder(){ 66 | return new AlgoOrder($this->init()); 67 | } 68 | 69 | /** 70 | * 71 | * */ 72 | public function c2c(){ 73 | return new C2c($this->init()); 74 | } 75 | 76 | /** 77 | * 78 | * */ 79 | public function common(){ 80 | return new Common($this->init()); 81 | } 82 | 83 | /** 84 | * 85 | * */ 86 | public function crossmargin(){ 87 | return new CrossMargin($this->init()); 88 | } 89 | 90 | /** 91 | * 92 | * */ 93 | public function etf(){ 94 | return new Etf($this->init()); 95 | } 96 | 97 | /** 98 | * 99 | * */ 100 | public function margin(){ 101 | return new Margin($this->init()); 102 | } 103 | 104 | /** 105 | * 106 | * */ 107 | public function market(){ 108 | return new Market($this->init()); 109 | } 110 | 111 | /** 112 | * 113 | * */ 114 | public function order(){ 115 | return new Order($this->init()); 116 | } 117 | 118 | /** 119 | * 120 | * */ 121 | public function reference(){ 122 | return new Reference($this->init()); 123 | } 124 | 125 | /** 126 | * 127 | * */ 128 | public function settings(){ 129 | return new Settings($this->init()); 130 | } 131 | 132 | /** 133 | * 134 | * */ 135 | public function subuser(){ 136 | return new Subuser($this->init()); 137 | } 138 | 139 | /** 140 | * 141 | * */ 142 | public function wallet(){ 143 | return new Wallet($this->init()); 144 | } 145 | } -------------------------------------------------------------------------------- /src/HuobiSwap.php: -------------------------------------------------------------------------------- 1 | 4 | * */ 5 | 6 | namespace Lin\Huobi; 7 | 8 | use Lin\Huobi\Api\Swap\Market; 9 | use Lin\Huobi\Api\Swap\Account; 10 | use Lin\Huobi\Api\Swap\Trade; 11 | 12 | class HuobiSwap 13 | { 14 | protected $key; 15 | protected $secret; 16 | protected $host; 17 | 18 | protected $options=[]; 19 | 20 | function __construct(string $key='',string $secret='',string $host='https://api.hbdm.com'){ 21 | $this->key=$key; 22 | $this->secret=$secret; 23 | $this->host=$host; 24 | } 25 | 26 | /** 27 | * 28 | * */ 29 | private function init(){ 30 | return [ 31 | 'key'=>$this->key, 32 | 'secret'=>$this->secret, 33 | 'host'=>$this->host, 34 | 'options'=>$this->options, 35 | ]; 36 | } 37 | 38 | /** 39 | * 40 | * */ 41 | function setOptions(array $options=[]){ 42 | $this->options=$options; 43 | } 44 | 45 | /** 46 | * 47 | * */ 48 | public function account(){ 49 | return new Account($this->init()); 50 | } 51 | 52 | /** 53 | * 54 | * */ 55 | public function market(){ 56 | return new Market($this->init()); 57 | } 58 | 59 | /** 60 | * 61 | * */ 62 | public function trade(){ 63 | return new Trade($this->init()); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/HuobiWebSocket.php: -------------------------------------------------------------------------------- 1 | 4 | * */ 5 | 6 | namespace Lin\Huobi; 7 | 8 | use Lin\Huobi\Api\WebSocket\SocketServer; 9 | use Lin\Huobi\Api\WebSocket\SocketClient; 10 | 11 | 12 | class HuobiWebSocket 13 | { 14 | private $server=null; 15 | private $client=null; 16 | private $config=[]; 17 | 18 | /** 19 | * @param array $config 20 | */ 21 | public function config(array $config=[]){ 22 | $this->config=$config; 23 | } 24 | 25 | /** 26 | * @return SocketServer 27 | */ 28 | public function server(){ 29 | return $this->server = new SocketServer($this->config); 30 | } 31 | 32 | /** 33 | * @return SocketClient|null 34 | */ 35 | public function client(){ 36 | if($this->client!==null) return $this->client; 37 | return $this->client = new SocketClient($this->config); 38 | } 39 | 40 | /** 41 | * 42 | */ 43 | public function start(){ 44 | $this->server()->start(); 45 | } 46 | 47 | /** 48 | * @param array $keysecret 49 | */ 50 | function keysecret(array $keysecret=[]){ 51 | $this->client()->keysecret($keysecret); 52 | } 53 | 54 | /** 55 | * @param array $sub 56 | */ 57 | public function subscribe(array $sub=[]){ 58 | $this->client()->subscribe($sub); 59 | } 60 | 61 | /** 62 | * @param array $sub 63 | */ 64 | public function unsubscribe(array $sub=[]){ 65 | $this->client()->unsubscribe($sub); 66 | } 67 | 68 | /** 69 | * @param array $sub 70 | * @param null $callback 71 | * @param bool $daemon 72 | * @return array 73 | */ 74 | public function getSubscribe(array $sub,$callback=null,$daemon=false){ 75 | return $this->client()->getSubscribe($sub,$callback,$daemon); 76 | } 77 | 78 | /** 79 | * @param null $callback 80 | * @param bool $daemon 81 | * @return array 82 | */ 83 | public function getSubscribes($callback=null,$daemon=false){ 84 | return $this->client()->getSubscribes($callback,$daemon); 85 | } 86 | 87 | /** 88 | * Private channel reconnect 89 | * @param string $key 90 | */ 91 | public function reconPrivate(string $key){ 92 | $this->client()->reconPrivate($key); 93 | } 94 | 95 | /** 96 | * Public channel reconnect 97 | */ 98 | public function reconPublic(){ 99 | $this->client()->reconPublic(); 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /src/Request.php: -------------------------------------------------------------------------------- 1 | 4 | * */ 5 | 6 | namespace Lin\Huobi; 7 | 8 | use GuzzleHttp\Exception\RequestException; 9 | use Lin\Huobi\Exceptions\Exception; 10 | 11 | class Request 12 | { 13 | protected $key=''; 14 | 15 | protected $secret=''; 16 | 17 | protected $host=''; 18 | 19 | protected $account_id=''; 20 | 21 | 22 | 23 | protected $nonce=''; 24 | 25 | protected $signature=''; 26 | 27 | protected $headers=[]; 28 | 29 | protected $type=''; 30 | 31 | protected $path=''; 32 | 33 | protected $data=[]; 34 | 35 | protected $options=[]; 36 | 37 | public function __construct(array $data) 38 | { 39 | $this->key=$data['key'] ?? ''; 40 | $this->secret=$data['secret'] ?? ''; 41 | $this->host=$data['host'] ?? 'https://api.huobi.pro'; 42 | 43 | $this->options=$data['options'] ?? []; 44 | } 45 | 46 | /** 47 | * 48 | * */ 49 | protected function auth(){ 50 | $this->nonce(); 51 | 52 | $this->signature(); 53 | 54 | $this->headers(); 55 | 56 | $this->options(); 57 | } 58 | 59 | /** 60 | * 61 | * */ 62 | protected function nonce(){ 63 | $this->nonce=gmdate('Y-m-d\TH:i:s'); 64 | } 65 | 66 | /** 67 | * 68 | * */ 69 | protected function signature(){ 70 | if(empty($this->key)) return; 71 | 72 | $param = [ 73 | 'AccessKeyId' => $this->key, 74 | 'SignatureMethod' => 'HmacSHA256', 75 | 'SignatureVersion' => 2, 76 | 'Timestamp' => $this->nonce, 77 | ]; 78 | 79 | if(!empty($this->data)) { 80 | $param=array_merge($param,$this->data); 81 | } 82 | 83 | $param=$this->sort($param); 84 | 85 | $host_tmp=explode('https://', $this->host); 86 | if(isset($host_tmp[1])) $temp=$this->type . "\n" . $host_tmp[1] . "\n" . $this->path . "\n" . implode('&', $param); 87 | $signature=base64_encode(hash_hmac('sha256', $temp ?? '', $this->secret, true)); 88 | 89 | $param[]="Signature=" . urlencode($signature); 90 | 91 | $this->signature=implode('&', $param); 92 | } 93 | 94 | /** 95 | * 96 | * */ 97 | protected function sort($param) 98 | { 99 | $u = []; 100 | $sort_rank = []; 101 | foreach ($param as $k => $v) { 102 | if(is_array($v)) $v=json_encode($v); 103 | $u[] = $k . "=" . urlencode($v); 104 | $sort_rank[] = ord($k); 105 | } 106 | asort($u); 107 | 108 | return $u; 109 | } 110 | 111 | /** 112 | * 113 | * */ 114 | protected function headers(){ 115 | $this->headers=[ 116 | 'Content-Type' => 'application/json', 117 | ]; 118 | } 119 | 120 | /** 121 | * 122 | * */ 123 | protected function options(){ 124 | if(isset($this->options['headers'])) $this->headers=array_merge($this->headers,$this->options['headers']); 125 | 126 | $this->options['headers']=$this->headers; 127 | $this->options['timeout'] = $this->options['timeout'] ?? 60; 128 | } 129 | 130 | /** 131 | * 132 | * */ 133 | protected function send(){ 134 | $client = new \GuzzleHttp\Client(); 135 | 136 | if(!empty($this->data) && $this->type!='GET') { 137 | $this->options['body']=json_encode($this->data); 138 | } 139 | 140 | if($this->type=='GET' && empty($this->key)){ 141 | $this->signature = empty($this->data) ? '' : http_build_query($this->data); 142 | } 143 | 144 | $response = $client->request($this->type, $this->host.$this->path.'?'.$this->signature, $this->options); 145 | 146 | //echo $this->type.' '.$this->host.$this->path.'?'.$this->signature.PHP_EOL; 147 | //print_r($this->options); 148 | //echo PHP_EOL; 149 | 150 | return $response->getBody()->getContents(); 151 | } 152 | 153 | /* 154 | * 155 | * */ 156 | protected function exec(){ 157 | $this->auth(); 158 | 159 | try { 160 | $temp=json_decode($this->send(),true); 161 | if(isset($temp['status']) && $temp['status']=='error') { 162 | $temp['_method']=$this->type; 163 | $temp['_url']=$this->host.$this->path; 164 | $temp['_httpcode']=200; 165 | throw new Exception(json_encode($temp)); 166 | } 167 | 168 | return $temp; 169 | }catch (RequestException $e){ 170 | if(empty($e->getResponse()) || $e->getResponse()==null) throw new Exception(json_encode(['_message'=>'system error'])); 171 | 172 | if(method_exists($e->getResponse(),'getBody')){ 173 | $contents=$e->getResponse()->getBody()->getContents(); 174 | 175 | $temp = empty($contents) ? [] : json_decode($contents,true); 176 | 177 | if(!empty($temp)) { 178 | $temp['_method']=$this->type; 179 | $temp['_url']=$this->host.$this->path; 180 | }else{ 181 | $temp['_message']=$e->getMessage(); 182 | } 183 | }else{ 184 | $temp['_message']=$e->getMessage(); 185 | } 186 | 187 | $temp['_httpcode']=$e->getCode(); 188 | 189 | throw new Exception(json_encode($temp)); 190 | } 191 | } 192 | } 193 | -------------------------------------------------------------------------------- /tests/future/contract.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * Fill in your key and secret and pass can be directly run 8 | * 9 | * Most of them are unfinished and need your help 10 | * https://github.com/zhouaini528/okex-php.git 11 | * */ 12 | use Lin\Huobi\HuobiFuture; 13 | 14 | require __DIR__ .'../../../vendor/autoload.php'; 15 | 16 | include 'key_secret.php'; 17 | 18 | $huobi=new HuobiFuture($key,$secret); 19 | 20 | //You can set special needs 21 | $huobi->setOptions([ 22 | //Set the request timeout to 60 seconds by default 23 | 'timeout'=>10, 24 | 25 | //If you are developing locally and need an agent, you can set this 26 | //'proxy'=>true, 27 | //More flexible Settings 28 | /* 'proxy'=>[ 29 | 'http' => 'http://127.0.0.1:12333', 30 | 'https' => 'http://127.0.0.1:12333', 31 | 'no' => ['.cn'] 32 | ], */ 33 | //Close the certificate 34 | //'verify'=>false, 35 | ]); 36 | 37 | //Place an Order 38 | try { 39 | $result=$huobi->contract()->postOrder([ 40 | 'symbol'=>'EOS',//string false "BTC","ETH"... 41 | 'contract_type'=>'quarter',// string false Contract Type ("this_week": "next_week": "quarter":) 42 | 'contract_code'=>'EOS201225',// string false BTC180914 43 | 'price'=>'1',// decimal true Price 44 | 'volume'=>'1',// long true Numbers of orders (amount) 45 | 'direction'=>'buy',// string true Transaction direction 46 | 'offset'=>'open',// string true "open", "close" 47 | 'order_price_type'=>'limit',//"limit", "opponent" 48 | 'lever_rate'=>20,//int true Leverage rate [if“Open”is multiple orders in 10 rate, there will be not multiple orders in 20 rate 49 | 50 | //'client_order_id'=>'',//long false Clients fill and maintain themselves, and this time must be greater than last time 51 | ]); 52 | print_r($result); 53 | }catch (\Exception $e){ 54 | print_r(json_decode($e->getMessage(),true)); 55 | } 56 | 57 | //Get Information of an Order 58 | try { 59 | $result=$huobi->contract()->postOrderInfo([ 60 | 'order_id'=>$result['data']['order_id'],//You can also 'xxxx,xxxx,xxxx' multiple ID 61 | //'client_order_id'=>'xxxx', 62 | 'symbol'=>'EOS' 63 | ]); 64 | print_r($result); 65 | }catch (\Exception $e){ 66 | print_r(json_decode($e->getMessage(),true)); 67 | } 68 | 69 | //Cancel an Order 70 | try { 71 | $result=$huobi->contract()->postCancel([ 72 | 'order_id'=>$result['data'][0]['order_id'],//You can also 'xxxx,xxxx,xxxx' multiple ID 73 | //'client_order_id'=>'xxxx', 74 | 'symbol'=>'EOS' 75 | ]); 76 | print_r($result); 77 | }catch (\Exception $e){ 78 | print_r(json_decode($e->getMessage(),true)); 79 | } 80 | 81 | //User`s position Information 82 | try { 83 | $result=$huobi->contract()->postPositionInfo(); 84 | print_r($result); 85 | }catch (\Exception $e){ 86 | print_r(json_decode($e->getMessage(),true)); 87 | } 88 | 89 | //User`s Account Information 90 | try { 91 | $result=$huobi->contract()->postAccountInfo(); 92 | print_r($result); 93 | }catch (\Exception $e){ 94 | print_r(json_decode($e->getMessage(),true)); 95 | } 96 | 97 | //Get Contracts Information 98 | try { 99 | $result=$huobi->contract()->getContractInfo(); 100 | print_r($result); 101 | }catch (\Exception $e){ 102 | print_r(json_decode($e->getMessage(),true)); 103 | } 104 | 105 | 106 | /*try { 107 | $result=$huobi->contract()->postOpenOrders([ 108 | 'symbol'=>'EOS' 109 | ]); 110 | print_r($result); 111 | }catch (\Exception $e){ 112 | print_r(json_decode($e->getMessage(),true)); 113 | } 114 | 115 | try { 116 | $result=$huobi->contract()->postCancelAll([ 117 | 'symbol'=>'EOS' 118 | ]); 119 | print_r($result); 120 | }catch (\Exception $e){ 121 | print_r(json_decode($e->getMessage(),true)); 122 | } 123 | 124 | try { 125 | $result=$huobi->contract()->postBatchOrder([ 126 | 'orders_data'=>[ 127 | [ 128 | 'symbol'=>'EOS', 129 | 'contract_type'=>'quarter', 130 | 'contract_code'=>'EOS201225', 131 | 'price'=>'1', 132 | 'volume'=>'1', 133 | 'direction'=>'buy', 134 | 'offset'=>'open', 135 | 'order_price_type'=>'limit', 136 | 'lever_rate'=>20, 137 | ], 138 | [ 139 | 'symbol'=>'EOS', 140 | 'contract_type'=>'quarter', 141 | 'contract_code'=>'EOS201225', 142 | 'price'=>'1.1', 143 | 'volume'=>'1', 144 | 'direction'=>'buy', 145 | 'offset'=>'open', 146 | 'order_price_type'=>'limit', 147 | 'lever_rate'=>20, 148 | ], 149 | ], 150 | ]); 151 | print_r($result); 152 | }catch (\Exception $e){ 153 | print_r(json_decode($e->getMessage(),true)); 154 | }*/ 155 | -------------------------------------------------------------------------------- /tests/future/lightning.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * Fill in your key and secret and pass can be directly run 8 | * 9 | * Most of them are unfinished and need your help 10 | * https://github.com/zhouaini528/okex-php.git 11 | * */ 12 | use Lin\Huobi\HuobiFuture; 13 | 14 | require __DIR__ .'../../../vendor/autoload.php'; 15 | 16 | include 'key_secret.php'; 17 | 18 | $huobi=new HuobiFuture($key,$secret); 19 | 20 | //You can set special needs 21 | $huobi->setOptions([ 22 | //Set the request timeout to 60 seconds by default 23 | 'timeout'=>10, 24 | 25 | //If you are developing locally and need an agent, you can set this 26 | //'proxy'=>true, 27 | //More flexible Settings 28 | /* 'proxy'=>[ 29 | 'http' => 'http://127.0.0.1:12333', 30 | 'https' => 'http://127.0.0.1:12333', 31 | 'no' => ['.cn'] 32 | ], */ 33 | //Close the certificate 34 | //'verify'=>false, 35 | ]); 36 | 37 | //The Last Trade of a Contract 38 | try { 39 | $result=$huobi->lightning()->postClosePosition([ 40 | 'symbol'=>'ETC',//string false "BTC","ETH"... 41 | 'contract_type'=>'quarter',// string false Contract Type ("this_week": "next_week": "quarter":) 42 | 'contract_code'=>'ETC191227',// string false BTC180914 43 | 'volume'=>1, 44 | 'direction'=>'sell', 45 | //'client_order_id'=>rand(100000,999999) 46 | /* 47 | symbol false string 品种代码 "BTC","ETH"... 48 | contract_type false string 合约类型 “this_week”:当周,“next_week”:次周,“quarter”:季度 49 | contract_code false string 合约代码 BTC190903 50 | volume true int 委托数量(张) 51 | direction true string “buy”:买,“sell”:卖 52 | client_order_id false int (API)客户自己填写和维护,必须保持唯一 53 | */ 54 | ]); 55 | print_r($result); 56 | }catch (\Exception $e){ 57 | print_r(json_decode($e->getMessage(),true)); 58 | } -------------------------------------------------------------------------------- /tests/future/market.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * Fill in your key and secret and pass can be directly run 8 | * 9 | * Most of them are unfinished and need your help 10 | * https://github.com/zhouaini528/okex-php.git 11 | * */ 12 | use Lin\Huobi\HuobiFuture; 13 | 14 | require __DIR__ .'../../../vendor/autoload.php'; 15 | 16 | include 'key_secret.php'; 17 | 18 | $huobi=new HuobiFuture(); 19 | 20 | //You can set special needs 21 | $huobi->setOptions([ 22 | //Set the request timeout to 60 seconds by default 23 | 'timeout'=>10, 24 | 25 | //If you are developing locally and need an agent, you can set this 26 | 'proxy'=>true, 27 | //More flexible Settings 28 | /* 'proxy'=>[ 29 | 'http' => 'http://127.0.0.1:12333', 30 | 'https' => 'http://127.0.0.1:12333', 31 | 'no' => ['.cn'] 32 | ], */ 33 | //Close the certificate 34 | //'verify'=>false, 35 | ]); 36 | 37 | //The Last Trade of a Contract 38 | try { 39 | $result=$huobi->market()->getTrade([ 40 | 'symbol'=>'XRP_CQ' 41 | ]); 42 | print_r($result); 43 | }catch (\Exception $e){ 44 | print_r(json_decode($e->getMessage(),true)); 45 | } 46 | 47 | //Request a Batch of Trade Records of a Contract 48 | try { 49 | $result=$huobi->market()->getHistoryTrade([ 50 | 'symbol'=>'XRP_CQ', 51 | //'size'=>100 52 | ]); 53 | print_r($result); 54 | }catch (\Exception $e){ 55 | print_r(json_decode($e->getMessage(),true)); 56 | } 57 | 58 | //Get Market Depth 59 | try { 60 | $result=$huobi->market()->getDepth([ 61 | 'symbol'=>'XRP_CQ', 62 | 'type'=>'step1' 63 | ]); 64 | print_r($result); 65 | }catch (\Exception $e){ 66 | print_r(json_decode($e->getMessage(),true)); 67 | } 68 | 69 | 70 | 71 | -------------------------------------------------------------------------------- /tests/linear/account.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * Fill in your key and secret and pass can be directly run 8 | * 9 | * Most of them are unfinished and need your help 10 | * https://github.com/zhouaini528/okex-php.git 11 | * */ 12 | use Lin\Huobi\HuobiLinear; 13 | 14 | require __DIR__ .'../../../vendor/autoload.php'; 15 | 16 | include 'key_secret.php'; 17 | 18 | $huobi=new HuobiLinear($key,$secret); 19 | 20 | //You can set special needs 21 | $huobi->setOptions([ 22 | //Set the request timeout to 60 seconds by default 23 | 'timeout'=>10, 24 | 25 | //If you are developing locally and need an agent, you can set this 26 | //'proxy'=>true, 27 | //More flexible Settings 28 | /* 'proxy'=>[ 29 | 'http' => 'http://127.0.0.1:12333', 30 | 'https' => 'http://127.0.0.1:12333', 31 | 'no' => ['.cn'] 32 | ], */ 33 | //Close the certificate 34 | //'verify'=>false, 35 | ]); 36 | 37 | //User`s position Information 38 | try { 39 | $result=$huobi->account()->postPositionInfo(); 40 | print_r($result); 41 | }catch (\Exception $e){ 42 | print_r(json_decode($e->getMessage(),true)); 43 | } 44 | 45 | -------------------------------------------------------------------------------- /tests/linear/market.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * Fill in your key and secret and pass can be directly run 8 | * 9 | * Most of them are unfinished and need your help 10 | * https://github.com/zhouaini528/okex-php.git 11 | * */ 12 | use Lin\Huobi\HuobiLinear; 13 | 14 | require __DIR__ .'../../../vendor/autoload.php'; 15 | 16 | include 'key_secret.php'; 17 | 18 | $huobi=new HuobiLinear(); 19 | 20 | //You can set special needs 21 | $huobi->setOptions([ 22 | //Set the request timeout to 60 seconds by default 23 | 'timeout'=>10, 24 | 25 | //If you are developing locally and need an agent, you can set this 26 | //'proxy'=>true, 27 | //More flexible Settings 28 | /* 'proxy'=>[ 29 | 'http' => 'http://127.0.0.1:12333', 30 | 'https' => 'http://127.0.0.1:12333', 31 | 'no' => ['.cn'] 32 | ], */ 33 | //Close the certificate 34 | //'verify'=>false, 35 | ]); 36 | 37 | //The Last Trade of a Contract 38 | try { 39 | $result=$huobi->market()->getTrade([ 40 | 'contract_code'=>'ETH-USD' 41 | ]); 42 | print_r($result); 43 | }catch (\Exception $e){ 44 | print_r(json_decode($e->getMessage(),true)); 45 | } 46 | 47 | //Request a Batch of Trade Records of a Contract 48 | try { 49 | $result=$huobi->market()->getHistorykline([ 50 | 'contract_code'=>'ETH-USD', 51 | 'period'=>'1min', 52 | 'size'=>10 53 | ]); 54 | print_r($result); 55 | }catch (\Exception $e){ 56 | print_r(json_decode($e->getMessage(),true)); 57 | } 58 | 59 | //Get Market Depth 60 | try { 61 | $result=$huobi->market()->getDepth([ 62 | 'contract_code'=>'ETH-USD', 63 | 'type'=>'step1' 64 | ]); 65 | print_r($result); 66 | }catch (\Exception $e){ 67 | print_r(json_decode($e->getMessage(),true)); 68 | } 69 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /tests/linear/trade.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * Fill in your key and secret and pass can be directly run 8 | * 9 | * Most of them are unfinished and need your help 10 | * https://github.com/zhouaini528/okex-php.git 11 | * */ 12 | use Lin\Huobi\HuobiLinear; 13 | 14 | require __DIR__ .'../../../vendor/autoload.php'; 15 | 16 | include 'key_secret.php'; 17 | 18 | $huobi=new HuobiLinear($key,$secret); 19 | 20 | //You can set special needs 21 | $huobi->setOptions([ 22 | //Set the request timeout to 60 seconds by default 23 | 'timeout'=>10, 24 | 25 | //If you are developing locally and need an agent, you can set this 26 | //'proxy'=>true, 27 | //More flexible Settings 28 | /* 'proxy'=>[ 29 | 'http' => 'http://127.0.0.1:12333', 30 | 'https' => 'http://127.0.0.1:12333', 31 | 'no' => ['.cn'] 32 | ], */ 33 | //Close the certificate 34 | //'verify'=>false, 35 | ]); 36 | 37 | //Place an Order 38 | try { 39 | $result=$huobi->trade()->postOrder([ 40 | 'contract_code'=>'ETH-USD',// string false BTC180914 41 | 'price'=>'100',// decimal true Price 42 | 'volume'=>'1',// long true Numbers of orders (amount) 43 | 'direction'=>'buy',// string true Transaction direction 44 | 'offset'=>'open',// string true "open", "close" 45 | 'order_price_type'=>'limit',//"limit", "opponent" 46 | 'lever_rate'=>20,//int true Leverage rate [if“Open”is multiple orders in 10 rate, there will be not multiple orders in 20 rate 47 | 48 | //'client_order_id'=>'',//long false Clients fill and maintain themselves, and this time must be greater than last time 49 | ]); 50 | print_r($result); 51 | }catch (\Exception $e){ 52 | print_r(json_decode($e->getMessage(),true)); 53 | } 54 | sleep(1); 55 | 56 | //Get Information of an Order 57 | try { 58 | $result=$huobi->trade()->postOrderInfo([ 59 | 'order_id'=>$result['data']['order_id'],//You can also 'xxxx,xxxx,xxxx' multiple ID 60 | //'client_order_id'=>'xxxx', 61 | 'contract_code'=>'ETH-USD' 62 | ]); 63 | print_r($result); 64 | }catch (\Exception $e){ 65 | print_r(json_decode($e->getMessage(),true)); 66 | } 67 | sleep(1); 68 | 69 | //Cancel an Order 70 | try { 71 | $result=$huobi->trade()->postCancel([ 72 | 'order_id'=>$result['data'][0]['order_id'],//You can also 'xxxx,xxxx,xxxx' multiple ID 73 | //'client_order_id'=>'xxxx', 74 | 'contract_code'=>'ETH-USD' 75 | ]); 76 | print_r($result); 77 | }catch (\Exception $e){ 78 | print_r(json_decode($e->getMessage(),true)); 79 | } 80 | sleep(1); 81 | -------------------------------------------------------------------------------- /tests/spot/account.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * Fill in your key and secret and pass can be directly run 8 | * 9 | * Most of them are unfinished and need your help 10 | * https://github.com/zhouaini528/huobi-php.git 11 | * */ 12 | use Lin\Huobi\HuobiSpot; 13 | 14 | require __DIR__ .'../../../vendor/autoload.php'; 15 | 16 | include 'key_secret.php'; 17 | 18 | $huobi=new HuobiSpot($key,$secret); 19 | 20 | //You can set special needs 21 | $huobi->setOptions([ 22 | //Set the request timeout to 60 seconds by default 23 | 'timeout'=>10, 24 | 25 | ]); 26 | 27 | //get the status of an account 28 | try { 29 | $result=$huobi->account()->get(); 30 | print_r($result); 31 | }catch (\Exception $e){ 32 | print_r(json_decode($e->getMessage(),true)); 33 | } 34 | 35 | //Get the balance of an account 36 | try { 37 | $result=$huobi->account()->getBalance([ 38 | 'account-id'=>$result['data'][0]['id'] 39 | ]); 40 | print_r($result); 41 | }catch (\Exception $e){ 42 | print_r(json_decode($e->getMessage(),true)); 43 | } 44 | 45 | -------------------------------------------------------------------------------- /tests/spot/market.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * Fill in your key and secret and pass can be directly run 8 | * 9 | * Most of them are unfinished and need your help 10 | * https://github.com/zhouaini528/huobi-php.git 11 | * */ 12 | use Lin\Huobi\HuobiSpot; 13 | 14 | require __DIR__ .'../../../vendor/autoload.php'; 15 | 16 | $huobi=new HuobiSpot(); 17 | 18 | //You can set special needs 19 | $huobi->setOptions([ 20 | //Set the request timeout to 60 seconds by default 21 | 'timeout'=>10, 22 | 23 | //If you are developing locally and need an agent, you can set this 24 | 'proxy'=>true, 25 | //More flexible Settings 26 | /* 'proxy'=>[ 27 | 'http' => 'http://127.0.0.1:12333', 28 | 'https' => 'http://127.0.0.1:12333', 29 | 'no' => ['.cn'] 30 | ], */ 31 | //Close the certificate 32 | //'verify'=>false, 33 | ]); 34 | 35 | 36 | //Get market data. This endpoint provides the snapshots of market data and can be used without verifications. 37 | try { 38 | $result=$huobi->market()->getDepth([ 39 | 'symbol'=>'btcusdt', 40 | //'type'=>'step3' default step0 41 | ]); 42 | print_r($result); 43 | }catch (\Exception $e){ 44 | print_r(json_decode($e->getMessage(),true)); 45 | } 46 | 47 | //List trading pairs and get the trading limit, price, and more information of different trading pairs. 48 | try { 49 | $result=$huobi->market()->getTickers(); 50 | print_r($result); 51 | }catch (\Exception $e){ 52 | print_r(json_decode($e->getMessage(),true)); 53 | } 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /tests/spot/order.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * Fill in your key and secret and pass can be directly run 8 | * 9 | * Most of them are unfinished and need your help 10 | * https://github.com/zhouaini528/huobi-php.git 11 | * */ 12 | use Lin\Huobi\HuobiSpot; 13 | 14 | require __DIR__ .'../../../vendor/autoload.php'; 15 | 16 | include 'key_secret.php'; 17 | 18 | $huobi=new HuobiSpot($key,$secret); 19 | 20 | //You can set special needs 21 | $huobi->setOptions([ 22 | //Set the request timeout to 60 seconds by default 23 | 'timeout'=>10, 24 | 25 | //If you are developing locally and need an agent, you can set this 26 | //'proxy'=>true, 27 | //More flexible Settings 28 | /* 'proxy'=>[ 29 | 'http' => 'http://127.0.0.1:12333', 30 | 'https' => 'http://127.0.0.1:12333', 31 | 'no' => ['.cn'] 32 | ], */ 33 | //Close the certificate 34 | //'verify'=>false, 35 | ]); 36 | 37 | 38 | //Place an Order 39 | try { 40 | $result=$huobi->order()->postPlace([ 41 | 'account-id'=>$account_id, 42 | 'symbol'=>'btcusdt', 43 | 'type'=>'buy-limit', 44 | 'amount'=>'0.1', 45 | 'price'=>'1000', 46 | ]); 47 | print_r($result); 48 | }catch (\Exception $e){ 49 | print_r(json_decode($e->getMessage(),true)); 50 | } 51 | sleep(1); 52 | 53 | //Get order details by order ID. 54 | try { 55 | $result=$huobi->order()->get([ 56 | 'order-id'=>$result['data'], 57 | ]); 58 | print_r($result); 59 | }catch (\Exception $e){ 60 | print_r(json_decode($e->getMessage(),true)); 61 | } 62 | sleep(1); 63 | 64 | //Cancelling an unfilled order. 65 | try { 66 | $result=$huobi->order()->postSubmitCancel([ 67 | 'order-id'=>$result['data']['id'], 68 | ]); 69 | print_r($result); 70 | }catch (\Exception $e){ 71 | print_r(json_decode($e->getMessage(),true)); 72 | } 73 | die; 74 | //***********************Customize the order ID 75 | //Place an Order 76 | try { 77 | $client_order_id=rand(10000,99999).rand(10000,99999); 78 | echo $client_order_id."\n"; 79 | $result=$huobi->order()->postPlace([ 80 | 'account-id'=>$account_id, 81 | 'symbol'=>'btcusdt', 82 | 'type'=>'buy-limit', 83 | 'amount'=>'0.001', 84 | 'price'=>'1000', 85 | 'client-order-id'=>$client_order_id, 86 | ]); 87 | print_r($result); 88 | }catch (\Exception $e){ 89 | print_r(json_decode($e->getMessage(),true)); 90 | } 91 | sleep(1); 92 | 93 | //Get order details by order ID. 94 | try { 95 | $result=$huobi->order()->getClientOrder([ 96 | 'clientOrderId'=>$client_order_id, 97 | ]); 98 | print_r($result); 99 | }catch (\Exception $e){ 100 | print_r(json_decode($e->getMessage(),true)); 101 | } 102 | sleep(1); 103 | 104 | //Cancelling an unfilled order. 105 | try { 106 | $result=$huobi->order()->postSubmitCancelClientOrder([ 107 | 'client-order-id'=>$client_order_id, 108 | ]); 109 | print_r($result); 110 | }catch (\Exception $e){ 111 | print_r(json_decode($e->getMessage(),true)); 112 | } 113 | 114 | 115 | 116 | 117 | -------------------------------------------------------------------------------- /tests/spot/proxy.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * Fill in your key and secret and pass can be directly run 8 | * 9 | * Most of them are unfinished and need your help 10 | * https://github.com/zhouaini528/huobi-php.git 11 | * */ 12 | use Lin\Huobi\HuobiSpot; 13 | 14 | require __DIR__ .'../../../vendor/autoload.php'; 15 | 16 | include 'key_secret.php'; 17 | 18 | $huobi=new HuobiSpot($key,$secret); 19 | 20 | //You can set special needs 21 | $huobi->setOptions([ 22 | //Set the request timeout to 60 seconds by default 23 | 'timeout'=>10, 24 | 25 | //If you are developing locally and need an agent, you can set this 26 | 'proxy'=>true, 27 | //More flexible Settings 28 | /* 'proxy'=>[ 29 | 'http' => 'http://127.0.0.1:12333', 30 | 'https' => 'http://127.0.0.1:12333', 31 | 'no' => ['.cn'] 32 | ], */ 33 | //Close the certificate 34 | //'verify'=>false, 35 | ]); 36 | 37 | 38 | //get the status of an account 39 | try { 40 | $result=$huobi->account()->get(); 41 | print_r($result); 42 | }catch (\Exception $e){ 43 | print_r(json_decode($e->getMessage(),true)); 44 | } 45 | 46 | //Get the balance of an account 47 | try { 48 | $result=$huobi->account()->getBalance([ 49 | 'account-id'=>$result['data'][0]['id'] 50 | ]); 51 | print_r($result); 52 | }catch (\Exception $e){ 53 | print_r(json_decode($e->getMessage(),true)); 54 | } 55 | 56 | -------------------------------------------------------------------------------- /tests/spot/subuser.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * Fill in your key and secret and pass can be directly run 8 | * 9 | * Most of them are unfinished and need your help 10 | * https://github.com/zhouaini528/huobi-php.git 11 | * */ 12 | use Lin\Huobi\HuobiSpot; 13 | 14 | require __DIR__ .'../../../vendor/autoload.php'; 15 | 16 | include 'key_secret.php'; 17 | 18 | $huobi=new HuobiSpot($key,$secret); 19 | 20 | //You can set special needs 21 | $huobi->setOptions([ 22 | //Set the request timeout to 60 seconds by default 23 | 'timeout'=>10, 24 | ]); 25 | 26 | 27 | try { 28 | $result=$huobi->subuser()->getUid(); 29 | print_r($result); 30 | }catch (\Exception $e){ 31 | print_r(json_decode($e->getMessage(),true)); 32 | } 33 | 34 | 35 | try { 36 | $result=$huobi->subuser()->postCreation([ 37 | 'userList'=>[ 38 | ['userName'=>'aaaf54142h','note'=>'xxfdfs34'], 39 | ], 40 | ]); 41 | print_r($result); 42 | }catch (\Exception $e){ 43 | print_r(json_decode($e->getMessage(),true)); 44 | } 45 | 46 | die; 47 | try { 48 | $result=$huobi->subuser()->getApiKey([ 49 | 'uid'=>'11111111', 50 | ]); 51 | print_r($result); 52 | }catch (\Exception $e){ 53 | print_r(json_decode($e->getMessage(),true)); 54 | } 55 | 56 | 57 | -------------------------------------------------------------------------------- /tests/spot/transfer.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * Fill in your key and secret and pass can be directly run 8 | * 9 | * Most of them are unfinished and need your help 10 | * https://github.com/zhouaini528/huobi-php.git 11 | * */ 12 | use Lin\Huobi\HuobiSpot; 13 | 14 | require __DIR__ .'../../../vendor/autoload.php'; 15 | 16 | include 'key_secret.php'; 17 | 18 | $huobi=new HuobiSpot($key,$secret); 19 | 20 | //You can set special needs 21 | $huobi->setOptions([ 22 | //Set the request timeout to 60 seconds by default 23 | 'timeout'=>10, 24 | 25 | //If you are developing locally and need an agent, you can set this 26 | 'proxy'=>true, 27 | //More flexible Settings 28 | /* 'proxy'=>[ 29 | 'http' => 'http://127.0.0.1:12333', 30 | 'https' => 'http://127.0.0.1:12333', 31 | 'no' => ['.cn'] 32 | ], */ 33 | //Close the certificate 34 | //'verify'=>false, 35 | ]); 36 | 37 | 38 | try { 39 | $result=$huobi->account()->postFuturesTransfer([ 40 | //currency string true NA 币种, e.g. btc 41 | //amount decimal true NA 划转数量 42 | //type string true NA 划转类型 从合约账户到现货账户:“futures-to-pro”,从现货账户到合约账户: “pro-to-futures” 43 | 'currency'=>'btc', 44 | 'amount'=>'0.001', 45 | 'type'=>'pro-to-futures' 46 | ]); 47 | print_r($result); 48 | }catch (\Exception $e){ 49 | print_r(json_decode($e->getMessage(),true)); 50 | } 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /tests/swap/account.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * Fill in your key and secret and pass can be directly run 8 | * 9 | * Most of them are unfinished and need your help 10 | * https://github.com/zhouaini528/okex-php.git 11 | * */ 12 | use Lin\Huobi\HuobiSwap; 13 | 14 | require __DIR__ .'../../../vendor/autoload.php'; 15 | 16 | include 'key_secret.php'; 17 | 18 | $huobi=new HuobiSwap($key,$secret); 19 | 20 | //You can set special needs 21 | $huobi->setOptions([ 22 | //Set the request timeout to 60 seconds by default 23 | 'timeout'=>10, 24 | 25 | //If you are developing locally and need an agent, you can set this 26 | //'proxy'=>true, 27 | //More flexible Settings 28 | /* 'proxy'=>[ 29 | 'http' => 'http://127.0.0.1:12333', 30 | 'https' => 'http://127.0.0.1:12333', 31 | 'no' => ['.cn'] 32 | ], */ 33 | //Close the certificate 34 | //'verify'=>false, 35 | ]); 36 | 37 | //User`s position Information 38 | try { 39 | $result=$huobi->account()->postPositionInfo(); 40 | print_r($result); 41 | }catch (\Exception $e){ 42 | print_r(json_decode($e->getMessage(),true)); 43 | } 44 | 45 | -------------------------------------------------------------------------------- /tests/swap/market.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * Fill in your key and secret and pass can be directly run 8 | * 9 | * Most of them are unfinished and need your help 10 | * https://github.com/zhouaini528/okex-php.git 11 | * */ 12 | use Lin\Huobi\HuobiSwap; 13 | 14 | require __DIR__ .'../../../vendor/autoload.php'; 15 | 16 | include 'key_secret.php'; 17 | 18 | $huobi=new HuobiSwap(); 19 | 20 | //You can set special needs 21 | $huobi->setOptions([ 22 | //Set the request timeout to 60 seconds by default 23 | 'timeout'=>10, 24 | 25 | //If you are developing locally and need an agent, you can set this 26 | //'proxy'=>true, 27 | //More flexible Settings 28 | /* 'proxy'=>[ 29 | 'http' => 'http://127.0.0.1:12333', 30 | 'https' => 'http://127.0.0.1:12333', 31 | 'no' => ['.cn'] 32 | ], */ 33 | //Close the certificate 34 | //'verify'=>false, 35 | ]); 36 | 37 | //The Last Trade of a Contract 38 | try { 39 | $result=$huobi->market()->getTrade([ 40 | 'contract_code'=>'ETH-USD' 41 | ]); 42 | print_r($result); 43 | }catch (\Exception $e){ 44 | print_r(json_decode($e->getMessage(),true)); 45 | } 46 | 47 | //Request a Batch of Trade Records of a Contract 48 | try { 49 | $result=$huobi->market()->getHistorykline([ 50 | 'contract_code'=>'ETH-USD', 51 | 'period'=>'1min', 52 | 'size'=>10 53 | ]); 54 | print_r($result); 55 | }catch (\Exception $e){ 56 | print_r(json_decode($e->getMessage(),true)); 57 | } 58 | 59 | //Get Market Depth 60 | try { 61 | $result=$huobi->market()->getDepth([ 62 | 'contract_code'=>'ETH-USD', 63 | 'type'=>'step1' 64 | ]); 65 | print_r($result); 66 | }catch (\Exception $e){ 67 | print_r(json_decode($e->getMessage(),true)); 68 | } 69 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /tests/swap/trade.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * Fill in your key and secret and pass can be directly run 8 | * 9 | * Most of them are unfinished and need your help 10 | * https://github.com/zhouaini528/okex-php.git 11 | * */ 12 | use Lin\Huobi\HuobiSwap; 13 | 14 | require __DIR__ .'../../../vendor/autoload.php'; 15 | 16 | include 'key_secret.php'; 17 | 18 | $huobi=new HuobiSwap($key,$secret); 19 | 20 | //You can set special needs 21 | $huobi->setOptions([ 22 | //Set the request timeout to 60 seconds by default 23 | 'timeout'=>10, 24 | 25 | //If you are developing locally and need an agent, you can set this 26 | //'proxy'=>true, 27 | //More flexible Settings 28 | /* 'proxy'=>[ 29 | 'http' => 'http://127.0.0.1:12333', 30 | 'https' => 'http://127.0.0.1:12333', 31 | 'no' => ['.cn'] 32 | ], */ 33 | //Close the certificate 34 | //'verify'=>false, 35 | ]); 36 | 37 | //Place an Order 38 | try { 39 | $result=$huobi->trade()->postOrder([ 40 | 'contract_code'=>'ETH-USD',// string false BTC180914 41 | 'price'=>'100',// decimal true Price 42 | 'volume'=>'1',// long true Numbers of orders (amount) 43 | 'direction'=>'buy',// string true Transaction direction 44 | 'offset'=>'open',// string true "open", "close" 45 | 'order_price_type'=>'limit',//"limit", "opponent" 46 | 'lever_rate'=>20,//int true Leverage rate [if“Open”is multiple orders in 10 rate, there will be not multiple orders in 20 rate 47 | 48 | //'client_order_id'=>'',//long false Clients fill and maintain themselves, and this time must be greater than last time 49 | ]); 50 | print_r($result); 51 | }catch (\Exception $e){ 52 | print_r(json_decode($e->getMessage(),true)); 53 | } 54 | sleep(1); 55 | 56 | //Get Information of an Order 57 | try { 58 | $result=$huobi->trade()->postOrderInfo([ 59 | 'order_id'=>$result['data']['order_id'],//You can also 'xxxx,xxxx,xxxx' multiple ID 60 | //'client_order_id'=>'xxxx', 61 | 'contract_code'=>'ETH-USD' 62 | ]); 63 | print_r($result); 64 | }catch (\Exception $e){ 65 | print_r(json_decode($e->getMessage(),true)); 66 | } 67 | sleep(1); 68 | 69 | //Cancel an Order 70 | try { 71 | $result=$huobi->trade()->postCancel([ 72 | 'order_id'=>$result['data'][0]['order_id'],//You can also 'xxxx,xxxx,xxxx' multiple ID 73 | //'client_order_id'=>'xxxx', 74 | 'contract_code'=>'ETH-USD' 75 | ]); 76 | print_r($result); 77 | }catch (\Exception $e){ 78 | print_r(json_decode($e->getMessage(),true)); 79 | } 80 | sleep(1); 81 | -------------------------------------------------------------------------------- /tests/websocket/client_future.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * Fill in your key and secret and pass can be directly run 8 | * 9 | * Most of them are unfinished and need your help 10 | * https://github.com/zhouaini528/okex-php.git 11 | * */ 12 | use \Lin\Huobi\HuobiWebSocket; 13 | 14 | require __DIR__ .'../../../vendor/autoload.php'; 15 | 16 | include 'key_secret.php'; 17 | 18 | $huobi=new HuobiWebSocket(); 19 | 20 | $huobi->config([ 21 | //Do you want to enable local logging,default false 22 | //'log'=>true, 23 | //Or set the log name 24 | 'log'=>['filename'=>'future'], 25 | 26 | //Daemons address and port,default 0.0.0.0:2211 27 | //'global'=>'127.0.0.1:2211', 28 | 29 | //Channel data update time,default 0.5 seconds 30 | //'data_time'=>0.5, 31 | 32 | //Set up subscription platform, default 'spot' 33 | 'platform'=>'future', //options value 'spot' 'future' 'swap' 'linear' 'option' 34 | //Or you can set it like this 35 | /* 36 | 'platform'=>[ 37 | 'type'=>'future', 38 | 'market'=>'ws://api.hbdm.com/ws',//Market Data Request and Subscription 39 | 'order'=>'ws://api.hbdm.com/notification',//Order Push Subscription 40 | 'kline'=>'ws://api.hbdm.com/ws_index',//Index Kline Data and Basis Data Subscription 41 | 42 | //'market'=>'ws://api.btcgateway.pro/ws', 43 | //'order'=>'ws://api.btcgateway.pro/notification', 44 | //'kline'=>'ws://api.btcgateway.pro/ws_index', 45 | ], 46 | */ 47 | ]); 48 | 49 | $action=intval($_GET['action'] ?? 0);//http pattern 50 | if(empty($action)) $action=intval($argv[1]);//cli pattern 51 | 52 | switch ($action){ 53 | //**************public 54 | //subscribe 55 | case 1:{ 56 | $huobi->subscribe([ 57 | //market 58 | 'market.BTC_CQ.depth.step0', 59 | 'market.ETH_CQ.depth.step0', 60 | //kline 61 | 'market.BTC-USD.index.1min', 62 | 'market.BTC_CQ.basis.1min.open', 63 | ]); 64 | break; 65 | } 66 | 67 | //unsubscribe 68 | case 2:{ 69 | $huobi->unsubscribe([ 70 | //market 71 | 'market.BTC_CQ.depth.step0', 72 | 'market.ETH_CQ.depth.step0', 73 | //kline 74 | 'market.BTC-USD.index.1min', 75 | 'market.BTC_CQ.basis.1min.open', 76 | ]); 77 | 78 | break; 79 | } 80 | 81 | case 3:{ 82 | 83 | $huobi->subscribe([ 84 | //market 85 | 'market.BTC_CQ.kline.1min', 86 | 'market.BTC_CQ.bbo', 87 | 'market.BTC_CQ.trade.detail', 88 | 'market.BTC_CQ.detail', 89 | ]); 90 | 91 | break; 92 | } 93 | 94 | case 4:{ 95 | $huobi->unsubscribe([ 96 | //market 97 | 'market.BTC_CQ.kline.1min', 98 | 'market.BTC_CQ.bbo', 99 | 'market.BTC_CQ.trade.detail', 100 | 'market.BTC_CQ.detail', 101 | ]); 102 | 103 | break; 104 | } 105 | 106 | //**************private 107 | //subscribe 108 | case 10:{ 109 | /* 110 | $huobi->keysecret([ 111 | 'key'=>'xxxxxxxxx', 112 | 'secret'=>'xxxxxxxxx', 113 | ]); 114 | */ 115 | 116 | $huobi->keysecret($key_secret[0]); 117 | $huobi->subscribe([ 118 | //market 119 | 'market.BTC_CQ.depth.step0', 120 | 'market.ETH_CQ.depth.step0', 121 | 122 | //kline 123 | 'market.BTC-USD.index.1min', 124 | 'market.BTC_CQ.basis.1min.open', 125 | 126 | //private 127 | 'orders.eos', 128 | 'accounts.eos', 129 | 'positions.eos', 130 | 'trigger_order.eos', 131 | 132 | 'public.btc.liquidation_orders', 133 | 'public.btc.contract_info', 134 | ]); 135 | 136 | break; 137 | } 138 | 139 | //unsubscribe 140 | case 11:{ 141 | $huobi->keysecret($key_secret[0]); 142 | 143 | $huobi->unsubscribe([ 144 | //market 145 | 'market.BTC_CQ.depth.step0', 146 | 'market.ETH_CQ.depth.step0', 147 | 148 | //kline 149 | 'market.BTC-USD.index.1min', 150 | 'market.BTC_CQ.basis.1min.open', 151 | 152 | //private 153 | 'orders.eos', 154 | 'accounts.eos', 155 | 'positions.eos', 156 | 'trigger_order.eos', 157 | 158 | 'public.btc.liquidation_orders', 159 | 'public.btc.contract_info', 160 | ]); 161 | 162 | break; 163 | } 164 | 165 | case 20:{ 166 | //****Three ways to get all data 167 | 168 | //The first way 169 | $data=$huobi->getSubscribes(); 170 | print_r(json_encode($data)); 171 | die; 172 | //The second way callback 173 | $huobi->getSubscribes(function($data){ 174 | print_r(json_encode($data)); 175 | }); 176 | 177 | //The third way is to guard the process 178 | $huobi->getSubscribes(function($data){ 179 | print_r(json_encode($data)); 180 | },true); 181 | 182 | break; 183 | } 184 | 185 | case 21:{ 186 | //****Three ways return to the specified channel data 187 | 188 | //The first way 189 | $data=$huobi->getSubscribe([ 190 | 'market.BTC_CQ.depth.step0', 191 | 'market.ETH_CQ.depth.step0', 192 | ]); 193 | print_r($data); 194 | 195 | //The second way callback 196 | $huobi->getSubscribe([ 197 | 'market.BTC_CQ.depth.step0', 198 | 'market.ETH_CQ.depth.step0', 199 | ],function($data){ 200 | print_r(json_encode($data)); 201 | }); 202 | 203 | //The third way is to guard the process 204 | $huobi->getSubscribe([ 205 | 'market.BTC_CQ.depth.step0', 206 | 'market.ETH_CQ.depth.step0', 207 | ],function($data){ 208 | print_r(json_encode($data)); 209 | },true); 210 | 211 | break; 212 | } 213 | 214 | case 22:{ 215 | //****Three ways return to the specified channel data,All private data is also returned by default 216 | 217 | //The first way 218 | $huobi->keysecret($key_secret[0]); 219 | $data=$huobi->getSubscribe([ 220 | 'market.BTC_CQ.depth.step0', 221 | //'market.ETH_CQ.depth.step0', 222 | 223 | 'orders.eos', 224 | 'accounts.eos', 225 | 'positions.eos', 226 | //'trigger_order.eos', 227 | ]); 228 | print_r(json_encode($data)); 229 | //die; 230 | //The second way callback 231 | $huobi->keysecret($key_secret[0]); 232 | $huobi->getSubscribe([ 233 | 'market.BTC_CQ.depth.step0', 234 | //'market.ETH_CQ.depth.step0', 235 | 236 | 'orders.eos', 237 | 'accounts.eos', 238 | 'positions.eos', 239 | //'trigger_order.eos', 240 | ],function($data){ 241 | print_r(json_encode($data)); 242 | }); 243 | 244 | //The third way is to guard the process 245 | $huobi->keysecret($key_secret[0]); 246 | $huobi->getSubscribe([ 247 | 'market.BTC_CQ.depth.step0', 248 | //'market.ETH_CQ.depth.step0', 249 | 250 | 'orders.eos', 251 | 'accounts.eos', 252 | 'positions.eos', 253 | //'trigger_order.eos', 254 | ],function($data){ 255 | print_r(json_encode($data)); 256 | },true); 257 | 258 | break; 259 | } 260 | 261 | case 99:{ 262 | $huobi->client()->test(); 263 | break; 264 | } 265 | 266 | case 10004:{ 267 | $huobi->client()->test2(); 268 | break; 269 | } 270 | 271 | case 10005:{ 272 | $huobi->client()->test_reconnection(); 273 | break; 274 | } 275 | } 276 | 277 | 278 | -------------------------------------------------------------------------------- /tests/websocket/client_linear.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * Fill in your key and secret and pass can be directly run 8 | * 9 | * Most of them are unfinished and need your help 10 | * https://github.com/zhouaini528/okex-php.git 11 | * */ 12 | use \Lin\Huobi\HuobiWebSocket; 13 | 14 | require __DIR__ .'../../../vendor/autoload.php'; 15 | 16 | include 'key_secret.php'; 17 | 18 | $huobi=new HuobiWebSocket(); 19 | 20 | $huobi->config([ 21 | //Do you want to enable local logging,default false 22 | //'log'=>true, 23 | //Or set the log name 24 | 'log'=>['filename'=>'linear'], 25 | 26 | //Daemons address and port,default 0.0.0.0:2211 27 | //'global'=>'127.0.0.1:2211', 28 | 29 | //Channel data update time,default 0.5 seconds 30 | //'data_time'=>0.5, 31 | 32 | //Set up subscription platform, default 'spot' 33 | 'platform'=>'linear', //options value 'spot' 'future' 'swap' 'linear' 'option' 34 | //Or you can set it like this 35 | /* 36 | 'platform'=>[ 37 | 'type'=>'swap', 38 | 'market'=>'ws://api.hbdm.com/linear-swap-ws',//Market Data Request and Subscription 39 | 'order'=>'ws://api.hbdm.com/linear-swap-notification',//Order Push Subscription 40 | 'kline'=>'ws://api.hbdm.com/ws_index',//Index Kline Data and Basis Data Subscription 41 | 42 | //'market'=>'ws://api.btcgateway.pro/linear-swap-ws', 43 | //'order'=>'ws://api.btcgateway.pro/linear-swap-notification', 44 | //'kline'=>'ws://api.btcgateway.pro/ws_index', 45 | ], 46 | */ 47 | ]); 48 | 49 | $action=intval($_GET['action'] ?? 0);//http pattern 50 | if(empty($action)) $action=intval($argv[1]);//cli pattern 51 | 52 | switch ($action){ 53 | //**************public 54 | //subscribe 55 | case 1:{ 56 | $huobi->subscribe([ 57 | //market 58 | 'market.BTC-USDT.depth.step0', 59 | 'market.ETH-USDT.depth.step0', 60 | 61 | //kline index and basis 62 | 'market.BTC-USDT.premium_index.1min', 63 | 'market.btc-USDT.estimated_rate.1min', 64 | 'market.BTC-USDT.basis.1min.open', 65 | ]); 66 | break; 67 | } 68 | 69 | //unsubscribe 70 | case 2:{ 71 | $huobi->unsubscribe([ 72 | //market 73 | 'market.BTC-USDT.depth.step0', 74 | 'market.ETH-USDT.depth.step0', 75 | 76 | //kline index and basis 77 | 'market.BTC-USDT.premium_index.1min', 78 | 'market.btc-USDT.estimated_rate.1min', 79 | 'market.BTC-USDT.basis.1min.open', 80 | ]); 81 | 82 | break; 83 | } 84 | 85 | case 3:{ 86 | 87 | $huobi->subscribe([ 88 | //market 89 | 'market.BTC-USDT.kline.1min', 90 | 'market.BTC-USDT.bbo', 91 | 'market.BTC-USDT.trade.detail', 92 | 'market.BTC-USDT.detail', 93 | ]); 94 | 95 | break; 96 | } 97 | 98 | case 4:{ 99 | $huobi->unsubscribe([ 100 | //market 101 | 'market.BTC-USDT.kline.1min', 102 | 'market.BTC-USDT.bbo', 103 | 'market.BTC-USDT.trade.detail', 104 | 'market.BTC-USDT.detail', 105 | ]); 106 | 107 | break; 108 | } 109 | 110 | //**************private 111 | //subscribe 112 | case 10:{ 113 | /* 114 | $huobi->keysecret([ 115 | 'key'=>'xxxxxxxxx', 116 | 'secret'=>'xxxxxxxxx', 117 | ]); 118 | */ 119 | 120 | $huobi->keysecret($key_secret[0]); 121 | $huobi->subscribe([ 122 | //market 123 | 'market.BTC-USDT.depth.step0', 124 | 'market.ETH-USDT.depth.step0', 125 | 126 | //kline index and basis 127 | 'market.BTC-USDT.premium_index.1min', 128 | 'market.btc-USDT.estimated_rate.1min', 129 | 'market.BTC-USDT.basis.1min.open', 130 | 131 | //private 132 | 'orders.eos-USDT', 133 | 'accounts.eos-USDT', 134 | 'positions.eos-USDT', 135 | 'trigger_order.eos-USDT', 136 | 137 | 'public.btc-USDT.liquidation_orders', 138 | 'public.btc-USDT.contract_info', 139 | 'public.btc-USDT.funding_rate', 140 | ]); 141 | 142 | break; 143 | } 144 | 145 | //unsubscribe 146 | case 11:{ 147 | $huobi->keysecret($key_secret[0]); 148 | 149 | $huobi->unsubscribe([ 150 | //market 151 | 'market.BTC-USDT.depth.step0', 152 | 'market.ETH-USDT.depth.step0', 153 | 154 | //kline index and basis 155 | 'market.BTC-USDT.premium_index.1min', 156 | 'market.btc-USDT.estimated_rate.1min', 157 | 'market.BTC-USDT.basis.1min.open', 158 | 159 | //private 160 | 'orders.eos-USDT', 161 | 'accounts.eos-USDT', 162 | 'positions.eos-USDT', 163 | 'trigger_order.eos-USDT', 164 | 165 | 'public.btc-USDT.liquidation_orders', 166 | 'public.btc-USDT.contract_info', 167 | 'public.btc-USDT.funding_rate', 168 | ]); 169 | 170 | break; 171 | } 172 | 173 | case 20:{ 174 | //****Three ways to get all data 175 | 176 | //The first way 177 | $data=$huobi->getSubscribes(); 178 | print_r(json_encode($data)); 179 | die; 180 | //The second way callback 181 | $huobi->getSubscribes(function($data){ 182 | print_r(json_encode($data)); 183 | }); 184 | 185 | //The third way is to guard the process 186 | $huobi->getSubscribes(function($data){ 187 | print_r(json_encode($data)); 188 | },true); 189 | 190 | break; 191 | } 192 | 193 | case 21:{ 194 | //****Three ways return to the specified channel data 195 | 196 | //The first way 197 | $data=$huobi->getSubscribe([ 198 | 'market.BTC-USDT.depth.step0', 199 | 'market.ETH-USDT.depth.step0', 200 | ]); 201 | print_r($data); 202 | 203 | //The second way callback 204 | $huobi->getSubscribe([ 205 | 'market.BTC-USDT.depth.step0', 206 | 'market.ETH-USDT.depth.step0', 207 | ],function($data){ 208 | print_r(json_encode($data)); 209 | }); 210 | 211 | //The third way is to guard the process 212 | $huobi->getSubscribe([ 213 | 'market.BTC-USDT.depth.step0', 214 | 'market.ETH-USDT.depth.step0', 215 | ],function($data){ 216 | print_r(json_encode($data)); 217 | },true); 218 | 219 | break; 220 | } 221 | 222 | case 22:{ 223 | //****Three ways return to the specified channel data,All private data is also returned by default 224 | 225 | //The first way 226 | $huobi->keysecret($key_secret[0]); 227 | $data=$huobi->getSubscribe([ 228 | 'market.BTC-USDT.depth.step0', 229 | //'market.ETH-USDT.depth.step0', 230 | 231 | 'orders.eos', 232 | 'accounts.eos', 233 | 'positions.eos', 234 | //'trigger_order.eos', 235 | ]); 236 | print_r(json_encode($data)); 237 | 238 | //The second way callback 239 | $huobi->keysecret($key_secret[0]); 240 | $huobi->getSubscribe([ 241 | 'market.BTC-USDT.depth.step0', 242 | //'market.ETH-USDT.depth.step0', 243 | 244 | 'orders.eos', 245 | 'accounts.eos', 246 | 'positions.eos', 247 | //'trigger_order.eos', 248 | ],function($data){ 249 | print_r(json_encode($data)); 250 | }); 251 | 252 | //The third way is to guard the process 253 | $huobi->keysecret($key_secret[0]); 254 | $huobi->getSubscribe([ 255 | 'market.BTC-USDT.depth.step0', 256 | //'market.ETH-USDT.depth.step0', 257 | 258 | 'orders.eos', 259 | 'accounts.eos', 260 | 'positions.eos', 261 | //'trigger_order.eos', 262 | ],function($data){ 263 | print_r(json_encode($data)); 264 | },true); 265 | 266 | break; 267 | } 268 | 269 | case 99:{ 270 | $huobi->client()->test(); 271 | break; 272 | } 273 | 274 | case 10004:{ 275 | $huobi->client()->test2(); 276 | break; 277 | } 278 | 279 | case 10005:{ 280 | $huobi->keysecret($key_secret[1]); 281 | $huobi->subscribe(); 282 | break; 283 | } 284 | 285 | //subscribe 286 | case 10006:{ 287 | $huobi->keysecret($key_secret[0]); 288 | $huobi->subscribe(); 289 | break; 290 | } 291 | } 292 | 293 | 294 | -------------------------------------------------------------------------------- /tests/websocket/client_spot.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * Fill in your key and secret and pass can be directly run 8 | * 9 | * Most of them are unfinished and need your help 10 | * https://github.com/zhouaini528/okex-php.git 11 | * */ 12 | use \Lin\Huobi\HuobiWebSocket; 13 | 14 | require __DIR__ .'../../../vendor/autoload.php'; 15 | 16 | include 'key_secret.php'; 17 | 18 | $huobi=new HuobiWebSocket(); 19 | 20 | $huobi->config([ 21 | //Do you want to enable local logging,default false 22 | //'log'=>true, 23 | //Or set the log name 24 | 'log'=>['filename'=>'spot'], 25 | 26 | //Daemons address and port,default 0.0.0.0:2211 27 | //'global'=>'127.0.0.1:2211', 28 | 29 | //Channel subscription monitoring time,2 seconds 30 | //'listen_time'=>2, 31 | 32 | //Channel data update time,0.1 seconds 33 | //'data_time'=>0.1, 34 | 35 | //Set up subscription platform, default 'spot' 36 | 'platform'=>'spot', //options value 'spot' 'future' 'swap' 'linear' 'option' 37 | //Or you can set it like this 38 | /* 39 | 'platform'=>[ 40 | 'type'=>'spot', 41 | 'market'=>'ws://api.huobi.pro/ws',//Market Data Request and Subscription 42 | 'order'=>'ws://api.huobi.pro/ws/v2',//Order Push Subscription 43 | 44 | //'market'=>'ws://api-aws.huobi.pro/ws', 45 | //'order'=>'ws://api-aws.huobi.pro/ws/v2', 46 | ], 47 | */ 48 | ]); 49 | 50 | $action=intval($_GET['action'] ?? 0);//http pattern 51 | if(empty($action)) $action=intval($argv[1]);//cli pattern 52 | 53 | switch ($action){ 54 | //**************public 55 | //subscribe 56 | case 1:{ 57 | $huobi->subscribe([ 58 | 'market.btcusdt.depth.step0', 59 | 'market.bchusdt.depth.step0', 60 | ]); 61 | break; 62 | } 63 | 64 | //unsubscribe 65 | case 2:{ 66 | $huobi->unsubscribe([ 67 | 'market.btcusdt.depth.step0', 68 | 'market.bchusdt.depth.step0', 69 | ]); 70 | 71 | break; 72 | } 73 | 74 | case 3:{ 75 | 76 | $huobi->subscribe([ 77 | 'market.btcusdt.kline.1min', 78 | 'market.btcusdt.bbo', 79 | 'market.btcusdt.trade.detail', 80 | 'market.btcusdt.detail', 81 | 'market.btcusdt.etp', 82 | ]); 83 | 84 | break; 85 | } 86 | 87 | case 4:{ 88 | $huobi->unsubscribe([ 89 | 'market.btcusdt.kline.1min', 90 | 'market.btcusdt.bbo', 91 | 'market.btcusdt.trade.detail', 92 | 'market.btcusdt.detail', 93 | 'market.btcusdt.etp', 94 | ]); 95 | 96 | break; 97 | } 98 | 99 | //**************private 100 | //subscribe 101 | case 10:{ 102 | /* 103 | $huobi->keysecret([ 104 | 'key'=>'xxxxxxxxx', 105 | 'secret'=>'xxxxxxxxx', 106 | ]); 107 | */ 108 | $huobi->keysecret($key_secret[0]); 109 | $huobi->subscribe([ 110 | //market 111 | 'market.btcusdt.depth.step0', 112 | 'market.bchusdt.depth.step0', 113 | 114 | //private 115 | 'orders#btcusdt', 116 | 'trade.clearing#btcusdt#1', 117 | 'accounts.update#1', 118 | ]); 119 | 120 | break; 121 | } 122 | 123 | //unsubscribe 124 | case 11:{ 125 | $huobi->keysecret($key_secret[0]); 126 | 127 | $huobi->unsubscribe([ 128 | //market 129 | 'market.btcusdt.depth.step0', 130 | 'market.bchusdt.depth.step0', 131 | 132 | //private 133 | 'orders#btcusdt', 134 | 'trade.clearing#btcusdt#1', 135 | 'accounts.update#1', 136 | ]); 137 | 138 | break; 139 | } 140 | 141 | 142 | 143 | case 20:{ 144 | //****Three ways to get all data 145 | 146 | //The first way 147 | $huobi->keysecret($key_secret[0]); 148 | $data=$huobi->getSubscribes(); 149 | print_r(json_encode($data)); 150 | die; 151 | //The second way callback 152 | $huobi->getSubscribes(function($data){ 153 | print_r(json_encode($data)); 154 | }); 155 | 156 | //The third way is to guard the process 157 | $huobi->getSubscribes(function($data){ 158 | print_r(json_encode($data)); 159 | },true); 160 | 161 | break; 162 | } 163 | 164 | case 21:{ 165 | //****Three ways return to the specified channel data 166 | 167 | //The first way 168 | $data=$huobi->getSubscribe([ 169 | 'market.btcusdt.depth.step0', 170 | 'market.bchusdt.depth.step0', 171 | ]); 172 | 173 | //The second way callback 174 | $huobi->getSubscribe([ 175 | 'market.btcusdt.depth.step0', 176 | 'market.bchusdt.depth.step0', 177 | ],function($data){ 178 | print_r(json_encode($data)); 179 | }); 180 | 181 | //The third way is to guard the process 182 | $huobi->getSubscribe([ 183 | 'market.btcusdt.depth.step0', 184 | 'market.bchusdt.depth.step0', 185 | ],function($data){ 186 | print_r(json_encode($data)); 187 | },true); 188 | 189 | break; 190 | } 191 | 192 | case 22:{ 193 | //****Three ways return to the specified channel data,All private data is also returned by default 194 | 195 | //The first way 196 | $huobi->keysecret($key_secret[0]); 197 | $data=$huobi->getSubscribe([ 198 | 'market.btcusdt.depth.step0', 199 | 'market.bchusdt.depth.step0', 200 | ]); 201 | print_r(json_encode($data)); 202 | 203 | //The second way callback 204 | $huobi->keysecret($key_secret[0]); 205 | $huobi->getSubscribe([ 206 | 'market.btcusdt.depth.step0', 207 | 'market.bchusdt.depth.step0', 208 | ],function($data){ 209 | print_r(json_encode($data)); 210 | }); 211 | 212 | //The third way is to guard the process 213 | $huobi->keysecret($key_secret[0]); 214 | $huobi->getSubscribe([ 215 | 'market.btcusdt.depth.step0', 216 | 'market.bchusdt.depth.step0', 217 | ],function($data){ 218 | print_r(json_encode($data)); 219 | },true); 220 | 221 | break; 222 | } 223 | 224 | case 99:{ 225 | $huobi->client()->test(); 226 | break; 227 | } 228 | 229 | case 10004:{ 230 | $huobi->client()->test2(); 231 | break; 232 | } 233 | 234 | case 10005:{ 235 | $huobi->client()->test_reconnection(); 236 | break; 237 | } 238 | 239 | case 10006:{ 240 | $huobi->client()->test_reconnection2(); 241 | break; 242 | } 243 | } 244 | 245 | 246 | -------------------------------------------------------------------------------- /tests/websocket/client_swap.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * Fill in your key and secret and pass can be directly run 8 | * 9 | * Most of them are unfinished and need your help 10 | * https://github.com/zhouaini528/okex-php.git 11 | * */ 12 | use \Lin\Huobi\HuobiWebSocket; 13 | 14 | require __DIR__ .'../../../vendor/autoload.php'; 15 | 16 | include 'key_secret.php'; 17 | 18 | $huobi=new HuobiWebSocket(); 19 | 20 | $huobi->config([ 21 | //Do you want to enable local logging,default false 22 | //'log'=>true, 23 | //Or set the log name 24 | 'log'=>['filename'=>'swap'], 25 | 26 | //Daemons address and port,default 0.0.0.0:2211 27 | //'global'=>'127.0.0.1:2211', 28 | 29 | //Channel data update time,default 0.5 seconds 30 | //'data_time'=>0.5, 31 | 32 | //Set up subscription platform, default 'spot' 33 | 'platform'=>'swap', //options value 'spot' 'future' 'swap' 'linear' 'option' 34 | //Or you can set it like this 35 | /* 36 | 'platform'=>[ 37 | 'type'=>'swap', 38 | 'market'=>'ws://api.hbdm.com/swap-ws',//Market Data Request and Subscription 39 | 'order'=>'ws://api.hbdm.com/swap-notification',//Order Push Subscription 40 | 'kline'=>'ws://api.hbdm.com/ws_index',//Index Kline Data and Basis Data Subscription 41 | 42 | //'market'=>'ws://api.btcgateway.pro/swap-ws', 43 | //'order'=>'ws://api.btcgateway.pro/swap-notification', 44 | //'kline'=>'ws://api.btcgateway.pro/ws_index', 45 | ], 46 | */ 47 | ]); 48 | 49 | $action=intval($_GET['action'] ?? 0);//http pattern 50 | if(empty($action)) $action=intval($argv[1]);//cli pattern 51 | 52 | switch ($action){ 53 | //**************public 54 | //subscribe 55 | case 1:{ 56 | $huobi->subscribe([ 57 | //market 58 | 'market.BTC-USD.depth.step0', 59 | 'market.ETH-USD.depth.step0', 60 | 61 | //kline index and basis 62 | 'market.BTC-USD.premium_index.1min', 63 | 'market.btc-USD.estimated_rate.1min', 64 | 'market.BTC-USD.basis.1min.open', 65 | ]); 66 | break; 67 | } 68 | 69 | //unsubscribe 70 | case 2:{ 71 | $huobi->unsubscribe([ 72 | //market 73 | 'market.BTC-USD.depth.step0', 74 | 'market.ETH-USD.depth.step0', 75 | 76 | //kline index and basis 77 | 'market.BTC-USD.premium_index.1min', 78 | 'market.btc-USD.estimated_rate.1min', 79 | 'market.BTC-USD.basis.1min.open', 80 | ]); 81 | 82 | break; 83 | } 84 | 85 | case 3:{ 86 | 87 | $huobi->subscribe([ 88 | //market 89 | 'market.BTC-USD.kline.1min', 90 | 'market.BTC-USD.bbo', 91 | 'market.BTC-USD.trade.detail', 92 | 'market.BTC-USD.detail', 93 | ]); 94 | 95 | break; 96 | } 97 | 98 | case 4:{ 99 | $huobi->unsubscribe([ 100 | //market 101 | 'market.BTC-USD.kline.1min', 102 | 'market.BTC-USD.bbo', 103 | 'market.BTC-USD.trade.detail', 104 | 'market.BTC-USD.detail', 105 | ]); 106 | 107 | break; 108 | } 109 | 110 | //**************private 111 | //subscribe 112 | case 10:{ 113 | /* 114 | $huobi->keysecret([ 115 | 'key'=>'xxxxxxxxx', 116 | 'secret'=>'xxxxxxxxx', 117 | ]); 118 | */ 119 | 120 | $huobi->keysecret($key_secret[0]); 121 | $huobi->subscribe([ 122 | //market 123 | 'market.BTC-USD.depth.step0', 124 | 'market.ETH-USD.depth.step0', 125 | 126 | //kline index and basis 127 | 'market.BTC-USD.premium_index.1min', 128 | 'market.btc-USD.estimated_rate.1min', 129 | 'market.BTC-USD.basis.1min.open', 130 | 131 | //private 132 | 'orders.eos-usd', 133 | 'accounts.eos-usd', 134 | 'positions.eos-usd', 135 | 'trigger_order.eos-usd', 136 | 137 | 'public.btc-usd.liquidation_orders', 138 | 'public.btc-usd.contract_info', 139 | 'public.btc-usd.funding_rate', 140 | ]); 141 | 142 | break; 143 | } 144 | 145 | //unsubscribe 146 | case 11:{ 147 | $huobi->keysecret($key_secret[0]); 148 | 149 | $huobi->unsubscribe([ 150 | //market 151 | 'market.BTC-USD.depth.step0', 152 | 'market.ETH-USD.depth.step0', 153 | 154 | //kline index and basis 155 | 'market.BTC-USD.premium_index.1min', 156 | 'market.btc-USD.estimated_rate.1min', 157 | 'market.BTC-USD.basis.1min.open', 158 | 159 | //private 160 | 'orders.eos-usd', 161 | 'accounts.eos-usd', 162 | 'positions.eos-usd', 163 | 'trigger_order.eos-usd', 164 | 165 | 'public.btc-usd.liquidation_orders', 166 | 'public.btc-usd.contract_info', 167 | 'public.btc-usd.funding_rate', 168 | ]); 169 | 170 | break; 171 | } 172 | 173 | case 20:{ 174 | //****Three ways to get all data 175 | 176 | //The first way 177 | $data=$huobi->getSubscribes(); 178 | print_r(json_encode($data)); 179 | die; 180 | //The second way callback 181 | $huobi->getSubscribes(function($data){ 182 | print_r(json_encode($data)); 183 | }); 184 | 185 | //The third way is to guard the process 186 | $huobi->getSubscribes(function($data){ 187 | print_r(json_encode($data)); 188 | },true); 189 | 190 | break; 191 | } 192 | 193 | case 21:{ 194 | //****Three ways return to the specified channel data 195 | 196 | //The first way 197 | $data=$huobi->getSubscribe([ 198 | 'market.BTC-USD.depth.step0', 199 | 'market.ETH-USD.depth.step0', 200 | ]); 201 | print_r($data); 202 | 203 | //The second way callback 204 | $huobi->getSubscribe([ 205 | 'market.BTC-USD.depth.step0', 206 | 'market.ETH-USD.depth.step0', 207 | ],function($data){ 208 | print_r(json_encode($data)); 209 | }); 210 | 211 | //The third way is to guard the process 212 | $huobi->getSubscribe([ 213 | 'market.BTC-USD.depth.step0', 214 | 'market.ETH-USD.depth.step0', 215 | ],function($data){ 216 | print_r(json_encode($data)); 217 | },true); 218 | 219 | break; 220 | } 221 | 222 | case 22:{ 223 | //****Three ways return to the specified channel data,All private data is also returned by default 224 | 225 | //The first way 226 | $huobi->keysecret($key_secret[0]); 227 | $data=$huobi->getSubscribe([ 228 | 'market.BTC-USD.depth.step0', 229 | //'market.ETH-USD.depth.step0', 230 | 231 | 'orders.eos', 232 | 'accounts.eos', 233 | 'positions.eos', 234 | //'trigger_order.eos', 235 | ]); 236 | print_r(json_encode($data)); 237 | 238 | //The second way callback 239 | $huobi->keysecret($key_secret[0]); 240 | $huobi->getSubscribe([ 241 | 'market.BTC-USD.depth.step0', 242 | //'market.ETH-USD.depth.step0', 243 | 244 | 'orders.eos', 245 | 'accounts.eos', 246 | 'positions.eos', 247 | //'trigger_order.eos', 248 | ],function($data){ 249 | print_r(json_encode($data)); 250 | }); 251 | 252 | //The third way is to guard the process 253 | $huobi->keysecret($key_secret[0]); 254 | $huobi->getSubscribe([ 255 | 'market.BTC-USD.depth.step0', 256 | //'market.ETH-USD.depth.step0', 257 | 258 | 'orders.eos', 259 | 'accounts.eos', 260 | 'positions.eos', 261 | //'trigger_order.eos', 262 | ],function($data){ 263 | print_r(json_encode($data)); 264 | },true); 265 | 266 | break; 267 | } 268 | 269 | case 99:{ 270 | $huobi->client()->test(); 271 | break; 272 | } 273 | 274 | case 10004:{ 275 | $huobi->client()->test2(); 276 | break; 277 | } 278 | 279 | case 10005:{ 280 | $huobi->keysecret($key_secret[1]); 281 | $huobi->subscribe(); 282 | break; 283 | } 284 | 285 | //subscribe 286 | case 10006:{ 287 | $huobi->keysecret($key_secret[0]); 288 | $huobi->subscribe(); 289 | break; 290 | } 291 | } 292 | 293 | 294 | -------------------------------------------------------------------------------- /tests/websocket/server_future.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * Fill in your key and secret and pass can be directly run 8 | * 9 | * Most of them are unfinished and need your help 10 | * https://github.com/zhouaini528/okex-php.git 11 | * */ 12 | use \Lin\Huobi\HuobiWebSocket; 13 | 14 | require __DIR__ .'../../../vendor/autoload.php'; 15 | 16 | $Huobi=new HuobiWebSocket(); 17 | 18 | $Huobi->config([ 19 | //Do you want to enable local logging,default false 20 | //'log'=>true, 21 | //Or set the log name 22 | 'log'=>['filename'=>'future'], 23 | 24 | //Daemons address and port,default 0.0.0.0:2211 25 | //'global'=>'127.0.0.1:2211', 26 | 27 | //Channel data update time,default 0.5 seconds 28 | //'data_time'=>0.5, 29 | 30 | //Set up subscription platform, default 'spot' 31 | 'platform'=>'future', //options value 'spot' 'future' 'swap' 'linear' 'option' 32 | //Or you can set it like this 33 | /* 34 | 'platform'=>[ 35 | 'type'=>'future', 36 | 'market'=>'ws://api.hbdm.com/ws',//Market Data Request and Subscription 37 | 'order'=>'ws://api.hbdm.com/notification',//Order Push Subscription 38 | 'kline'=>'ws://api.hbdm.com/ws_index',//Index Kline Data and Basis Data Subscription 39 | 40 | //'market'=>'ws://api.btcgateway.pro/ws', 41 | //'order'=>'ws://api.btcgateway.pro/notification', 42 | //'kline'=>'ws://api.btcgateway.pro/ws_index', 43 | ], 44 | */ 45 | ]); 46 | 47 | $Huobi->start(); 48 | 49 | -------------------------------------------------------------------------------- /tests/websocket/server_linear.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * Fill in your key and secret and pass can be directly run 8 | * 9 | * Most of them are unfinished and need your help 10 | * https://github.com/zhouaini528/okex-php.git 11 | * */ 12 | use \Lin\Huobi\HuobiWebSocket; 13 | 14 | require __DIR__ .'../../../vendor/autoload.php'; 15 | 16 | $Huobi=new HuobiWebSocket(); 17 | 18 | $Huobi->config([ 19 | //Do you want to enable local logging,default false 20 | //'log'=>true, 21 | //Or set the log name 22 | 'log'=>['filename'=>'linear'], 23 | 24 | //Daemons address and port,default 0.0.0.0:2211 25 | //'global'=>'127.0.0.1:2211', 26 | 27 | //Channel data update time,default 0.5 seconds 28 | //'data_time'=>0.5, 29 | 30 | //Set up subscription platform, default 'spot' 31 | 'platform'=>'linear', //options value 'spot' 'future' 'swap' 'linear' 'option' 32 | //Or you can set it like this 33 | /* 34 | 'platform'=>[ 35 | 'type'=>'swap', 36 | 'market'=>'ws://api.hbdm.com/linear-swap-ws',//Market Data Request and Subscription 37 | 'order'=>'ws://api.hbdm.com/linear-swap-notification',//Order Push Subscription 38 | 'kline'=>'ws://api.hbdm.com/ws_index',//Index Kline Data and Basis Data Subscription 39 | 40 | //'market'=>'ws://api.btcgateway.pro/linear-swap-ws', 41 | //'order'=>'ws://api.btcgateway.pro/linear-swap-notification', 42 | //'kline'=>'ws://api.btcgateway.pro/ws_index', 43 | ], 44 | */ 45 | ]); 46 | 47 | $Huobi->start(); 48 | 49 | -------------------------------------------------------------------------------- /tests/websocket/server_spot.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * Fill in your key and secret and pass can be directly run 8 | * 9 | * Most of them are unfinished and need your help 10 | * https://github.com/zhouaini528/okex-php.git 11 | * */ 12 | use \Lin\Huobi\HuobiWebSocket; 13 | 14 | require __DIR__ .'../../../vendor/autoload.php'; 15 | 16 | $Huobi=new HuobiWebSocket(); 17 | 18 | $Huobi->config([ 19 | //Do you want to enable local logging,default false 20 | //'log'=>true, 21 | //Or set the log name 22 | 'log'=>['filename'=>'spot'], 23 | 24 | //Daemons address and port,default 0.0.0.0:2211 25 | //'global'=>'127.0.0.1:2211', 26 | 27 | //Channel subscription monitoring time,2 seconds 28 | //'listen_time'=>2, 29 | 30 | //Channel data update time,default 0.5 seconds 31 | //'data_time'=>0.5, 32 | 33 | //Set up subscription platform, default 'spot' 34 | 'platform'=>'spot', //options value 'spot' 'future' 'swap' 'linear' 'option' 35 | //Or you can set it like this 36 | /* 37 | 'platform'=>[ 38 | 'type'=>'spot', 39 | 'market'=>'ws://api.huobi.pro/ws',//Market Data Request and Subscription 40 | 'order'=>'ws://api.huobi.pro/ws/v2',//Order Push Subscription 41 | 42 | //'market'=>'ws://api-aws.huobi.pro/ws', 43 | //'order'=>'ws://api-aws.huobi.pro/ws/v2', 44 | ], 45 | */ 46 | ]); 47 | 48 | $Huobi->start(); 49 | 50 | -------------------------------------------------------------------------------- /tests/websocket/server_swap.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * Fill in your key and secret and pass can be directly run 8 | * 9 | * Most of them are unfinished and need your help 10 | * https://github.com/zhouaini528/okex-php.git 11 | * */ 12 | use \Lin\Huobi\HuobiWebSocket; 13 | 14 | require __DIR__ .'../../../vendor/autoload.php'; 15 | 16 | $Huobi=new HuobiWebSocket(); 17 | 18 | $Huobi->config([ 19 | //Do you want to enable local logging,default false 20 | //'log'=>true, 21 | //Or set the log name 22 | 'log'=>['filename'=>'swap'], 23 | 24 | //Daemons address and port,default 0.0.0.0:2211 25 | //'global'=>'127.0.0.1:2211', 26 | 27 | //Channel data update time,default 0.5 seconds 28 | //'data_time'=>0.5, 29 | 30 | //Set up subscription platform, default 'spot' 31 | 'platform'=>'swap', //options value 'spot' 'future' 'swap' 'linear' 'option' 32 | //Or you can set it like this 33 | /* 34 | 'platform'=>[ 35 | 'type'=>'swap', 36 | 'market'=>'ws://api.hbdm.com/swap-ws',//Market Data Request and Subscription 37 | 'order'=>'ws://api.hbdm.com/swap-notification',//Order Push Subscription 38 | 'kline'=>'ws://api.hbdm.com/ws_index',//Index Kline Data and Basis Data Subscription 39 | 40 | //'market'=>'ws://api.btcgateway.pro/swap-ws', 41 | //'order'=>'ws://api.btcgateway.pro/swap-notification', 42 | //'kline'=>'ws://api.btcgateway.pro/ws_index', 43 | ], 44 | */ 45 | ]); 46 | 47 | $Huobi->start(); 48 | 49 | --------------------------------------------------------------------------------