├── LICENSE ├── README.md ├── README_CN.md ├── composer.json ├── src ├── Api │ ├── AccountV3 │ │ ├── Account.php │ │ ├── Currencies.php │ │ ├── Deposit.php │ │ ├── Ledger.php │ │ ├── Transfer.php │ │ ├── Wallet.php │ │ └── Withdrawal.php │ ├── EttV3 │ │ └── README.md │ ├── FuturesV3 │ │ ├── Accounts.php │ │ ├── Fills.php │ │ ├── Instruments.php │ │ ├── Orders.php │ │ └── Position.php │ ├── MarginV3 │ │ ├── Accounts.php │ │ ├── Fills.php │ │ └── Orders.php │ ├── OkexV5 │ │ ├── Account.php │ │ ├── Asset.php │ │ ├── Market.php │ │ ├── Publics.php │ │ ├── SubAccount.php │ │ ├── System.php │ │ └── Trade.php │ ├── OptionV3 │ │ ├── Accounts.php │ │ ├── Fills.php │ │ ├── Instruments.php │ │ ├── Orders.php │ │ └── Position.php │ ├── SpotV3 │ │ ├── Accounts.php │ │ ├── Fills.php │ │ ├── Instruments.php │ │ ├── Orders.php │ │ └── Trade.php │ ├── SwapV3 │ │ ├── Accounts.php │ │ ├── Fills.php │ │ ├── Instruments.php │ │ ├── Orders.php │ │ └── Position.php │ ├── WebSocketV3 │ │ ├── SocketClient.php │ │ ├── SocketFunction.php │ │ ├── SocketGlobal.php │ │ └── SocketServer.php │ └── WebSocketV5 │ │ ├── SocketClient.php │ │ ├── SocketFunction.php │ │ ├── SocketGlobal.php │ │ └── SocketServer.php ├── Exceptions │ └── Exception.php ├── OkexAccount.php ├── OkexFuture.php ├── OkexMargin.php ├── OkexOption.php ├── OkexSpot.php ├── OkexSwap.php ├── OkexV5.php ├── OkexWebSocket.php ├── OkexWebSocketV5.php └── Request.php └── tests ├── account_v3 ├── account.php ├── currencies.php ├── deposit.php ├── ledger.php ├── transfer.php ├── wallet.php └── withdrawal.php ├── future_v3 ├── accounts.php ├── instrument.php ├── order.php ├── position.php └── proxy.php ├── margin_v3 ├── accounts.php └── order.php ├── okex_v5 ├── account.php ├── asset.php ├── market.php ├── publics.php └── trade.php ├── spot_v3 ├── accounts.php ├── fills.php ├── instrument.php ├── order.php ├── proxy.php └── trade.php ├── swap_v3 ├── accounts.php ├── instrument.php ├── order.php ├── position.php └── proxy.php ├── websocket_v3 ├── client.php └── server.php └── websocket_v5 ├── client.php └── server.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 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "linwj/okex", 3 | "type": "library", 4 | "description": "Okex 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\\Okex\\": "./src/" 16 | } 17 | }, 18 | "require": { 19 | "php": ">=7.0", 20 | "guzzlehttp/guzzle": "*", 21 | "workerman/workerman": "*", 22 | "workerman/globaldata": "*" 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/Api/AccountV3/Account.php: -------------------------------------------------------------------------------- 1 | 4 | * */ 5 | 6 | namespace Lin\Okex\Api\AccountV3; 7 | 8 | use Lin\Okex\Request; 9 | 10 | class Account extends Request 11 | { 12 | /** 13 | * GET /api/account/v3/uid 14 | * */ 15 | public function getUid(array $data=[]){ 16 | $this->type='GET'; 17 | $this->path='/api/account/v3/uid'; 18 | $this->data=$data; 19 | return $this->exec(); 20 | } 21 | 22 | /** 23 | * POST/api/account/v3/purchase_redempt 24 | * */ 25 | public function postPurchaseRedempt(array $data=[]){ 26 | $this->type='POST'; 27 | $this->path='/api/account/v3/purchase_redempt'; 28 | $this->data=$data; 29 | return $this->exec(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/Api/AccountV3/Currencies.php: -------------------------------------------------------------------------------- 1 | 4 | * */ 5 | 6 | namespace Lin\Okex\Api\AccountV3; 7 | 8 | use Lin\Okex\Request; 9 | 10 | class Currencies extends Request 11 | { 12 | /** 13 | * GET /api/account/v3/currencies 14 | * */ 15 | public function get(array $data=[]){ 16 | $this->type='GET'; 17 | $this->path='/api/account/v3/currencies'; 18 | 19 | $this->data=$data; 20 | 21 | return $this->exec(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Api/AccountV3/Deposit.php: -------------------------------------------------------------------------------- 1 | 4 | * */ 5 | 6 | namespace Lin\Okex\Api\AccountV3; 7 | 8 | use Lin\Okex\Request; 9 | 10 | class Deposit extends Request 11 | { 12 | /** 13 | * GET /api/account/v3/deposit/address 14 | * */ 15 | public function getAddress(array $data=[]){ 16 | $this->type='GET'; 17 | $this->path='/api/account/v3/deposit/address'; 18 | 19 | $this->data=$data; 20 | 21 | return $this->exec(); 22 | } 23 | 24 | /** 25 | * GET /api/account/v3/deposit/history/ 26 | * */ 27 | public function getHistory(array $data=[]){ 28 | $this->type='GET'; 29 | $this->path='/api/account/v3/deposit/history/'.$data['currency']; 30 | 31 | $this->data=$data; 32 | 33 | return $this->exec(); 34 | } 35 | 36 | /** 37 | * GET /api/account/v3/deposit/history 38 | * */ 39 | public function getHistoryAll(array $data=[]){ 40 | $this->type='GET'; 41 | $this->path='/api/account/v3/deposit/history'; 42 | 43 | $this->data=$data; 44 | 45 | return $this->exec(); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/Api/AccountV3/Ledger.php: -------------------------------------------------------------------------------- 1 | 4 | * */ 5 | 6 | namespace Lin\Okex\Api\AccountV3; 7 | 8 | use Lin\Okex\Request; 9 | 10 | class Ledger extends Request 11 | { 12 | /** 13 | * 14 | * */ 15 | public function get(array $data=[]){ 16 | $this->type='GET'; 17 | $this->path='/api/account/v3/ledger'; 18 | 19 | $this->data=$data; 20 | 21 | return $this->exec(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Api/AccountV3/Transfer.php: -------------------------------------------------------------------------------- 1 | 4 | * */ 5 | 6 | namespace Lin\Okex\Api\AccountV3; 7 | 8 | use Lin\Okex\Request; 9 | 10 | class Transfer extends Request 11 | { 12 | /** 13 | * POST /api/account/v3/transfer 14 | * 15 | * currency String 是 币种,如eos 16 | amount String 是 划转数量 17 | from String 是 转出账户(0:子账户 1:币币 3:合约 4:C2C 5:币币杠杆 6:资金账户 8:余币宝 9 永续合约) 18 | to String 是 转入账户(0:子账户 1:币币 3:合约 4:C2C 5:币币杠杆 6:资金账户 8:余币宝 9 永续合约) 19 | sub_account String 否 子账号登录名,from或to指定为0时,sub_account为必填项, 20 | instrument_id String 否 杠杆转出币对,如:eos-usdt,仅限已开通杠杆的币对 21 | to_instrument_id String 否 杠杆转入币对,如:eos-btc,仅限已开通杠杆的币对 22 | * */ 23 | public function post(array $data=[]){ 24 | $this->type='POST'; 25 | $this->path='/api/account/v3/transfer'; 26 | 27 | $this->data=$data; 28 | 29 | return $this->exec(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/Api/AccountV3/Wallet.php: -------------------------------------------------------------------------------- 1 | 4 | * */ 5 | 6 | namespace Lin\Okex\Api\AccountV3; 7 | 8 | use Lin\Okex\Request; 9 | 10 | class Wallet extends Request 11 | { 12 | /** 13 | * GET /api/account/v3/wallet 14 | * */ 15 | public function getAll(){ 16 | $this->type='GET'; 17 | $this->path='/api/account/v3/wallet'; 18 | 19 | return $this->exec(); 20 | } 21 | 22 | /** 23 | * GET /api/account/v3/wallet/ 24 | * */ 25 | public function get(array $data=[]){ 26 | $this->type='GET'; 27 | $this->path='/api/account/v3/wallet/'.$data['currency']; 28 | 29 | $this->data=$data; 30 | 31 | return $this->exec(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Api/AccountV3/Withdrawal.php: -------------------------------------------------------------------------------- 1 | 4 | * */ 5 | 6 | namespace Lin\Okex\Api\AccountV3; 7 | 8 | use Lin\Okex\Request; 9 | 10 | class Withdrawal extends Request 11 | { 12 | /** 13 | * POST /api/account/v3/withdrawal 14 | * 15 | * currency String 是 币种 16 | amount String 是 数量 17 | destination String 是 提币到(2:OKCoin国际 3:OKEx 4:数字货币地址) 18 | to_address String 是 认证过的数字货币地址、邮箱或手机号。某些数字货币地址格式为:地址+标签,例:"ARDOR-7JF3-8F2E-QUWZ-CAN7F:123456" 19 | trade_pwd String 是 交易密码 20 | fee String 是 网络手续费≥0.提币到OKCoin国际或OKEx免手续费,请设置为0.提币到数字货币地址所需网络手续费可通过提币手续费接口查询 21 | * */ 22 | public function post(array $data=[]){ 23 | $this->type='POST'; 24 | $this->path='/api/account/v3/withdrawal'; 25 | 26 | $this->data=$data; 27 | 28 | return $this->exec(); 29 | } 30 | 31 | /** 32 | * GET /api/account/v3/withdrawal/fee 33 | * */ 34 | public function getFee(array $data=[]){ 35 | $this->type='GET'; 36 | $this->path='/api/account/v3/withdrawal/fee'; 37 | 38 | $this->data=$data; 39 | 40 | return $this->exec(); 41 | } 42 | 43 | /** 44 | *GET /api/account/v3/withdrawal/history 45 | * */ 46 | public function getHistoryAll(array $data=[]){ 47 | $this->type='GET'; 48 | $this->path='/api/account/v3/withdrawal/history'; 49 | 50 | $this->data=$data; 51 | 52 | return $this->exec(); 53 | } 54 | 55 | /** 56 | *GET /api/account/v3/withdrawal/history/ 57 | * */ 58 | public function getHistory(array $data=[]){ 59 | $this->type='GET'; 60 | $this->path='/api/account/v3/withdrawal/history/'.$data['currency']; 61 | 62 | $this->data=$data; 63 | 64 | return $this->exec(); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/Api/EttV3/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhouaini528/okex-php/5511b10d1bf16a6a9080fd9f690ddc76c265d37e/src/Api/EttV3/README.md -------------------------------------------------------------------------------- /src/Api/FuturesV3/Accounts.php: -------------------------------------------------------------------------------- 1 | 4 | * */ 5 | 6 | namespace Lin\Okex\Api\FuturesV3; 7 | 8 | 9 | 10 | use Lin\Okex\Request; 11 | 12 | class Accounts extends Request 13 | { 14 | /** 15 | * GET/api/futures/v3/account 16 | * */ 17 | public function getAll(){ 18 | $this->type='GET'; 19 | $this->path='/api/futures/v3/accounts'; 20 | 21 | return $this->exec(); 22 | } 23 | 24 | /* 25 | * GET/api/futures/v3/accounts/ 26 | * */ 27 | public function get(array $data=[]){ 28 | $this->type='GET'; 29 | $this->path='/api/futures/v3/accounts/'.$data['underlying']; 30 | 31 | $this->data=$data; 32 | 33 | return $this->exec(); 34 | } 35 | 36 | /* 37 | * GET/api/futures/v3/accounts//leverage 38 | * */ 39 | public function getLeverage(array $data=[]){ 40 | $this->type='GET'; 41 | $this->path='/api/futures/v3/accounts/'.$data['underlying'].'/leverage'; 42 | 43 | $this->data=$data; 44 | 45 | return $this->exec(); 46 | } 47 | 48 | /* 49 | * POST /api/futures/v3/accounts//leverage 50 | * */ 51 | public function postLeverage(array $data=[]){ 52 | $this->type='POST'; 53 | $this->path='/api/futures/v3/accounts/'.$data['underlying'].'/leverage'; 54 | $this->data=$data; 55 | return $this->exec(); 56 | } 57 | 58 | /* 59 | * GET/api/futures/v3/accounts//ledger 60 | * */ 61 | public function getLedger(array $data=[]){ 62 | $this->type='GET'; 63 | $this->path='/api/futures/v3/accounts/'.$data['underlying'].'/ledger'; 64 | $this->data=$data; 65 | return $this->exec(); 66 | } 67 | 68 | /** 69 | * GET/api/futures/v3/accounts//holds 70 | * */ 71 | public function getHolds(array $data=[]){ 72 | $this->type='GET'; 73 | $this->path='/api/futures/v3/accounts/'.$data['instrument_id'].'/holds'; 74 | 75 | $this->data=$data; 76 | 77 | return $this->exec(); 78 | } 79 | 80 | /** 81 | * POST /api/futures/v3/accounts/margin_mode 82 | * */ 83 | public function postMarginMode(array $data=[]){ 84 | $this->type='POST'; 85 | $this->path='/api/futures/v3/accounts/margin_mode'; 86 | $this->data=$data; 87 | return $this->exec(); 88 | } 89 | 90 | /* 91 | * POST /api/futures/v3/accounts/auto_margin 92 | * */ 93 | public function postAutoMargin(array $data=[]){ 94 | $this->type='POST'; 95 | $this->path='/api/futures/v3/accounts/auto_margin'; 96 | $this->data=$data; 97 | return $this->exec(); 98 | } 99 | 100 | /* 101 | * GET/api/futures/v3/trade_fee 102 | * */ 103 | public function getTradeFee(array $data=[]){ 104 | $this->type='GET'; 105 | $this->path='/api/futures/v3/trade_fee'; 106 | $this->data=$data; 107 | return $this->exec(); 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /src/Api/FuturesV3/Fills.php: -------------------------------------------------------------------------------- 1 | 4 | * */ 5 | 6 | namespace Lin\Okex\Api\FuturesV3; 7 | 8 | use Lin\Okex\Request; 9 | 10 | class Fills extends Request 11 | { 12 | /** 13 | * GET /api/futures/v3/fills 14 | * */ 15 | public function get(array $data=[]){ 16 | $this->type='GET'; 17 | $this->path='/api/futures/v3/fills'; 18 | $this->data=$data; 19 | return $this->exec(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/Api/FuturesV3/Instruments.php: -------------------------------------------------------------------------------- 1 | 4 | * */ 5 | 6 | namespace Lin\Okex\Api\FuturesV3; 7 | 8 | 9 | use Lin\Okex\Request; 10 | 11 | class Instruments extends Request 12 | { 13 | /** 14 | * GET/api/futures/v3/instruments 15 | */ 16 | public function get(){ 17 | $this->type='GET'; 18 | $this->path='/api/futures/v3/instruments'; 19 | 20 | return $this->exec(); 21 | } 22 | 23 | /** 24 | * GET/api/futures/v3/instruments//book 25 | */ 26 | public function getBook(array $data=[]){ 27 | $this->type='GET'; 28 | $this->path='/api/futures/v3/instruments/'.$data['instrument_id'].'/book'; 29 | unset($data['instrument_id']); 30 | 31 | $this->data=$data; 32 | 33 | return $this->exec(); 34 | } 35 | 36 | /** 37 | * GET /api/futures/v3/instruments/ticker 38 | * */ 39 | public function getTickerAll(){ 40 | $this->type='GET'; 41 | $this->path='/api/futures/v3/instruments/ticker'; 42 | return $this->exec(); 43 | } 44 | 45 | /** 46 | * GET /api/futures/v3/instruments//ticker 47 | * */ 48 | public function getTicker(array $data=[]){ 49 | $this->type='GET'; 50 | $this->path='GET /api/futures/v3/instruments/'.$data['instrument_id'].'/ticker'; 51 | $this->data=$data; 52 | return $this->exec(); 53 | } 54 | 55 | /** 56 | *GET /api/futures/v3/instruments//trades 57 | * */ 58 | public function getTrades(array $data=[]){ 59 | $this->type='GET'; 60 | $this->path='/api/futures/v3/instruments/'.$data['instrument_id'].'/trades'; 61 | $this->data=$data; 62 | return $this->exec(); 63 | } 64 | 65 | /** 66 | *GET /api/futures/v3/instruments//candles 67 | * */ 68 | public function getCandles(array $data=[]){ 69 | $this->type='GET'; 70 | $this->path='/api/futures/v3/instruments/'.$data['instrument_id'].'/candles'; 71 | $this->data=$data; 72 | return $this->exec(); 73 | } 74 | 75 | /** 76 | *GET/api/futures/v3/instruments//index 77 | * */ 78 | public function getIndex(array $data=[]){ 79 | $this->type='GET'; 80 | $this->path='/api/futures/v3/instruments/'.$data['instrument_id'].'/index'; 81 | $this->data=$data; 82 | return $this->exec(); 83 | } 84 | 85 | /** 86 | *GET /api/futures/v3/instruments//estimated_price 87 | * */ 88 | public function getEstimatedPrice(array $data=[]){ 89 | $this->type='GET'; 90 | $this->path='/api/futures/v3/instruments/'.$data['instrument_id'].'/estimated_price'; 91 | $this->data=$data; 92 | return $this->exec(); 93 | } 94 | 95 | /** 96 | *GET /api/futures/v3/instruments//open_interest 97 | * */ 98 | public function getOpenInterest(array $data=[]){ 99 | $this->type='GET'; 100 | $this->path='/api/futures/v3/instruments/'.$data['instrument_id'].'/open_interest'; 101 | $this->data=$data; 102 | return $this->exec(); 103 | } 104 | 105 | /** 106 | *GET /api/futures/v3/instruments//price_limit 107 | * */ 108 | public function getPriceLimit(array $data=[]){ 109 | $this->type='GET'; 110 | $this->path='/api/futures/v3/instruments/'.$data['instrument_id'].'/price_limit'; 111 | $this->data=$data; 112 | return $this->exec(); 113 | } 114 | 115 | /** 116 | *GET/api/futures/v3/instruments//mark_price 117 | * */ 118 | public function getMarkPrice(array $data=[]){ 119 | $this->type='GET'; 120 | $this->path='/api/futures/v3/instruments/'.$data['instrument_id'].'/mark_price'; 121 | $this->data=$data; 122 | return $this->exec(); 123 | } 124 | 125 | /** 126 | *GET /api/futures/v3/instruments//liquidation 127 | * */ 128 | public function getLiquidation(array $data=[]){ 129 | $this->type='GET'; 130 | $this->path='/api/futures/v3/instruments/'.$data['instrument_id'].'/liquidation'; 131 | $this->data=$data; 132 | return $this->exec(); 133 | } 134 | 135 | /** 136 | *GET /api/futures/v3/instruments//history/candles 137 | * */ 138 | public function getHistoryCandles(array $data=[]){ 139 | $this->type='GET'; 140 | $this->path='/api/futures/v3/instruments/'.$data['instrument_id'].'/history/candles'; 141 | $this->data=$data; 142 | return $this->exec(); 143 | } 144 | 145 | /** 146 | *GET /api/futures/v3/rate 147 | * */ 148 | public function getRate(array $data=[]){ 149 | $this->type='GET'; 150 | $this->path='/api/futures/v3/rate'; 151 | $this->data=$data; 152 | return $this->exec(); 153 | } 154 | 155 | /** 156 | *GET /api/futures/v3/settlement/history 157 | * */ 158 | public function getSettlementHistory(array $data=[]){ 159 | $this->type='GET'; 160 | $this->path='/api/futures/v3/settlement/history'; 161 | $this->data=$data; 162 | return $this->exec(); 163 | } 164 | } 165 | -------------------------------------------------------------------------------- /src/Api/FuturesV3/Orders.php: -------------------------------------------------------------------------------- 1 | 4 | * */ 5 | 6 | namespace Lin\Okex\Api\FuturesV3; 7 | 8 | 9 | 10 | use Lin\Okex\Request; 11 | 12 | class Orders extends Request 13 | { 14 | /** 15 | OKEx token trading only supports limit and market orders (more order types will become available in the future). You can place an order only if you have enough funds. 16 | Once your order is placed, the amount will be put on hold. 17 | 18 | Parameters Parameters Types Required Description 19 | client_oid string No the order ID customized by yourself , The client_oid type should be comprised of alphabets + numbers or only alphabets within 1 – 32 characters, both uppercase and lowercase letters are supported 20 | instrument_id String Yes Contract ID,e.g. “TC-USD-180213” 21 | type String Yes 1:open long 2:open short 3:close long 4:close short 22 | price price Yes Price of each contract 23 | size Number Yes The buying or selling quantity 24 | match_price String No Order at best counter party price? (0:no 1:yes) the parameter is defaulted as 0. If it is set as 1, the price parameter will be ignored 25 | leverage Number Yes 10x or 20x leverage 26 | order_type string No Fill in number for parameter,0: Normal limit order (Unfilled and 0 represent normal limit order) 1: Post only 2: Fill Or Kill 3: Immediatel Or Cancel 27 | * */ 28 | public function post(array $data=[]){ 29 | $this->type='POST'; 30 | $this->path='/api/futures/v3/order'; 31 | 32 | $data['leverage']=$data['leverage']??10; 33 | 34 | $this->data=$data; 35 | 36 | return $this->exec(); 37 | } 38 | 39 | /** 40 | * POST /api/futures/v3/orders 41 | * */ 42 | public function postBatch(array $data=[]){ 43 | $this->type='POST'; 44 | $this->path='/api/futures/v3/orders'; 45 | 46 | $this->data=$data; 47 | 48 | return $this->exec(); 49 | } 50 | 51 | /** 52 | * POST /api/futures/v3/cancel_order// or 53 | * Cancelling an unfilled order. 54 | 55 | Parameters Parameters Types Required Description 56 | order_id String Yes Order ID 57 | instrument_id String Yes Contract ID,e.g. “BTC-USD-180213” 58 | client_oid string Yes the order ID created by yourself, The client_oid type should be comprised of alphabets + numbers or only alphabets within 1 – 32 characters, both uppercase and lowercase letters are supported 59 | 60 | * */ 61 | public function postCancel(array $data=[]){ 62 | $id=$data['order_id'] ?? $data['client_oid']; 63 | unset($data['order_id']); 64 | unset($data['client_oid']); 65 | 66 | $this->type='POST'; 67 | $this->path='/api/futures/v3/cancel_order/'.$data['instrument_id'].'/'.$id; 68 | $this->data=$data; 69 | return $this->exec(); 70 | } 71 | 72 | /** 73 | * POST /api/futures/v3/cancel_batch_orders/ 74 | * */ 75 | public function postCancelBatch(array $data=[]){ 76 | $this->type='POST'; 77 | $this->path='/api/futures/v3/cancel_batch_orders/'.$data['instrument_id']; 78 | $this->data=$data; 79 | return $this->exec(); 80 | } 81 | 82 | /** 83 | *POST/api/futures/v3/amend_order/ 84 | * */ 85 | public function postAmend(array $data=[]){ 86 | $this->type='POST'; 87 | $this->path='/api/futures/v3/amend_order/'.$data['instrument_id']; 88 | $this->data=$data; 89 | return $this->exec(); 90 | } 91 | 92 | /** 93 | *POST /api/futures/v3/amend_batch_orders/ 94 | * */ 95 | public function postAmendBatch(array $data=[]){ 96 | $this->type='POST'; 97 | $this->path='/api/futures/v3/amend_batch_orders/'.$data['instrument_id']; 98 | $this->data=$data; 99 | return $this->exec(); 100 | } 101 | 102 | /** 103 | *GET /api/futures/v3/orders/ 104 | * */ 105 | public function getAll(array $data=[]){ 106 | $this->type='GET'; 107 | $this->path='/api/futures/v3/orders/'.$data['instrument_id']; 108 | $this->data=$data; 109 | return $this->exec(); 110 | } 111 | 112 | /** 113 | * Get order details 114 | * 115 | * GET/api/futures/v3/orders// 116 | * GET/api/futures/v3/orders// 117 | 118 | Parameters Parameters Types Required Description 119 | order_id String Yes Order ID 120 | instrument_id String Yes Contract ID,e.g.“BTC-USD-180213” 121 | client_oid string Yes The client_oid type should be comprised of alphabets + numbers or only alphabets within 1 – 32 characters, both uppercase and lowercase letters are supported 122 | 123 | * */ 124 | public function get(array $data=[]){ 125 | $id=$data['order_id'] ?? $data['client_oid']; 126 | unset($data['order_id']); 127 | unset($data['client_oid']); 128 | 129 | $this->type='GET'; 130 | $this->path='/api/futures/v3/orders/'.$data['instrument_id'].'/'.$id; 131 | 132 | $this->data=$data; 133 | 134 | return $this->exec(); 135 | } 136 | 137 | /** 138 | *POST /api/futures/v3/cancel_all 139 | * */ 140 | public function postCancelAll(array $data=[]){ 141 | $this->type='POST'; 142 | $this->path='/api/futures/v3/cancel_all'; 143 | $this->data=$data; 144 | return $this->exec(); 145 | } 146 | 147 | /* 148 | *POST /api/futures/v3/order_algo 149 | * */ 150 | public function postOrderAlgo(array $data=[]){ 151 | $this->type='POST'; 152 | $this->path='/api/futures/v3/order_algo'; 153 | $this->data=$data; 154 | return $this->exec(); 155 | } 156 | 157 | /* 158 | *POST /api/futures/v3/cancel_algos 159 | * */ 160 | public function postCancelAlgos(array $data=[]){ 161 | $this->type='POST'; 162 | $this->path='/api/futures/v3/cancel_algos'; 163 | $this->data=$data; 164 | return $this->exec(); 165 | } 166 | 167 | /* 168 | *GET/api/futures/v3/order_algo/ 169 | * */ 170 | public function getOrderAlgo(array $data=[]){ 171 | $this->type='GET'; 172 | $this->path='/api/futures/v3/order_algo/'.$data['instrument_id']; 173 | $this->data=$data; 174 | return $this->exec(); 175 | } 176 | } 177 | -------------------------------------------------------------------------------- /src/Api/FuturesV3/Position.php: -------------------------------------------------------------------------------- 1 | 4 | * */ 5 | 6 | namespace Lin\Okex\Api\FuturesV3; 7 | 8 | use Lin\Okex\Request; 9 | 10 | class Position extends Request 11 | { 12 | /** 13 | * Get the information of all holding positions in futures trading.Due to high energy consumption, you are advised to capture data with the "Futures Account of a Currency" API instead. 14 | * 15 | * */ 16 | public function getAll(){ 17 | $this->type='GET'; 18 | $this->path='/api/futures/v3/position'; 19 | 20 | return $this->exec(); 21 | } 22 | 23 | /** 24 | * Get the information of holding positions of a contract. 25 | * 26 | Parameters Parameters Types Required Description 27 | instrument_id String Yes Contract ID, e.g.“BTC-USD-180213” 28 | * */ 29 | public function get(array $data=[]){ 30 | $this->type='GET'; 31 | $this->path='/api/futures/v3/'.$data['instrument_id'].'/position'; 32 | 33 | $this->data=$data; 34 | 35 | return $this->exec(); 36 | } 37 | 38 | /* 39 | * POST /api/futures/v3/close_position 40 | * */ 41 | public function postClose(array $data=[]){ 42 | $this->type='GET'; 43 | $this->path='/api/futures/v3/close_position'; 44 | 45 | $this->data=$data; 46 | 47 | return $this->exec(); 48 | } 49 | 50 | /* 51 | * POST /api/futures/v3/position/margin 52 | * */ 53 | public function postMargin(array $data=[]){ 54 | $this->type='GET'; 55 | $this->path='/api/futures/v3/position/margin'; 56 | 57 | $this->data=$data; 58 | 59 | return $this->exec(); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/Api/MarginV3/Accounts.php: -------------------------------------------------------------------------------- 1 | 4 | * */ 5 | 6 | namespace Lin\Okex\Api\MarginV3; 7 | 8 | use Lin\Okex\Request; 9 | 10 | class Accounts extends Request 11 | { 12 | public function getAll(){ 13 | $this->type='GET'; 14 | $this->path='/api/margin/v3/accounts'; 15 | 16 | return $this->exec(); 17 | } 18 | 19 | /** 20 | * GET /api/margin/v3/accounts/ 21 | * */ 22 | public function get(array $data=[]){ 23 | $this->type='GET'; 24 | $this->path='/api/margin/v3/accounts/'.$data['instrument_id']; 25 | 26 | $this->data=$data; 27 | 28 | return $this->exec(); 29 | } 30 | 31 | /** 32 | * GET /api/margin/v3/accounts//ledger 33 | * */ 34 | public function getLedger(array $data=[]){ 35 | $this->type='GET'; 36 | $this->path='/api/margin/v3/accounts/'.$data['instrument_id'].'/ledger'; 37 | 38 | $this->data=$data; 39 | 40 | return $this->exec(); 41 | } 42 | 43 | /** 44 | * GET /api/margin/v3/accounts/availability 45 | * */ 46 | public function getAvailabilityAll(){ 47 | $this->type='GET'; 48 | $this->path='/api/margin/v3/accounts/availability'; 49 | 50 | return $this->exec(); 51 | } 52 | 53 | /** 54 | * GET /api/margin/v3/accounts//availability 55 | * */ 56 | public function getAvailability(array $data=[]){ 57 | $this->type='GET'; 58 | $this->path='/api/margin/v3/accounts/'.$data['instrument_id'].'/availability'; 59 | 60 | $this->data=$data; 61 | 62 | return $this->exec(); 63 | } 64 | 65 | /** 66 | * GET /api/margin/v3/accounts/borrowed 67 | * */ 68 | public function getBorrowedAll(){ 69 | $this->type='GET'; 70 | $this->path='/api/margin/v3/accounts/borrowed'; 71 | 72 | return $this->exec(); 73 | } 74 | 75 | /** 76 | * GET /api/margin/v3/accounts//borrowed 77 | * */ 78 | public function getBorrowed(array $data=[]){ 79 | $this->type='GET'; 80 | $this->path='/api/margin/v3/accounts/'.$data['instrument_id'].'/borrowed'; 81 | 82 | $this->data=$data; 83 | 84 | return $this->exec(); 85 | } 86 | 87 | /** 88 | * POST /api/margin/v3/accounts/borrow 89 | * */ 90 | public function postBorrow(array $data=[]){ 91 | $this->type='POST'; 92 | $this->path='/api/margin/v3/accounts/borrow'; 93 | 94 | $this->data=$data; 95 | 96 | return $this->exec(); 97 | } 98 | 99 | /** 100 | * POST /api/margin/v3/accounts/repayment 101 | * */ 102 | public function postRepayment(array $data=[]){ 103 | $this->type='POST'; 104 | $this->path='/api/margin/v3/accounts/repayment'; 105 | 106 | $this->data=$data; 107 | 108 | return $this->exec(); 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /src/Api/MarginV3/Fills.php: -------------------------------------------------------------------------------- 1 | 4 | * */ 5 | 6 | namespace Lin\Okex\Api\MarginV3; 7 | 8 | use Lin\Okex\Request; 9 | 10 | class Fills extends Request 11 | { 12 | /** 13 | * GET /api/margin/v3/fills 14 | * */ 15 | public function get(){ 16 | $this->type='GET'; 17 | $this->path='/api/margin/v3/fills'; 18 | 19 | return $this->exec(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/Api/MarginV3/Orders.php: -------------------------------------------------------------------------------- 1 | 4 | * */ 5 | 6 | namespace Lin\Okex\Api\MarginV3; 7 | 8 | 9 | 10 | use Lin\Okex\Request; 11 | 12 | class Orders extends Request 13 | { 14 | /** 15 | * POST /api/margin/v3/orders 16 | * */ 17 | public function post(array $data=[]){ 18 | $this->type='POST'; 19 | $this->path='/api/margin/v3/orders'; 20 | 21 | $this->data=$data; 22 | 23 | return $this->exec(); 24 | } 25 | 26 | /** 27 | * POST /api/margin/v3/batch_orders 28 | * */ 29 | public function postBatch(array $data=[]){ 30 | $this->type='POST'; 31 | $this->path='/api/margin/v3/batch_orders'; 32 | 33 | $this->data=$data; 34 | 35 | return $this->exec(); 36 | } 37 | 38 | /** 39 | * POST /api/margin/v3/cancel_orders/ 40 | * POST /api/margin/v3/cancel_orders/ 41 | * */ 42 | public function postCancel(array $data=[]){ 43 | $id=$data['order_id'] ?? $data['client_oid']; 44 | unset($data['order_id']); 45 | unset($data['client_oid']); 46 | 47 | $this->type='POST'; 48 | $this->path='/api/margin/v3/cancel_orders/'.$id; 49 | 50 | $this->data=$data; 51 | 52 | return $this->exec(); 53 | } 54 | 55 | /** 56 | * POST /api/margin/v3/cancel_batch_orders 57 | * */ 58 | public function postCancelBatch(array $data=[]){ 59 | $this->type='POST'; 60 | $this->path='/api/margin/v3/cancel_batch_orders/'; 61 | 62 | $this->data=$data; 63 | 64 | return $this->exec(); 65 | } 66 | 67 | /** 68 | * GET /api/margin/v3/orders 69 | * */ 70 | public function getAll(array $data=[]){ 71 | $this->type='GET'; 72 | $this->path='/api/margin/v3/orders'; 73 | 74 | $this->data=$data; 75 | 76 | return $this->exec(); 77 | } 78 | 79 | /** 80 | * GET /api/margin/v3/orders/ 81 | * GET /api/margin/v3/orders/ 82 | * */ 83 | public function get(array $data=[]){ 84 | $id=$data['order_id'] ?? $data['client_oid']; 85 | unset($data['order_id']); 86 | unset($data['client_oid']); 87 | 88 | $this->type='GET'; 89 | $this->path='/api/margin/v3/orders/'.$id; 90 | 91 | $this->data=$data; 92 | 93 | return $this->exec(); 94 | } 95 | 96 | /** 97 | * GET /api/margin/v3/orders_pending 98 | * */ 99 | public function getPending(array $data=[]){ 100 | $this->type='GET'; 101 | $this->path=' /api/margin/v3/orders_pending'; 102 | 103 | $this->data=$data; 104 | 105 | return $this->exec(); 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /src/Api/OkexV5/Account.php: -------------------------------------------------------------------------------- 1 | 4 | * */ 5 | 6 | namespace Lin\Okex\Api\OkexV5; 7 | 8 | use Lin\Okex\Request; 9 | 10 | class Account extends Request 11 | { 12 | /** 13 | *GET /api/v5/account/balance 14 | * */ 15 | public function getBalance(array $data=[]){ 16 | $this->type='GET'; 17 | $this->path='/api/v5/account/balance'; 18 | 19 | $this->data=$data; 20 | return $this->exec(); 21 | } 22 | 23 | /** 24 | *GET /api/v5/account/positions 25 | * */ 26 | public function getPositions(array $data=[]){ 27 | $this->type='GET'; 28 | $this->path='/api/v5/account/positions'; 29 | 30 | $this->data=$data; 31 | return $this->exec(); 32 | } 33 | 34 | /** 35 | *GET /api/v5/account/bills 36 | * */ 37 | public function getBills(array $data=[]){ 38 | $this->type='GET'; 39 | $this->path='/api/v5/account/bills'; 40 | 41 | $this->data=$data; 42 | return $this->exec(); 43 | } 44 | 45 | /** 46 | *GET /api/v5/account/bills-archive 47 | * */ 48 | public function getBillsArchive(array $data=[]){ 49 | $this->type='GET'; 50 | $this->path='/api/v5/account/bills-archive'; 51 | 52 | $this->data=$data; 53 | return $this->exec(); 54 | } 55 | 56 | /** 57 | *GET /api/v5/account/config 58 | * */ 59 | public function getConfig(array $data=[]){ 60 | $this->type='GET'; 61 | $this->path='/api/v5/account/config'; 62 | 63 | $this->data=$data; 64 | return $this->exec(); 65 | } 66 | 67 | /** 68 | *POST /api/v5/account/set-position-mode 69 | * */ 70 | public function postSetPositionMode(array $data=[]){ 71 | $this->type='POST'; 72 | $this->path='/api/v5/account/set-position-mode'; 73 | 74 | $this->data=$data; 75 | return $this->exec(); 76 | } 77 | 78 | /** 79 | *POST /api/v5/account/set-leverage 80 | * */ 81 | public function postSetLeverage(array $data=[]){ 82 | $this->type='POST'; 83 | $this->path='/api/v5/account/set-leverage'; 84 | 85 | $this->data=$data; 86 | return $this->exec(); 87 | } 88 | 89 | /** 90 | *GET /api/v5/account/max-size 91 | * */ 92 | public function getMaxSize(array $data=[]){ 93 | $this->type='GET'; 94 | $this->path='/api/v5/account/max-size'; 95 | 96 | $this->data=$data; 97 | return $this->exec(); 98 | } 99 | 100 | /** 101 | *GET /api/v5/account/max-avail-size 102 | * */ 103 | public function getMaxAvailSize(array $data=[]){ 104 | $this->type='GET'; 105 | $this->path='/api/v5/account/max-avail-size'; 106 | 107 | $this->data=$data; 108 | return $this->exec(); 109 | } 110 | 111 | /** 112 | *POST /api/v5/account/position/margin-balance 113 | * */ 114 | public function postPositionMarginBalance(array $data=[]){ 115 | $this->type='POST'; 116 | $this->path='/api/v5/account/position/margin-balance'; 117 | 118 | $this->data=$data; 119 | return $this->exec(); 120 | } 121 | 122 | /** 123 | *GET /api/v5/account/leverage-info 124 | * */ 125 | public function getLeverageInfo(array $data=[]){ 126 | $this->type='GET'; 127 | $this->path='/api/v5/account/leverage-info'; 128 | 129 | $this->data=$data; 130 | return $this->exec(); 131 | } 132 | 133 | /** 134 | *GET /api/v5/account/max-loan 135 | * */ 136 | public function getMaxLoan(array $data=[]){ 137 | $this->type='GET'; 138 | $this->path='/api/v5/account/max-loan'; 139 | 140 | $this->data=$data; 141 | return $this->exec(); 142 | } 143 | 144 | /** 145 | *GET /api/v5/account/trade-fee 146 | * */ 147 | public function getTradeFee(array $data=[]){ 148 | $this->type='GET'; 149 | $this->path='/api/v5/account/trade-fee'; 150 | 151 | $this->data=$data; 152 | return $this->exec(); 153 | } 154 | 155 | /** 156 | *GET /api/v5/account/interest-accrued 157 | * */ 158 | public function getInterestAccrued(array $data=[]){ 159 | $this->type='GET'; 160 | $this->path='/api/v5/account/interest-accrued'; 161 | 162 | $this->data=$data; 163 | return $this->exec(); 164 | } 165 | 166 | /** 167 | *POST /api/v5/account/set-greeks 168 | * */ 169 | public function postSetGreeks(array $data=[]){ 170 | $this->type='POST'; 171 | $this->path='/api/v5/account/set-greeks'; 172 | 173 | $this->data=$data; 174 | return $this->exec(); 175 | } 176 | 177 | /** 178 | *GET /api/v5/account/max-withdrawal 179 | * */ 180 | public function getMaxWithdrawal(array $data=[]){ 181 | $this->type='GET'; 182 | $this->path='/api/v5/account/max-withdrawal'; 183 | 184 | $this->data=$data; 185 | return $this->exec(); 186 | } 187 | } 188 | -------------------------------------------------------------------------------- /src/Api/OkexV5/Asset.php: -------------------------------------------------------------------------------- 1 | 4 | * */ 5 | 6 | namespace Lin\Okex\Api\OkexV5; 7 | 8 | use Lin\Okex\Request; 9 | 10 | class Asset extends Request 11 | { 12 | /** 13 | * GET /api/v5/asset/deposit-address 14 | * */ 15 | public function getDepositAddress(array $data=[]){ 16 | $this->type='GET'; 17 | $this->path='/api/v5/asset/deposit-address'; 18 | 19 | $this->data=$data; 20 | return $this->exec(); 21 | } 22 | 23 | /** 24 | *GET /api/v5/asset/balances 25 | * */ 26 | public function getBalances(array $data=[]){ 27 | $this->type='GET'; 28 | $this->path='/api/v5/asset/balances'; 29 | 30 | $this->data=$data; 31 | return $this->exec(); 32 | } 33 | 34 | /** 35 | *POST /api/v5/asset/transfer 36 | * */ 37 | public function postTransfer(array $data=[]){ 38 | $this->type='POST'; 39 | $this->path='/api/v5/asset/transfer'; 40 | 41 | $this->data=$data; 42 | return $this->exec(); 43 | } 44 | 45 | /** 46 | *POST /api/v5/asset/withdrawal 47 | * */ 48 | public function postWithdrawal(array $data=[]){ 49 | $this->type='POST'; 50 | $this->path='/api/v5/asset/withdrawal'; 51 | 52 | $this->data=$data; 53 | return $this->exec(); 54 | } 55 | 56 | /** 57 | *GET /api/v5/asset/deposit-history 58 | * */ 59 | public function getDepositHistory(array $data=[]){ 60 | $this->type='GET'; 61 | $this->path='/api/v5/asset/deposit-history'; 62 | 63 | $this->data=$data; 64 | return $this->exec(); 65 | } 66 | 67 | /** 68 | *GET /api/v5/asset/withdrawal-history 69 | * */ 70 | public function getWithdrawalHistory(array $data=[]){ 71 | $this->type='GET'; 72 | $this->path='/api/v5/asset/withdrawal-history'; 73 | 74 | $this->data=$data; 75 | return $this->exec(); 76 | } 77 | 78 | /** 79 | *GET /api/v5/asset/currencies 80 | * */ 81 | public function getCurrencies(array $data=[]){ 82 | $this->type='GET'; 83 | $this->path='/api/v5/asset/currencies'; 84 | 85 | $this->data=$data; 86 | return $this->exec(); 87 | } 88 | 89 | /** 90 | *POST /api/v5/asset/purchase_redempt 91 | * */ 92 | public function postPurchaseRedempt(array $data=[]){ 93 | $this->type='POST'; 94 | $this->path='/api/v5/asset/purchase_redempt'; 95 | 96 | $this->data=$data; 97 | return $this->exec(); 98 | } 99 | 100 | /** 101 | *GET /api/v5/asset/bills 102 | * */ 103 | public function getBills(array $data=[]){ 104 | $this->type='GET'; 105 | $this->path='/api/v5/asset/bills'; 106 | 107 | $this->data=$data; 108 | return $this->exec(); 109 | } 110 | 111 | 112 | /** 113 | * 114 | * */ 115 | /*public function get(array $data=[]){ 116 | $this->type='GET'; 117 | $this->path=''; 118 | 119 | $this->data=$data; 120 | return $this->exec(); 121 | }*/ 122 | } 123 | -------------------------------------------------------------------------------- /src/Api/OkexV5/Market.php: -------------------------------------------------------------------------------- 1 | 4 | * */ 5 | 6 | namespace Lin\Okex\Api\OkexV5; 7 | 8 | use Lin\Okex\Request; 9 | 10 | class Market extends Request 11 | { 12 | /** 13 | *GET /api/v5/market/tickers 14 | * */ 15 | public function getTickers(array $data=[]){ 16 | $this->type='GET'; 17 | $this->path='/api/v5/market/tickers'; 18 | 19 | $this->data=$data; 20 | return $this->exec(); 21 | } 22 | 23 | /** 24 | *GET /api/v5/market/ticker 25 | * */ 26 | public function getTicker(array $data=[]){ 27 | $this->type='GET'; 28 | $this->path='/api/v5/market/ticker'; 29 | 30 | $this->data=$data; 31 | return $this->exec(); 32 | } 33 | 34 | /** 35 | *GET /api/v5/market/index-tickers 36 | * */ 37 | public function getIndexTickers(array $data=[]){ 38 | $this->type='GET'; 39 | $this->path='/api/v5/market/index-tickers'; 40 | 41 | $this->data=$data; 42 | return $this->exec(); 43 | } 44 | 45 | /** 46 | *GET /api/v5/market/books 47 | * */ 48 | public function getBooks(array $data=[]){ 49 | $this->type='GET'; 50 | $this->path='/api/v5/market/books'; 51 | 52 | $this->data=$data; 53 | return $this->exec(); 54 | } 55 | 56 | /** 57 | *GET /api/v5/market/candles 58 | * */ 59 | public function getCandles(array $data=[]){ 60 | $this->type='GET'; 61 | $this->path='/api/v5/market/candles'; 62 | 63 | $this->data=$data; 64 | return $this->exec(); 65 | } 66 | 67 | /** 68 | *GET /api/v5/market/history-candles 69 | * */ 70 | public function getHistoryCandles(array $data=[]){ 71 | $this->type='GET'; 72 | $this->path='/api/v5/market/history-candles'; 73 | 74 | $this->data=$data; 75 | return $this->exec(); 76 | } 77 | 78 | /** 79 | *GET /api/v5/market/index-candles 80 | * */ 81 | public function getIndexCandles(array $data=[]){ 82 | $this->type='GET'; 83 | $this->path='/api/v5/market/index-candles'; 84 | 85 | $this->data=$data; 86 | return $this->exec(); 87 | } 88 | 89 | /** 90 | *GET /api/v5/market/mark-price-candles 91 | * */ 92 | public function getMarkPriceCandles(array $data=[]){ 93 | $this->type='GET'; 94 | $this->path='/api/v5/market/mark-price-candles'; 95 | 96 | $this->data=$data; 97 | return $this->exec(); 98 | } 99 | 100 | /** 101 | *GET /api/v5/market/trades 102 | * */ 103 | public function getTrades(array $data=[]){ 104 | $this->type='GET'; 105 | $this->path='/api/v5/market/trades'; 106 | 107 | $this->data=$data; 108 | return $this->exec(); 109 | } 110 | 111 | /** 112 | * 113 | * */ 114 | /*public function get(array $data=[]){ 115 | $this->type='GET'; 116 | $this->path=''; 117 | 118 | $this->data=$data; 119 | return $this->exec(); 120 | }*/ 121 | } 122 | -------------------------------------------------------------------------------- /src/Api/OkexV5/Publics.php: -------------------------------------------------------------------------------- 1 | 4 | * */ 5 | 6 | namespace Lin\Okex\Api\OkexV5; 7 | 8 | use Lin\Okex\Request; 9 | 10 | class Publics extends Request 11 | { 12 | /** 13 | *GET /api/v5/public/instruments 14 | * */ 15 | public function getInstruments(array $data=[]){ 16 | $this->type='GET'; 17 | $this->path='/api/v5/public/instruments'; 18 | 19 | $this->data=$data; 20 | return $this->exec(); 21 | } 22 | 23 | /** 24 | *GET /api/v5/public/delivery-exercise-history 25 | * */ 26 | public function getDeliveryExerciseHistory(array $data=[]){ 27 | $this->type='GET'; 28 | $this->path='/api/v5/public/delivery-exercise-history'; 29 | 30 | $this->data=$data; 31 | return $this->exec(); 32 | } 33 | 34 | /** 35 | *GET /api/v5/public/open-interest 36 | * */ 37 | public function getOpenInterest(array $data=[]){ 38 | $this->type='GET'; 39 | $this->path='/api/v5/public/open-interest'; 40 | 41 | $this->data=$data; 42 | return $this->exec(); 43 | } 44 | 45 | /** 46 | *GET /api/v5/public/funding-rate 47 | * */ 48 | public function getFundingRate(array $data=[]){ 49 | $this->type='GET'; 50 | $this->path='/api/v5/public/funding-rate'; 51 | 52 | $this->data=$data; 53 | return $this->exec(); 54 | } 55 | 56 | /** 57 | *GET /api/v5/public/funding-rate-history 58 | * */ 59 | public function getFundingRateHistory(array $data=[]){ 60 | $this->type='GET'; 61 | $this->path='/api/v5/public/funding-rate-history'; 62 | 63 | $this->data=$data; 64 | return $this->exec(); 65 | } 66 | 67 | /** 68 | *GET /api/v5/public/price-limit 69 | * */ 70 | public function getPriceLimit(array $data=[]){ 71 | $this->type='GET'; 72 | $this->path='/api/v5/public/price-limit'; 73 | 74 | $this->data=$data; 75 | return $this->exec(); 76 | } 77 | 78 | /** 79 | *GET /api/v5/public/opt-summary 80 | * */ 81 | public function getOptSummary(array $data=[]){ 82 | $this->type='GET'; 83 | $this->path='/api/v5/public/opt-summary'; 84 | 85 | $this->data=$data; 86 | return $this->exec(); 87 | } 88 | 89 | /** 90 | *GET /api/v5/public/estimated-price 91 | * */ 92 | public function getEstimatedPrice(array $data=[]){ 93 | $this->type='GET'; 94 | $this->path='/api/v5/public/estimated-price'; 95 | 96 | $this->data=$data; 97 | return $this->exec(); 98 | } 99 | 100 | /** 101 | *GET /api/v5/public/discount-rate-interest-free-quota 102 | * */ 103 | public function getDiscountRateInterestFreeQuota(array $data=[]){ 104 | $this->type='GET'; 105 | $this->path='/api/v5/public/discount-rate-interest-free-quota'; 106 | 107 | $this->data=$data; 108 | return $this->exec(); 109 | } 110 | 111 | /** 112 | *GET /api/v5/public/time 113 | * */ 114 | public function getTime(array $data=[]){ 115 | $this->type='GET'; 116 | $this->path='/api/v5/public/time'; 117 | 118 | $this->data=$data; 119 | return $this->exec(); 120 | } 121 | 122 | /** 123 | *GET /api/v5/public/liquidation-orders 124 | * */ 125 | public function getLiquidationOrders(array $data=[]){ 126 | $this->type='GET'; 127 | $this->path='/api/v5/public/liquidation-orders'; 128 | 129 | $this->data=$data; 130 | return $this->exec(); 131 | } 132 | 133 | /** 134 | *GET /api/v5/public/mark-price 135 | * */ 136 | public function getMarkPrice(array $data=[]){ 137 | $this->type='GET'; 138 | $this->path='/api/v5/public/mark-price'; 139 | 140 | $this->data=$data; 141 | return $this->exec(); 142 | } 143 | 144 | /** 145 | * 146 | * */ 147 | /*public function get(array $data=[]){ 148 | $this->type='GET'; 149 | $this->path=''; 150 | 151 | $this->data=$data; 152 | return $this->exec(); 153 | }*/ 154 | } 155 | -------------------------------------------------------------------------------- /src/Api/OkexV5/SubAccount.php: -------------------------------------------------------------------------------- 1 | 4 | * */ 5 | 6 | namespace Lin\Okex\Api\OkexV5; 7 | 8 | use Lin\Okex\Request; 9 | 10 | class SubAccount extends Request 11 | { 12 | /** 13 | *GET /api/v5/account/subaccount/balances 14 | * */ 15 | public function getBalances(array $data=[]){ 16 | $this->type='GET'; 17 | $this->path='/api/v5/account/subaccount/balances'; 18 | 19 | $this->data=$data; 20 | return $this->exec(); 21 | } 22 | 23 | /** 24 | *GET /api/v5/asset/subaccount/bills 25 | * */ 26 | public function getBills(array $data=[]){ 27 | $this->type='GET'; 28 | $this->path='/api/v5/asset/subaccount/bills'; 29 | 30 | $this->data=$data; 31 | return $this->exec(); 32 | } 33 | 34 | /** 35 | *POST /api/v5/users/subaccount/delete-apikey 36 | * */ 37 | public function postDeleteApiKey(array $data=[]){ 38 | $this->type='POST'; 39 | $this->path='/api/v5/users/subaccount/delete-apikey'; 40 | 41 | $this->data=$data; 42 | return $this->exec(); 43 | } 44 | 45 | /** 46 | *POST /api/v5/users/subaccount/modify-apikey 47 | * */ 48 | public function postModifyApiKey(array $data=[]){ 49 | $this->type='POST'; 50 | $this->path='/api/v5/users/subaccount/modify-apikey'; 51 | 52 | $this->data=$data; 53 | return $this->exec(); 54 | } 55 | 56 | /** 57 | *POST /api/v5/users/subaccount/apikey 58 | * */ 59 | public function postApiKey(array $data=[]){ 60 | $this->type='POST'; 61 | $this->path='/api/v5/users/subaccount/apikey'; 62 | 63 | $this->data=$data; 64 | return $this->exec(); 65 | } 66 | 67 | /** 68 | *GET /api/v5/users/subaccount/list 69 | * */ 70 | public function getList(array $data=[]){ 71 | $this->type='GET'; 72 | $this->path='/api/v5/users/subaccount/list'; 73 | 74 | $this->data=$data; 75 | return $this->exec(); 76 | } 77 | 78 | /** 79 | *POST /api/v5/asset/subaccount/transfer 80 | * */ 81 | public function postTransfer(array $data=[]){ 82 | $this->type='POST'; 83 | $this->path='/api/v5/asset/subaccount/transfer'; 84 | 85 | $this->data=$data; 86 | return $this->exec(); 87 | } 88 | 89 | /** 90 | * 91 | * */ 92 | /*public function get(array $data=[]){ 93 | $this->type='GET'; 94 | $this->path=''; 95 | 96 | $this->data=$data; 97 | return $this->exec(); 98 | }*/ 99 | } 100 | -------------------------------------------------------------------------------- /src/Api/OkexV5/System.php: -------------------------------------------------------------------------------- 1 | type='GET'; 13 | $this->path='/api/v5/system/status'; 14 | 15 | $this->data=$data; 16 | return $this->exec(); 17 | } 18 | } -------------------------------------------------------------------------------- /src/Api/OkexV5/Trade.php: -------------------------------------------------------------------------------- 1 | 4 | * */ 5 | 6 | namespace Lin\Okex\Api\OkexV5; 7 | 8 | use Lin\Okex\Request; 9 | 10 | class Trade extends Request 11 | { 12 | /** 13 | *POST /api/v5/trade/order 14 | * */ 15 | public function postOrder(array $data=[]){ 16 | $this->type='POST'; 17 | $this->path='/api/v5/trade/order'; 18 | 19 | $this->data=$data; 20 | return $this->exec(); 21 | } 22 | 23 | /** 24 | *POST /api/v5/trade/batch-orders 25 | * */ 26 | public function postBatchOrders(array $data=[]){ 27 | $this->type='POST'; 28 | $this->path='/api/v5/trade/batch-orders'; 29 | 30 | $this->data=$data; 31 | return $this->exec(); 32 | } 33 | 34 | /** 35 | *POST /api/v5/trade/cancel-order 36 | * */ 37 | public function postCancelOrder(array $data=[]){ 38 | $this->type='POST'; 39 | $this->path='/api/v5/trade/cancel-order'; 40 | 41 | $this->data=$data; 42 | return $this->exec(); 43 | } 44 | 45 | /** 46 | *POST /api/v5/trade/cancel-batch-orders 47 | * */ 48 | public function postCancelBatchOrders(array $data=[]){ 49 | $this->type='POST'; 50 | $this->path='/api/v5/trade/cancel-batch-orders'; 51 | 52 | $this->data=$data; 53 | return $this->exec(); 54 | } 55 | 56 | /** 57 | *POST /api/v5/trade/amend-order 58 | * */ 59 | public function postAmendOrder(array $data=[]){ 60 | $this->type='POST'; 61 | $this->path='/api/v5/trade/amend-order'; 62 | 63 | $this->data=$data; 64 | return $this->exec(); 65 | } 66 | 67 | /** 68 | *POST /api/v5/trade/amend-batch-orders 69 | * */ 70 | public function postAmendBatchOrders(array $data=[]){ 71 | $this->type='POST'; 72 | $this->path='/api/v5/trade/amend-batch-orders'; 73 | 74 | $this->data=$data; 75 | return $this->exec(); 76 | } 77 | 78 | /** 79 | *POST /api/v5/trade/close-position 80 | * */ 81 | public function postClosePosition(array $data=[]){ 82 | $this->type='POST'; 83 | $this->path='/api/v5/trade/close-position'; 84 | 85 | $this->data=$data; 86 | return $this->exec(); 87 | } 88 | 89 | /** 90 | *GET /api/v5/trade/order 91 | * */ 92 | public function getOrder(array $data=[]){ 93 | $this->type='GET'; 94 | $this->path='/api/v5/trade/order'; 95 | 96 | $this->data=$data; 97 | return $this->exec(); 98 | } 99 | 100 | /** 101 | *GET /api/v5/trade/orders-pending 102 | * */ 103 | public function getOrdersPending(array $data=[]){ 104 | $this->type='GET'; 105 | $this->path='/api/v5/trade/orders-pending'; 106 | 107 | $this->data=$data; 108 | return $this->exec(); 109 | } 110 | 111 | /** 112 | *GET /api/v5/trade/orders-history 113 | * */ 114 | public function getOrdersHistory(array $data=[]){ 115 | $this->type='GET'; 116 | $this->path='/api/v5/trade/orders-history'; 117 | 118 | $this->data=$data; 119 | return $this->exec(); 120 | } 121 | 122 | /** 123 | *GET /api/v5/trade/orders-history-archive 124 | * */ 125 | public function getOrdersHistoryArchive(array $data=[]){ 126 | $this->type='GET'; 127 | $this->path='/api/v5/trade/orders-history-archive'; 128 | 129 | $this->data=$data; 130 | return $this->exec(); 131 | } 132 | 133 | /** 134 | *GET /api/v5/trade/fills 135 | * */ 136 | public function getFills(array $data=[]){ 137 | $this->type='GET'; 138 | $this->path='/api/v5/trade/fills'; 139 | 140 | $this->data=$data; 141 | return $this->exec(); 142 | } 143 | 144 | /** 145 | *POST /api/v5/trade/order-algo 146 | * */ 147 | public function postOrderAlgo(array $data=[]){ 148 | $this->type='POST'; 149 | $this->path='/api/v5/trade/order-algo'; 150 | 151 | $this->data=$data; 152 | return $this->exec(); 153 | } 154 | 155 | /** 156 | *POST /api/v5/trade/cancel-algos 157 | * */ 158 | public function postCancelAlgos(array $data=[]){ 159 | $this->type='POST'; 160 | $this->path='/api/v5/trade/cancel-algos'; 161 | 162 | $this->data=$data; 163 | return $this->exec(); 164 | } 165 | 166 | /** 167 | *GET /api/v5/trade/orders-algo-pending 168 | * */ 169 | public function getOrdersAlgoPending(array $data=[]){ 170 | $this->type='GET'; 171 | $this->path='/api/v5/trade/orders-algo-pending'; 172 | 173 | $this->data=$data; 174 | return $this->exec(); 175 | } 176 | 177 | /** 178 | *GET /api/v5/trade/orders-algo-history 179 | * */ 180 | public function getOrdersAlgoHistory(array $data=[]){ 181 | $this->type='GET'; 182 | $this->path='/api/v5/trade/orders-algo-history'; 183 | 184 | $this->data=$data; 185 | return $this->exec(); 186 | } 187 | 188 | } 189 | -------------------------------------------------------------------------------- /src/Api/OptionV3/Accounts.php: -------------------------------------------------------------------------------- 1 | 4 | * */ 5 | 6 | namespace Lin\Okex\Api\OptionV3; 7 | 8 | use Lin\Okex\Request; 9 | 10 | class Accounts extends Request 11 | { 12 | /** 13 | * GET /api/option/v3/accounts/ 14 | * */ 15 | public function get(array $data=[]){ 16 | $this->type='GET'; 17 | $this->path='/api/option/v3/accounts/'.$data['underlying']; 18 | 19 | $this->data=$data; 20 | 21 | return $this->exec(); 22 | } 23 | 24 | /** 25 | * GET /api/option/v3/accounts//ledger 26 | * */ 27 | public function getLedger(array $data=[]){ 28 | $this->type='GET'; 29 | $this->path='/api/option/v3/accounts/'.$data['underlying'].'/ledger'; 30 | 31 | $this->data=$data; 32 | 33 | return $this->exec(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Api/OptionV3/Fills.php: -------------------------------------------------------------------------------- 1 | 4 | * */ 5 | 6 | namespace Lin\Okex\Api\OptionV3; 7 | 8 | use Lin\Okex\Request; 9 | 10 | class Fills extends Request 11 | { 12 | /** 13 | * GET /api/option/v3/fills/ 14 | * */ 15 | public function get(array $data=[]){ 16 | $this->type='GET'; 17 | $this->path='/api/option/v3/fills/'.$data['underlying']; 18 | 19 | $this->data=$data; 20 | 21 | return $this->exec(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Api/OptionV3/Instruments.php: -------------------------------------------------------------------------------- 1 | 4 | * */ 5 | 6 | namespace Lin\Okex\Api\OptionV3; 7 | 8 | use Lin\Okex\Request; 9 | 10 | class Instruments extends Request 11 | { 12 | /** 13 | * GET /api/option/v3/instruments/ 14 | * */ 15 | public function get(array $data=[]){ 16 | $this->type='GET'; 17 | $this->path='/api/option/v3/instruments/'.$data['underlying']; 18 | 19 | $this->data=$data; 20 | 21 | return $this->exec(); 22 | } 23 | 24 | /** 25 | * GET /api/option/v3/instruments//summary 26 | * */ 27 | public function getSummaryAll(array $data=[]){ 28 | $this->type='GET'; 29 | $this->path='/api/option/v3/instruments/'.$data['underlying'].'/summary'; 30 | 31 | $this->data=$data; 32 | 33 | return $this->exec(); 34 | } 35 | 36 | /** 37 | * GET /api/option/v3/instruments//summary/ 38 | * */ 39 | public function getAummary(array $data=[]){ 40 | $this->type='GET'; 41 | $this->path='/api/option/v3/instruments/'.$data['underlying'].'/summary/'.$data['instrument_id']; 42 | 43 | $this->data=$data; 44 | 45 | return $this->exec(); 46 | } 47 | 48 | /** 49 | * GET /api/option/v3/instruments//book 50 | * */ 51 | public function getBook(array $data=[]){ 52 | $this->type='GET'; 53 | $this->path='/api/option/v3/instruments/'.$data['instrument_id'].'/book'; 54 | 55 | $this->data=$data; 56 | 57 | return $this->exec(); 58 | } 59 | 60 | /** 61 | * GET /api/option/v3/instruments//trades 62 | * */ 63 | public function getTrades(array $data=[]){ 64 | $this->type='GET'; 65 | $this->path='/api/option/v3/instruments/'.$data['instrument_id'].'/trades'; 66 | 67 | $this->data=$data; 68 | 69 | return $this->exec(); 70 | } 71 | 72 | /** 73 | * GET /api/option/v3/instruments//ticker 74 | * */ 75 | public function getTicker(array $data=[]){ 76 | $this->type='GET'; 77 | $this->path='/api/option/v3/instruments/'.$data['instrument_id'].'/ticker'; 78 | 79 | $this->data=$data; 80 | 81 | return $this->exec(); 82 | } 83 | 84 | /** 85 | * GET /api/option/v3/instruments//candles 86 | * */ 87 | public function getCandles(array $data=[]){ 88 | $this->type='GET'; 89 | $this->path='/api/option/v3/instruments/'.$data['instrument_id'].'/candles'; 90 | 91 | $this->data=$data; 92 | 93 | return $this->exec(); 94 | } 95 | 96 | /** 97 | * GET /api/option/v3/trade_fee 98 | * */ 99 | public function getTradeFee(){ 100 | $this->type='GET'; 101 | $this->path='/api/option/v3/trade_fee'; 102 | 103 | return $this->exec(); 104 | } 105 | 106 | /** 107 | * GET /api/option/v3/underlying 108 | * */ 109 | public function getUnderlying(){ 110 | $this->type='GET'; 111 | $this->path='/api/option/v3/underlying'; 112 | 113 | return $this->exec(); 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /src/Api/OptionV3/Orders.php: -------------------------------------------------------------------------------- 1 | 4 | * */ 5 | 6 | namespace Lin\Okex\Api\OptionV3; 7 | 8 | 9 | 10 | use Lin\Okex\Request; 11 | 12 | class Orders extends Request 13 | { 14 | /** 15 | * POST /api/option/v3/order 16 | * */ 17 | public function post(array $data=[]){ 18 | $this->type='POST'; 19 | $this->path='/api/option/v3/order'; 20 | 21 | $this->data=$data; 22 | 23 | return $this->exec(); 24 | } 25 | 26 | /** 27 | * POST /api/option/v3/orders 28 | * */ 29 | public function postBatch(array $data=[]){ 30 | $this->type='POST'; 31 | $this->path='/api/option/v3/orders'; 32 | 33 | $this->data=$data; 34 | 35 | return $this->exec(); 36 | } 37 | 38 | /** 39 | * POST /api/option/v3/cancel_order// 40 | * */ 41 | public function postCancel(array $data=[]){ 42 | $id=$data['order_id'] ?? $data['client_oid']; 43 | unset($data['order_id']); 44 | unset($data['client_oid']); 45 | 46 | $this->type='POST'; 47 | $this->path='/api/option/v3/cancel_order/'.$data['underlying'].'/'.$id; 48 | 49 | $this->data=$data; 50 | 51 | return $this->exec(); 52 | } 53 | 54 | /** 55 | * POST /api/option/v3/cancel_batch_orders/ 56 | * */ 57 | public function postCancelBatch(array $data=[]){ 58 | $this->type='POST'; 59 | $this->path='/api/option/v3/cancel_batch_orders/'.$data['underlying']; 60 | 61 | $this->data=$data; 62 | 63 | return $this->exec(); 64 | } 65 | 66 | /** 67 | * 68 | * POST /api/option/v3/amend_order/ 69 | * @param array $data 70 | * @return mixed*/ 71 | public function postAmendOrder(array $data=[]){ 72 | $this->type='POST'; 73 | $this->path='/api/option/v3/amend_order/'.$data['underlying']; 74 | 75 | $this->data=$data; 76 | 77 | return $this->exec(); 78 | } 79 | 80 | /** 81 | * POST /api/option/v3/amend_batch_orders/ 82 | * */ 83 | public function postAmendBatchOrders(array $data=[]){ 84 | $this->type='POST'; 85 | $this->path='/api/option/v3/amend_batch_orders/'.$data['underlying']; 86 | 87 | $this->data=$data; 88 | 89 | return $this->exec(); 90 | } 91 | 92 | /** 93 | * GET /api/option/v3/orders// 94 | * */ 95 | public function get(array $data=[]){ 96 | $id=$data['order_id'] ?? $data['client_oid']; 97 | unset($data['order_id']); 98 | unset($data['client_oid']); 99 | 100 | $this->type='GET'; 101 | $this->path='/api/option/v3/orders/'.$data['underlying'].'/'.$id; 102 | 103 | $this->data=$data; 104 | 105 | return $this->exec(); 106 | } 107 | 108 | /** 109 | * GET /api/option/v3/orders/ 110 | * */ 111 | public function getAll(array $data=[]){ 112 | $this->type='GET'; 113 | $this->path='/api/option/v3/orders/'.$data['underlying']; 114 | 115 | $this->data=$data; 116 | 117 | return $this->exec(); 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /src/Api/OptionV3/Position.php: -------------------------------------------------------------------------------- 1 | 4 | * */ 5 | 6 | namespace Lin\Okex\Api\OptionV3; 7 | 8 | 9 | 10 | use Lin\Okex\Request; 11 | 12 | class Position extends Request 13 | { 14 | /** 15 | * GET /api/option/v3//position 16 | * */ 17 | public function get(array $data=[]){ 18 | $this->type='GET'; 19 | $this->path='/api/option/v3/'.$data['underlying'].'/position'; 20 | 21 | $this->data=$data; 22 | 23 | return $this->exec(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Api/SpotV3/Accounts.php: -------------------------------------------------------------------------------- 1 | 4 | * */ 5 | 6 | namespace Lin\Okex\Api\SpotV3; 7 | 8 | 9 | 10 | use Lin\Okex\Request; 11 | 12 | class Accounts extends Request 13 | { 14 | public function getAll(array $data=[]){ 15 | $this->type='GET'; 16 | $this->path='/api/spot/v3/accounts'; 17 | $this->data=$data; 18 | 19 | return $this->exec(); 20 | } 21 | 22 | /** 23 | 'currency'=>'BTC', required 24 | * */ 25 | public function get(array $data=[]){ 26 | $this->type='GET'; 27 | $this->path='/api/spot/v3/accounts/'.$data['currency']; 28 | unset($data['currency']); 29 | 30 | $this->data=$data; 31 | 32 | return $this->exec(); 33 | } 34 | 35 | /** 36 | * 'currency'=>'BTC', required 37 | * 'limit'=>2, optional 38 | * 'form' optional 39 | * 'to' optional 40 | * */ 41 | public function getLedger(array $data=[]){ 42 | $this->type='GET'; 43 | $this->path='/api/spot/v3/accounts/'.$data['currency'].'/ledger'; 44 | unset($data['currency']); 45 | 46 | $this->data=$data; 47 | 48 | return $this->exec(); 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /src/Api/SpotV3/Fills.php: -------------------------------------------------------------------------------- 1 | 4 | * */ 5 | 6 | namespace Lin\Okex\Api\SpotV3; 7 | 8 | use Lin\Okex\Request; 9 | 10 | class Fills extends Request 11 | { 12 | /** 13 | * GET /api/spot/v3/fills 14 | * */ 15 | public function get(array $data=[]){ 16 | $this->type='GET'; 17 | $this->path='/api/spot/v3/fills'; 18 | $this->data=$data; 19 | 20 | return $this->exec(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/Api/SpotV3/Instruments.php: -------------------------------------------------------------------------------- 1 | 4 | * */ 5 | 6 | namespace Lin\Okex\Api\SpotV3; 7 | 8 | use Lin\Okex\Request; 9 | 10 | class Instruments extends Request 11 | { 12 | /** 13 | * GET/api/spot/v3/instruments 14 | * */ 15 | public function get(array $data=[]){ 16 | $this->type='GET'; 17 | $this->path='/api/spot/v3/instruments'; 18 | $this->data=$data; 19 | 20 | return $this->exec(); 21 | } 22 | 23 | /** 24 | * GET/api/spot/v3/instruments//book 25 | * */ 26 | public function getBook(array $data=[]){ 27 | $this->type='GET'; 28 | $this->path='/api/spot/v3/instruments/'.$data['instrument_id'].'/book'; 29 | unset($data['instrument_id']); 30 | 31 | $this->data=$data; 32 | 33 | return $this->exec(); 34 | } 35 | 36 | /** 37 | * GET /api/spot/v3/instruments/ticker 38 | * */ 39 | public function getTickerAll(array $data=[]){ 40 | $this->type='GET'; 41 | $this->path='/api/spot/v3/instruments/ticker'; 42 | $this->data=$data; 43 | return $this->exec(); 44 | } 45 | 46 | /** 47 | * GET /api/spot/v3/instruments//ticker 48 | * */ 49 | public function getTicker(array $data=[]){ 50 | $this->type='GET'; 51 | $this->path='/api/spot/v3/instruments/'.$data['instrument_id'].'/ticker'; 52 | $this->data=$data; 53 | return $this->exec(); 54 | } 55 | 56 | /** 57 | *GET /api/spot/v3/instruments//trades 58 | * */ 59 | public function getTrades(array $data=[]){ 60 | $this->type='GET'; 61 | $this->path='/api/spot/v3/instruments/'.$data['instrument_id'].'/trades'; 62 | $this->data=$data; 63 | return $this->exec(); 64 | } 65 | 66 | /** 67 | *GET /api/spot/v3/instruments//candles 68 | * */ 69 | public function getCandles(array $data=[]){ 70 | $this->type='GET'; 71 | $this->path='/api/spot/v3/instruments/'.$data['instrument_id'].'/candles'; 72 | $this->data=$data; 73 | return $this->exec(); 74 | } 75 | 76 | /** 77 | *GET/api/spot/v3/instruments//history/candles 78 | * */ 79 | public function getHistoryCandles(array $data=[]){ 80 | $this->type='GET'; 81 | $this->path='/api/spot/v3/instruments/'.$data['instrument_id'].'/history/candles'; 82 | $this->data=$data; 83 | return $this->exec(); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/Api/SpotV3/Orders.php: -------------------------------------------------------------------------------- 1 | 4 | * */ 5 | 6 | namespace Lin\Okex\Api\SpotV3; 7 | 8 | use Lin\Okex\Request; 9 | 10 | class Orders extends Request 11 | { 12 | /** 13 | * POST /api/spot/v3/orders 14 | */ 15 | public function post(array $data=[]){ 16 | $this->type='POST'; 17 | $this->path='/api/spot/v3/orders'; 18 | 19 | $data['margin_trading']=1; 20 | $this->data=$data; 21 | 22 | return $this->exec(); 23 | } 24 | 25 | /** 26 | * POST /api/spot/v3/batch_orders 27 | * */ 28 | public function postBatch(array $data=[]){ 29 | $this->type='POST'; 30 | $this->path='/api/spot/v3/batch_orders'; 31 | $this->data=$data; 32 | return $this->exec(); 33 | } 34 | 35 | /** 36 | * POST /api/spot/v3/cancel_orders/ or 37 | * */ 38 | public function postCancel(array $data=[]){ 39 | $id=$data['order_id'] ?? $data['client_oid']; 40 | unset($data['order_id']); 41 | unset($data['client_oid']); 42 | 43 | $this->type='POST'; 44 | $this->path='/api/spot/v3/cancel_orders/'.$id; 45 | 46 | $this->data=$data; 47 | 48 | return $this->exec(); 49 | } 50 | 51 | /** 52 | * POST /api/spot/v3/cancel_batch_orders 53 | * */ 54 | public function postCancelBatch(array $data=[]){ 55 | $this->type='POST'; 56 | $this->path='/api/spot/v3/cancel_batch_orders'; 57 | $this->data=$data; 58 | return $this->exec(); 59 | } 60 | 61 | /** 62 | *GET /api/spot/v3/orders 63 | * */ 64 | public function getAll(array $data=[]){ 65 | $this->type='GET'; 66 | $this->path='/api/spot/v3/orders'; 67 | $this->data=$data; 68 | return $this->exec(); 69 | } 70 | 71 | /** 72 | * GET/api/spot/v3/orders_pending 73 | * */ 74 | public function getPending(array $data=[]){ 75 | $this->type='GET'; 76 | $this->path='/api/spot/v3/orders_pending'; 77 | $this->data=$data; 78 | return $this->exec(); 79 | } 80 | 81 | /** 82 | * GET/api/spot/v3/orders/ or /api/spot/v3/orders/ 83 | * */ 84 | public function get(array $data=[]){ 85 | $id=$data['order_id'] ?? ($data['client_oid'] ?? ''); 86 | unset($data['order_id']); 87 | unset($data['client_oid']); 88 | 89 | if(empty($id) && !isset($data['state'])) $data['state']=2; 90 | 91 | $this->type='GET'; 92 | $this->path='/api/spot/v3/orders/'.$id; 93 | 94 | $this->data=$data; 95 | 96 | return $this->exec(); 97 | } 98 | 99 | /** 100 | *POST /api/spot/v3/order_algo 101 | * */ 102 | public function postOrderAlgo(array $data=[]){ 103 | $this->type='POST'; 104 | $this->path='/api/spot/v3/order_algo'; 105 | $this->data=$data; 106 | return $this->exec(); 107 | } 108 | 109 | /** 110 | *POST /api/spot/v3/cancel_batch_algos 111 | * */ 112 | public function postCancelBatchAlgos(array $data=[]){ 113 | $this->type='POST'; 114 | $this->path='/api/spot/v3/cancel_batch_algos'; 115 | $this->data=$data; 116 | return $this->exec(); 117 | } 118 | 119 | /** 120 | *GET/api/spot/v3/algo 121 | * */ 122 | public function getAlgo(array $data=[]){ 123 | $this->type='GET'; 124 | $this->path='/api/spot/v3/algo'; 125 | $this->data=$data; 126 | return $this->exec(); 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /src/Api/SpotV3/Trade.php: -------------------------------------------------------------------------------- 1 | 4 | * */ 5 | 6 | namespace Lin\Okex\Api\SpotV3; 7 | 8 | use Lin\Okex\Request; 9 | 10 | class Trade extends Request 11 | { 12 | /** 13 | * GET /api/spot/v3/trade_fee 14 | * */ 15 | public function getFee(array $data=[]){ 16 | $this->type='GET'; 17 | $this->path='/api/spot/v3/trade_fee'; 18 | $this->data=$data; 19 | 20 | return $this->exec(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/Api/SwapV3/Accounts.php: -------------------------------------------------------------------------------- 1 | 4 | * */ 5 | 6 | namespace Lin\Okex\Api\SwapV3; 7 | 8 | use Lin\Okex\Request; 9 | 10 | class Accounts extends Request 11 | { 12 | /* 13 | * GET/api/swap/v3/accounts 14 | * */ 15 | public function getAll(){ 16 | $this->type='GET'; 17 | $this->path='/api/swap/v3/accounts'; 18 | 19 | return $this->exec(); 20 | } 21 | 22 | /** 23 | * GET GET /api/swap/v3//accounts 24 | * */ 25 | public function get(array $data=[]){ 26 | $this->type='GET'; 27 | $this->path='/api/swap/v3/'.$data['instrument_id'].'/accounts'; 28 | 29 | $this->data=$data; 30 | 31 | return $this->exec(); 32 | } 33 | 34 | /** 35 | * GET /api/swap/v3/accounts//settings 36 | * */ 37 | public function getSettings(array $data=[]){ 38 | $this->type='GET'; 39 | $this->path='/api/swap/v3/accounts/'.$data['instrument_id'].'/settings'; 40 | 41 | $this->data=$data; 42 | 43 | return $this->exec(); 44 | } 45 | 46 | /** 47 | * POST /api/swap/v3/accounts//leverage 48 | * */ 49 | public function postLeverage(array $data=[]){ 50 | $this->type='POST'; 51 | $this->path='/api/swap/v3/accounts/'.$data['instrument_id'].'/leverage'; 52 | 53 | $this->data=$data; 54 | 55 | return $this->exec(); 56 | } 57 | 58 | /** 59 | * GET /api/swap/v3/accounts//ledger 60 | * */ 61 | public function getLedger(array $data=[]){ 62 | $this->type='GET'; 63 | $this->path='/api/swap/v3/accounts/'.$data['instrument_id'].'/ledger'; 64 | 65 | $this->data=$data; 66 | 67 | return $this->exec(); 68 | } 69 | 70 | /** 71 | * GET /api/swap/v3/accounts//holds 72 | * */ 73 | public function getHolds(array $data=[]){ 74 | $this->type='GET'; 75 | $this->path='/api/swap/v3/accounts/'.$data['instrument_id'].'/holds'; 76 | 77 | $this->data=$data; 78 | 79 | return $this->exec(); 80 | } 81 | 82 | /* 83 | * GET/api/swap/v3/trade_fee 84 | * */ 85 | public function getRradeFee(array $data=[]){ 86 | $this->type='GET'; 87 | $this->path='/api/swap/v3/trade_fee'; 88 | 89 | $this->data=$data; 90 | 91 | return $this->exec(); 92 | } 93 | 94 | 95 | } 96 | -------------------------------------------------------------------------------- /src/Api/SwapV3/Fills.php: -------------------------------------------------------------------------------- 1 | 4 | * */ 5 | 6 | namespace Lin\Okex\Api\SwapV3; 7 | 8 | use Lin\Okex\Request; 9 | 10 | class Fills extends Request 11 | { 12 | /** 13 | * GET /api/swap/v3/fills 14 | * */ 15 | public function get(array $data=[]){ 16 | $this->type='GET'; 17 | $this->path='/api/swap/v3/fills'; 18 | 19 | return $this->exec(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/Api/SwapV3/Instruments.php: -------------------------------------------------------------------------------- 1 | 4 | * */ 5 | 6 | namespace Lin\Okex\Api\SwapV3; 7 | 8 | use Lin\Okex\Request; 9 | 10 | class Instruments extends Request 11 | { 12 | /** 13 | * GET /api/swap/v3/instruments 14 | * */ 15 | public function get(){ 16 | $this->type='GET'; 17 | $this->path='/api/swap/v3/instruments'; 18 | 19 | return $this->exec(); 20 | } 21 | 22 | /** 23 | * /api/swap/v3/instruments//depth 24 | * */ 25 | public function getDepth(array $data=[]){ 26 | $this->type='GET'; 27 | $this->path='/api/swap/v3/instruments/'.$data['instrument_id'].'/depth'; 28 | 29 | $this->data=$data; 30 | 31 | return $this->exec(); 32 | } 33 | 34 | /* 35 | * GET/api/swap/v3/instruments/ticker 36 | * */ 37 | public function getTickerAll(){ 38 | $this->type='GET'; 39 | $this->path='/api/swap/v3/instruments/ticker'; 40 | 41 | return $this->exec(); 42 | } 43 | 44 | /* 45 | * GET/api/swap/v3/instruments//ticker 46 | * */ 47 | public function getTicker(array $data=[]){ 48 | $this->type='GET'; 49 | $this->path='/api/swap/v3/instruments/'.$data['instrument_id'].'/ticker'; 50 | 51 | $this->data=$data; 52 | 53 | return $this->exec(); 54 | } 55 | 56 | /* 57 | * GET/api/swap/v3/instruments//trades 58 | * */ 59 | public function getTrades(array $data=[]){ 60 | $this->type='GET'; 61 | $this->path='/api/swap/v3/instruments/'.$data['instrument_id'].'/trades'; 62 | 63 | $this->data=$data; 64 | 65 | return $this->exec(); 66 | } 67 | 68 | /* 69 | * GET/api/swap/v3/instruments//candles 70 | * */ 71 | public function getCandles(array $data=[]){ 72 | $this->type='GET'; 73 | $this->path='/api/swap/v3/instruments/'.$data['instrument_id'].'/candles'; 74 | 75 | $this->data=$data; 76 | 77 | return $this->exec(); 78 | } 79 | 80 | /* 81 | * GET/api/swap/v3/instruments//index 82 | * */ 83 | public function getIndex(array $data=[]){ 84 | $this->type='GET'; 85 | $this->path='/api/swap/v3/instruments/'.$data['instrument_id'].'/index'; 86 | 87 | $this->data=$data; 88 | 89 | return $this->exec(); 90 | } 91 | 92 | /* 93 | * GET/api/swap/v3/rate 94 | * */ 95 | public function getRate(array $data=[]){ 96 | $this->type='GET'; 97 | $this->path='/api/swap/v3/rate'; 98 | 99 | $this->data=$data; 100 | 101 | return $this->exec(); 102 | } 103 | 104 | /* 105 | * GET/api/swap/v3/instruments//open_interest 106 | * */ 107 | public function getOpenInterest(array $data=[]){ 108 | $this->type='GET'; 109 | $this->path='/api/swap/v3/instruments/'.$data['instrument_id'].'/open_interest'; 110 | 111 | $this->data=$data; 112 | 113 | return $this->exec(); 114 | } 115 | 116 | /* 117 | * GET/api/swap/v3/instruments//price_limit 118 | * */ 119 | public function getPriceLimit(array $data=[]){ 120 | $this->type='GET'; 121 | $this->path='/api/swap/v3/instruments/'.$data['instrument_id'].'/price_limit'; 122 | 123 | $this->data=$data; 124 | 125 | return $this->exec(); 126 | } 127 | 128 | /* 129 | * GET/api/swap/v3/instruments//liquidation 130 | * */ 131 | public function getLiquidation(array $data=[]){ 132 | $this->type='GET'; 133 | $this->path='/api/swap/v3/instruments/'.$data['instrument_id'].'/liquidation'; 134 | 135 | $this->data=$data; 136 | 137 | return $this->exec(); 138 | } 139 | 140 | /* 141 | * GET/api/swap/v3/instruments//funding_time 142 | * */ 143 | public function getFundingTime(array $data=[]){ 144 | $this->type='GET'; 145 | $this->path='/api/swap/v3/instruments/'.$data['instrument_id'].'/funding_time'; 146 | 147 | $this->data=$data; 148 | 149 | return $this->exec(); 150 | } 151 | 152 | /* 153 | * GET/api/swap/v3/instruments//mark_price 154 | * */ 155 | public function getMarkPrice(array $data=[]){ 156 | $this->type='GET'; 157 | $this->path='/api/swap/v3/instruments/'.$data['instrument_id'].'/mark_price'; 158 | 159 | $this->data=$data; 160 | 161 | return $this->exec(); 162 | } 163 | 164 | /* 165 | * GET/api/swap/v3/instruments//historical_funding_rate 166 | * */ 167 | public function getHistoricalFundingRate(array $data=[]){ 168 | $this->type='GET'; 169 | $this->path='/api/swap/v3/instruments/'.$data['instrument_id'].'/historical_funding_rate'; 170 | 171 | $this->data=$data; 172 | 173 | return $this->exec(); 174 | } 175 | 176 | /* 177 | * GET/api/swap/v3/instruments//history/candles 178 | * */ 179 | public function getHistoryCandles(array $data=[]){ 180 | $this->type='GET'; 181 | $this->path='/api/swap/v3/instruments/'.$data['instrument_id'].'/history/candles'; 182 | 183 | $this->data=$data; 184 | 185 | return $this->exec(); 186 | } 187 | } 188 | -------------------------------------------------------------------------------- /src/Api/SwapV3/Orders.php: -------------------------------------------------------------------------------- 1 | 4 | * */ 5 | 6 | namespace Lin\Okex\Api\SwapV3; 7 | 8 | 9 | 10 | use Lin\Okex\Request; 11 | 12 | class Orders extends Request 13 | { 14 | /* 15 | * POST /api/swap/v3/order 16 | * */ 17 | public function post(array $data=[]){ 18 | $this->type='POST'; 19 | $this->path='/api/swap/v3/order'; 20 | 21 | $this->data=$data; 22 | 23 | return $this->exec(); 24 | } 25 | 26 | /* 27 | * POST /api/swap/v3/orders 28 | * */ 29 | public function postBatch(array $data=[]){ 30 | $this->type='POST'; 31 | $this->path='/api/swap/v3/orders'; 32 | 33 | $this->data=$data; 34 | 35 | return $this->exec(); 36 | } 37 | 38 | /* 39 | * POST /api/swap/v3/cancel_order// or 40 | * */ 41 | public function postCancel(array $data=[]){ 42 | $id=$data['order_id'] ?? $data['client_oid']; 43 | unset($data['order_id']); 44 | unset($data['client_oid']); 45 | 46 | $this->type='POST'; 47 | $this->path='/api/swap/v3/cancel_order/'.$data['instrument_id'].'/'.$id; 48 | 49 | $this->data=$data; 50 | 51 | return $this->exec(); 52 | } 53 | 54 | /* 55 | * POST /api/swap/v3/cancel_batch_orders/ 56 | * */ 57 | public function postCancelBatch(array $data=[]){ 58 | $this->type='POST'; 59 | $this->path='/api/swap/v3/cancel_batch_orders/'.$data['instrument_id']; 60 | 61 | $this->data=$data; 62 | 63 | return $this->exec(); 64 | } 65 | 66 | /* 67 | *POST/api/swap/v3/amend_order/ 68 | * */ 69 | public function postAmend(array $data=[]){ 70 | $this->type='POST'; 71 | $this->path='/api/swap/v3/amend_order/'.$data['instrument_id']; 72 | 73 | $this->data=$data; 74 | 75 | return $this->exec(); 76 | } 77 | 78 | /* 79 | *POST/api/swap/v3/amend_batch_orders/ 80 | * */ 81 | public function postAmendBatch(array $data=[]){ 82 | $this->type='POST'; 83 | $this->path='/api/swap/v3/amend_batch_orders/'.$data['instrument_id']; 84 | 85 | $this->data=$data; 86 | 87 | return $this->exec(); 88 | } 89 | 90 | /* 91 | * GET/api/swap/v3/orders/ 92 | * */ 93 | public function getAll(array $data=[]){ 94 | $this->type='GET'; 95 | $this->path='/api/swap/v3/orders/'.$data['instrument_id']; 96 | 97 | $this->data=$data; 98 | 99 | return $this->exec(); 100 | } 101 | 102 | /* 103 | * GET/api/swap/v3/orders// 104 | * GET/api/swap/v3/orders// 105 | * */ 106 | public function get(array $data=[]){ 107 | $id=$data['order_id'] ?? $data['client_oid']; 108 | unset($data['order_id']); 109 | unset($data['client_oid']); 110 | 111 | $this->type='GET'; 112 | $this->path='/api/swap/v3/orders/'.$data['instrument_id'].'/'.$id; 113 | 114 | $this->data=$data; 115 | 116 | return $this->exec(); 117 | } 118 | 119 | /** 120 | *POST /api/swap/v3/order_algo 121 | * */ 122 | public function postOrderAlgo(array $data=[]){ 123 | $this->type='POST'; 124 | $this->path='/api/swap/v3/order_algo'; 125 | $this->data=$data; 126 | return $this->exec(); 127 | } 128 | 129 | /** 130 | *POST /api/swap/v3/cancel_algos 131 | * */ 132 | public function postCancelAlgos(array $data=[]){ 133 | $this->type='POST'; 134 | $this->path='/api/swap/v3/cancel_algos'; 135 | $this->data=$data; 136 | return $this->exec(); 137 | } 138 | 139 | /** 140 | *GET/api/swap/v3/order_algo/ 141 | * */ 142 | public function getOrderAlgo(array $data=[]){ 143 | $this->type='GET'; 144 | $this->path='/api/swap/v3/order_algo/'.$data['instrument_id']; 145 | $this->data=$data; 146 | return $this->exec(); 147 | } 148 | 149 | /** 150 | *POST /api/swap/v3/cancel_all 151 | * */ 152 | public function postCancelAll(array $data=[]){ 153 | $this->type='POST'; 154 | $this->path='/api/swap/v3/cancel_all'; 155 | $this->data=$data; 156 | return $this->exec(); 157 | } 158 | } 159 | -------------------------------------------------------------------------------- /src/Api/SwapV3/Position.php: -------------------------------------------------------------------------------- 1 | 4 | * */ 5 | 6 | namespace Lin\Okex\Api\SwapV3; 7 | 8 | 9 | 10 | use Lin\Okex\Request; 11 | 12 | class Position extends Request 13 | { 14 | /* 15 | * GET/api/swap/v3/position 16 | * */ 17 | public function getAll(){ 18 | $this->type='GET'; 19 | $this->path='/api/swap/v3/position'; 20 | 21 | return $this->exec(); 22 | } 23 | 24 | /* 25 | * GET/api/swap/v3//position 26 | * */ 27 | public function get(array $data=[]){ 28 | $this->type='GET'; 29 | $this->path='/api/swap/v3/'.$data['instrument_id'].'/position'; 30 | 31 | $this->data=$data; 32 | 33 | return $this->exec(); 34 | } 35 | 36 | /* 37 | * POST/api/swap/v3/close_position 38 | * */ 39 | public function postClose(array $data=[]){ 40 | $this->type='POST'; 41 | $this->path='/api/swap/v3/close_position'; 42 | 43 | $this->data=$data; 44 | 45 | return $this->exec(); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/Api/WebSocketV3/SocketClient.php: -------------------------------------------------------------------------------- 1 | 4 | * */ 5 | 6 | namespace Lin\Okex\Api\WebSocketV3; 7 | 8 | use Lin\Okex\Api\WebSocketV3\SocketGlobal; 9 | use Lin\Okex\Api\WebSocketV3\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 | 21 | 22 | function __construct(array $config=[]) 23 | { 24 | $this->config=$config; 25 | 26 | $this->client(); 27 | 28 | $this->init(); 29 | } 30 | 31 | protected function init(){ 32 | //初始化全局变量 33 | $this->add('global_key',[]);//保存全局变量key 34 | 35 | $this->add('all_sub',[]);//目前总共订阅的频道 36 | 37 | $this->add('add_sub',[]);//正在订阅的频道 38 | 39 | $this->add('del_sub',[]);//正在删除的频道 40 | 41 | $this->add('keysecret',[]);//目前总共key 42 | 43 | $this->add('global_local',[]);//临时存储数据 44 | 45 | $this->add('debug',[]); 46 | } 47 | 48 | function keysecret(array $keysecret=[]){ 49 | $this->keysecret=$keysecret; 50 | 51 | $this->keysecretInit($this->keysecret); 52 | 53 | return $this; 54 | } 55 | 56 | /** 57 | * @param array $sub 58 | */ 59 | public function subscribe(array $sub=[]){ 60 | $add_sub=$this->get('add_sub'); 61 | if(empty($add_sub)) $this->save('add_sub',$this->resub($sub)); 62 | else $this->save('add_sub',array_merge($this->resub($sub),$add_sub)); 63 | } 64 | 65 | /** 66 | * @param array $sub 67 | */ 68 | public function unsubscribe(array $sub=[]){ 69 | $this->save('del_sub',$this->resub($sub)); 70 | } 71 | 72 | /** 73 | * @param array $sub 默认获取所有public订阅的数据,private数据需要设置keysecret 74 | * @param null $callback 75 | * @param bool $daemon 76 | * @return mixed 77 | */ 78 | public function getSubscribe(array $sub,$callback=null,$daemon=false){ 79 | if($daemon) $this->daemon($callback,$sub); 80 | 81 | $sub=$this->resub($sub); 82 | 83 | return $this->getData($this,$callback,$sub); 84 | } 85 | 86 | /** 87 | * 返回订阅的所有数据 88 | * @param null $callback 89 | * @param bool $daemon 90 | * @return array 91 | */ 92 | public function getSubscribes($callback=null,$daemon=false){ 93 | if($daemon) $this->daemon($callback); 94 | 95 | return $this->getData($this,$callback); 96 | } 97 | 98 | protected function daemon($callback=null,$sub=[]){ 99 | $worker = new Worker(); 100 | $worker->onWorkerStart = function() use($callback,$sub) { 101 | $global = $this->client(); 102 | 103 | $time=isset($this->config['data_time']) ? $this->config['data_time'] : 0.1 ; 104 | 105 | $sub=$this->resub($sub); 106 | 107 | Timer::add($time, function() use ($global,$callback,$sub){ 108 | $this->getData($global,$callback,$sub); 109 | }); 110 | }; 111 | Worker::runAll(); 112 | } 113 | 114 | /** 115 | * @param $global 116 | * @param null $callback 117 | * @param array $sub 返回规定的频道 118 | * @return array 119 | */ 120 | protected function getData($global,$callback=null,$sub=[]){ 121 | $all_sub=$global->get('all_sub'); 122 | if(empty($all_sub)) return []; 123 | 124 | $global_local=$global->get('global_local'); 125 | $temp=[]; 126 | 127 | //默认返回所有数据 128 | if(empty($sub)){ 129 | foreach ($all_sub as $k=>$v){ 130 | if(is_array($v)){ 131 | if(empty($this->keysecret) || $this->keysecret['key']!=$v[1]['key']) continue; 132 | 133 | $table=$this->userKey($v[1],$v[0]); 134 | $data=$global->getQueue(strtolower($table)); 135 | $temp[strtolower($table)]=$data; 136 | }else{ 137 | //$data=$global->get(strtolower($v)); 138 | //$temp[strtolower($v)]=$data; 139 | $k_strtolower=strtolower($v); 140 | if(isset($global_local['public'][$k_strtolower])) $temp[$k_strtolower]=$global_local['public'][$k_strtolower]; 141 | } 142 | } 143 | }else{ 144 | //返回规定的数据 145 | if(!empty($this->keysecret)) { 146 | //是否有私有数据 147 | if(isset($all_sub[$this->keysecret['key']])) $sub=array_merge($sub,$all_sub[$this->keysecret['key']]); 148 | } 149 | 150 | /*print_r($sub); 151 | die;*/ 152 | foreach ($sub as $k=>$v){ 153 | if(count($v)==1) { 154 | $table=$v[0]; 155 | //$data=$global->get(strtolower($table)); 156 | $data=$global_local['public'][strtolower($table)]; 157 | } else { 158 | //判断私有数据是否需要走队列数据 159 | //$temp_v=explode(self::$USER_DELIMITER,$v); 160 | $table=$this->userKey($v[1],$v[0]); 161 | $data=$global->getQueue(strtolower($table)); 162 | } 163 | 164 | if(empty($data)) continue; 165 | 166 | $temp[$table]=$data; 167 | } 168 | } 169 | 170 | if($callback!==null){ 171 | call_user_func_array($callback, array($temp)); 172 | } 173 | 174 | return $temp; 175 | } 176 | 177 | /* 178 | * 179 | * */ 180 | function reconPrivate(string $key){ 181 | $debug=$this->client->debug; 182 | if(empty($debug)){ 183 | $this->client->debug=[ 184 | 'private'=>[$key=>$key], 185 | ]; 186 | }else{ 187 | $this->client->debug=['private'=>array_merge($this->client->debug['private'],[$key=>$key])]; 188 | } 189 | } 190 | 191 | function reconPublic(){ 192 | $this->client->debug=[ 193 | 'public'=>['public'=>'close'], 194 | ]; 195 | } 196 | 197 | function test(){ 198 | print_r($this->client->all_sub); 199 | print_r($this->client->add_sub); 200 | print_r($this->client->del_sub); 201 | print_r($this->client->keysecret); 202 | print_r($this->client->global_key); 203 | } 204 | 205 | function test2(){ 206 | $global_key=$this->client->global_key; 207 | foreach ($global_key as $k=>$v){ 208 | echo count($this->client->$v).'----'.$k.PHP_EOL; 209 | echo json_encode($this->client->$v).PHP_EOL; 210 | } 211 | } 212 | 213 | function test_reconnection2(){ 214 | $this->client->debug2=1; 215 | } 216 | } 217 | -------------------------------------------------------------------------------- /src/Api/WebSocketV3/SocketFunction.php: -------------------------------------------------------------------------------- 1 | 4 | * */ 5 | 6 | namespace Lin\Okex\Api\WebSocketV3; 7 | 8 | 9 | trait SocketFunction 10 | { 11 | //标记分隔符 12 | static $USER_DELIMITER='==='; 13 | 14 | //对数据轮询 获取当前数据的订阅ID 15 | protected function getInstrumentId(array $array){ 16 | if(isset($array['currency'])) return $array['currency']; 17 | if(isset($array['instrument_id'])) return $array['instrument_id']; 18 | 19 | foreach ($array as $v){ 20 | if(is_array($v)) { 21 | $rlt=$this->getInstrumentId($v); 22 | if(!empty($rlt)) return $rlt; 23 | } 24 | } 25 | 26 | return ; 27 | } 28 | 29 | /** 30 | * 标记订阅的频道是否需要有登陆的KEY 31 | */ 32 | protected function resub(array $sub=[]){ 33 | $new_sub=[]; 34 | $temp1=['account','position','order']; 35 | foreach ($sub as $v) { 36 | $temp2=[$v]; 37 | foreach ($temp1 as $tv){ 38 | if(strpos($v, $tv) !== false){ 39 | array_push($temp2,empty($this->keysecret)? [] : $this->keysecret); 40 | } 41 | } 42 | array_push($new_sub,$temp2); 43 | } 44 | 45 | return $new_sub; 46 | } 47 | 48 | /** 49 | * @param $global 50 | * @param $tag 51 | * @param $data 52 | * @param string $keysecret 53 | */ 54 | protected function errorMessage($global,$tag,$data,$keysecret=''){ 55 | $all_sub=$global->get('all_sub'); 56 | if(empty($all_sub)) return; 57 | 58 | if($tag=='public') { 59 | //查询 message 是否包含了关键词。并把错误信息写入频道记录 60 | foreach ($all_sub as $k=>$v){ 61 | if(is_array($v)) continue; 62 | $sub=strtolower($v); 63 | if(stristr(strtolower($data['message']),$v)!==false) $global->save($sub,$data); 64 | } 65 | }else{ 66 | //如果是用户单独订阅,则该用户所有相关的订阅都显示该错误 67 | /*foreach ($all_sub as $k=>$v){ 68 | if(!is_array($v)) continue; 69 | $sub=strtolower($v[0]); 70 | $global->add($keysecret['key'].$sub,$data); 71 | }*/ 72 | } 73 | } 74 | 75 | protected function log($message){ 76 | if (!is_string($message)) $message=json_encode($message); 77 | 78 | $time=time(); 79 | $tiemdate=date('Y-m-d H:i:s',$time); 80 | 81 | $message=$tiemdate.' '.$message.PHP_EOL; 82 | 83 | if(isset($this->config['log'])){ 84 | if(is_array($this->config['log']) && isset($this->config['log']['filename'])){ 85 | $filename=$this->config['log']['filename'].'-'.date('Y-m-d',$time).'.txt'; 86 | }else{ 87 | $filename=date('Y-m-d',$time).'.txt'; 88 | } 89 | 90 | file_put_contents($filename,$message,FILE_APPEND); 91 | } 92 | 93 | echo $message; 94 | } 95 | 96 | /** 97 | * 设置用户key 98 | * @param $keysecret 99 | */ 100 | protected function userKey(array $keysecret,string $sub){ 101 | return $keysecret['key'].self::$USER_DELIMITER.$sub; 102 | } 103 | 104 | /** 105 | * 重新订阅 106 | */ 107 | private function reconnection($global,$type='public',array $keysecret=[]){ 108 | $all_sub=$global->get('all_sub'); 109 | if(empty($all_sub)) return; 110 | 111 | if($type=='public'){ 112 | $temp=[]; 113 | foreach ($all_sub as $v){ 114 | if(!is_array($v)) $temp[]=$v; 115 | } 116 | }else{ 117 | $this->keysecret=$keysecret; 118 | 119 | $temp=[]; 120 | foreach ($all_sub as $v){ 121 | if(is_array($v) && $keysecret['key']==$v[1]['key']){ 122 | $temp[]=$v[0]; 123 | } 124 | } 125 | } 126 | 127 | $add_sub=$global->get('add_sub'); 128 | if(empty($add_sub)) $global->save('add_sub',$this->resub($temp)); 129 | else $global->save('add_sub',array_merge($this->resub($temp),$add_sub)); 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /src/Api/WebSocketV3/SocketGlobal.php: -------------------------------------------------------------------------------- 1 | 4 | * */ 5 | 6 | namespace Lin\Okex\Api\WebSocketV3; 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 | protected function server(){ 19 | $address=isset($this->config['global']) ? explode(':',$this->config['global']) : ['0.0.0.0','2207']; 20 | $this->server=new Server($address[0],$address[1]); 21 | return $this; 22 | } 23 | 24 | protected function client(){ 25 | $address=isset($this->config['global']) ? $this->config['global'] : '0.0.0.0:2207'; 26 | $this->client=new Client($address); 27 | return $this; 28 | } 29 | 30 | protected function add($key,$value){ 31 | $this->client->add($key,$value); 32 | 33 | $this->saveGlobalKey($key); 34 | } 35 | 36 | protected function get($key){ 37 | if(!isset($this->client->$key) || empty($this->client->$key)) return []; 38 | return $this->client->$key; 39 | } 40 | 41 | protected function save($key,$value){ 42 | if(!isset($this->client->$key)) $this->add($key,$value); 43 | else $this->client->$key=$value; 44 | } 45 | 46 | /** 47 | * 对了获取数据 48 | * @param $key 49 | * @return array 50 | */ 51 | protected function getQueue($key){ 52 | if(!isset($this->client->$key) || empty($this->client->$key)) return []; 53 | 54 | do{ 55 | $old_value=$new_value=$this->client->$key; 56 | 57 | if(empty($new_value)) return []; 58 | //队列先进先出。 59 | $value=array_shift($new_value); 60 | } 61 | while(!$this->client->cas($key, $old_value, $new_value)); 62 | 63 | return $value; 64 | } 65 | 66 | /** 67 | * 队列保存数据 68 | * @param $key 69 | * @param $value 70 | */ 71 | protected function saveQueue($key,$value){ 72 | //最大存储数据量,超过后保留一条最新的数据,其余数据全部删除。 73 | $max= isset($this->config['queue_count']) ? $this->config['queue_count'] : 100; 74 | 75 | if(!isset($this->client->$key)) $this->add($key,[$value]); 76 | else { 77 | do{ 78 | $old_value=$new_value=$this->client->$key; 79 | 80 | //超过最大数据量,保留最新数据 81 | if(count($new_value)>$max){ 82 | $new_value=[$value]; 83 | }else{ 84 | array_push($new_value,$value); 85 | } 86 | } 87 | while(!$this->client->cas($key, $old_value, $new_value)); 88 | } 89 | } 90 | 91 | protected function addSubUpdate($type='public',$data=[]){ 92 | do{ 93 | $old_value=$new_value=$this->client->add_sub; 94 | foreach ($new_value as $k=>$v){ 95 | if($type=='public' && count($v)==1) unset($new_value[$k]); 96 | if($type=='private') { 97 | //添加的频道必须当前用户 98 | $key=$v[1]['key']; 99 | if(count($v)>1 && $key==$data['user_key']) unset($new_value[$k]); 100 | } 101 | } 102 | } 103 | while(!$this->client->cas('add_sub', $old_value, $new_value)); 104 | } 105 | 106 | protected function delSubUpdate($type='public',$data=[]){ 107 | do{ 108 | $old_value=$new_value=$this->client->del_sub; 109 | foreach ($new_value as $k=>$v){ 110 | if($type=='public' && count($v)==1) unset($new_value[$k]); 111 | if($type=='private') { 112 | //添加的频道必须当前用户 113 | $key=$v[1]['key']; 114 | if(count($v)>1 && $key==$data['user_key']) unset($new_value[$k]); 115 | } 116 | } 117 | } 118 | while(!$this->client->cas('del_sub', $old_value, $new_value)); 119 | } 120 | 121 | protected function allSubUpdate($type='public',$data=[]){ 122 | do{ 123 | $old_value=$new_value=$this->client->all_sub; 124 | foreach ($data['sub'] as $v){ 125 | if($type=='public') $key=$v; 126 | if($type=='private') $key=$v[1]['key'].self::$USER_DELIMITER.$v[0]; 127 | $new_value[$key]=$v; 128 | } 129 | } 130 | while(!$this->client->cas('all_sub', $old_value, $new_value)); 131 | } 132 | 133 | protected function unAllSubUpdate($type='public',$data=[]){ 134 | do{ 135 | $old_value=$new_value=$this->client->all_sub; 136 | foreach ($data['sub'] as $v){ 137 | if($type=='public') unset($new_value[$v]); 138 | if($type=='private') unset($new_value[$v[1]['key'].$v[0]]); 139 | } 140 | } 141 | while(!$this->client->cas('all_sub', $old_value, $new_value)); 142 | } 143 | 144 | protected function keysecretUpdate($key,$login=0){ 145 | do{ 146 | $old_client_keysecret=$new_client_keysecret=$this->client->keysecret; 147 | $new_client_keysecret[$key]['login']=$login; 148 | } 149 | while(!$this->client->cas('keysecret', $old_client_keysecret, $new_client_keysecret)); 150 | } 151 | 152 | protected function keysecretInit($keysecret){ 153 | do { 154 | $old_value = $new_value = $this->client->keysecret; 155 | 156 | if(!isset($new_value[$keysecret['key']])) { 157 | $new_value[$keysecret['key']]=$keysecret; 158 | $new_value[$keysecret['key']]['login']=0; 159 | } 160 | } 161 | while(!$this->client->cas('keysecret', $old_value, $new_value)); 162 | } 163 | 164 | protected function saveGlobalKey($key){ 165 | do { 166 | $old_value = $new_value = $this->client->global_key; 167 | $new_value[$key]=$key; 168 | } 169 | while(!$this->client->cas('global_key', $old_value, $new_value)); 170 | } 171 | } 172 | -------------------------------------------------------------------------------- /src/Api/WebSocketV5/SocketClient.php: -------------------------------------------------------------------------------- 1 | 4 | * */ 5 | 6 | namespace Lin\Okex\Api\WebSocketV5; 7 | 8 | use Lin\Okex\Api\WebSocketV5\SocketGlobal; 9 | use Lin\Okex\Api\WebSocketV5\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 | 21 | 22 | function __construct(array $config=[]) 23 | { 24 | $this->config=$config; 25 | 26 | $this->client(); 27 | 28 | $this->init(); 29 | } 30 | 31 | protected function init(){ 32 | //初始化全局变量 33 | $this->add('global_key',[]);//保存全局变量key 34 | 35 | $this->add('all_sub',[]);//目前总共订阅的频道 36 | 37 | $this->add('add_sub',[]);//正在订阅的频道 38 | 39 | $this->add('del_sub',[]);//正在删除的频道 40 | 41 | $this->add('keysecret',[]);//目前总共key 42 | 43 | $this->add('global_local',[]);//临时存储数据 44 | 45 | $this->add('debug',[]); 46 | } 47 | 48 | function keysecret(array $keysecret=[]){ 49 | $this->keysecret=$keysecret; 50 | 51 | $this->keysecretInit($this->keysecret); 52 | 53 | return $this; 54 | } 55 | 56 | /** 57 | * @param array $sub 58 | */ 59 | public function subscribe(array $sub=[]){ 60 | $add_sub=$this->get('add_sub'); 61 | if(empty($add_sub)) $this->save('add_sub',$this->resub($sub)); 62 | else $this->save('add_sub',array_merge($this->resub($sub),$add_sub)); 63 | } 64 | 65 | /** 66 | * @param array $sub 67 | */ 68 | public function unsubscribe(array $sub=[]){ 69 | $this->save('del_sub',$this->resub($sub)); 70 | } 71 | 72 | /** 73 | * @param array $sub 默认获取所有public订阅的数据,private数据需要设置keysecret 74 | * @param null $callback 75 | * @param bool $daemon 76 | * @return mixed 77 | */ 78 | public function getSubscribe(array $sub,$callback=null,$daemon=false){ 79 | if($daemon) $this->daemon($callback,$sub); 80 | 81 | $sub=$this->resub($sub); 82 | 83 | return $this->getData($this,$callback,$sub); 84 | } 85 | 86 | /** 87 | * 返回订阅的所有数据 88 | * @param null $callback 89 | * @param bool $daemon 90 | * @return array 91 | */ 92 | public function getSubscribes($callback=null,$daemon=false){ 93 | if($daemon) $this->daemon($callback); 94 | 95 | return $this->getData($this,$callback); 96 | } 97 | 98 | protected function daemon($callback=null,$sub=[]){ 99 | $worker = new Worker(); 100 | $worker->onWorkerStart = function() use($callback,$sub) { 101 | $global = $this->client(); 102 | 103 | $time=isset($this->config['data_time']) ? $this->config['data_time'] : 0.1 ; 104 | 105 | $sub=$this->resub($sub); 106 | 107 | Timer::add($time, function() use ($global,$callback,$sub){ 108 | $this->getData($global,$callback,$sub); 109 | }); 110 | }; 111 | Worker::runAll(); 112 | } 113 | 114 | /** 115 | * @param $global 116 | * @param null $callback 117 | * @param array $sub 返回规定的频道 118 | * @return array 119 | */ 120 | protected function getData($global,$callback=null,$sub=[]){ 121 | $all_sub=$global->get('all_sub'); 122 | if(empty($all_sub)) return []; 123 | 124 | $global_local=$global->get('global_local'); 125 | $temp=[]; 126 | 127 | //默认返回所有数据 128 | if(empty($sub)){ 129 | foreach ($all_sub as $k=>$v){ 130 | $is_array=explode(self::$USER_DELIMITER,$k); 131 | if(count($is_array)>1){ 132 | /*[xxxxx-xxxxx-xxxxx==={"channel":"orders-algo","instType":"FUTURES","uly":"BTC-USD","instId":"BTC-USD-210924"}] => Array 133 | ( 134 | [channel] => orders-algo 135 | [instType] => FUTURES 136 | [uly] => BTC-USD 137 | [instId] => BTC-USD-210924 138 | )*/ 139 | //是否是当前用户获取数据 140 | if(empty($this->keysecret) || $this->keysecret['key']!=$is_array[0]) continue; 141 | 142 | $data=$global->getQueue($k); 143 | $temp[$k]=$data; 144 | }else{ 145 | /*[{"channel":"candle5m","instId":"BTC-USDT"}] => Array 146 | ( 147 | [channel] => candle5m 148 | [instId] => BTC-USDT 149 | )*/ 150 | 151 | //$data=$global->get($k); 152 | if(!isset($global_local['public'][$k])) continue; 153 | 154 | $data=$global_local['public'][$k]; 155 | $temp[$k]=$data; 156 | } 157 | } 158 | }else{ 159 | //print_r($sub); 160 | foreach ($sub as $k=>$v){ 161 | if(!array_key_exists('key',$v)){ 162 | $table=json_encode($v); 163 | //$data=$global->get($table); 164 | $data=$global_local['public'][$table]; 165 | } else { 166 | $keysecret=[ 167 | 'key'=>$v['key'], 168 | ]; 169 | unset($v['key']); 170 | $table=$this->userKey($keysecret,json_encode($v)); 171 | $data=$global->getQueue($table); 172 | } 173 | 174 | if(empty($data)) continue; 175 | $temp[$table]=$data; 176 | } 177 | } 178 | 179 | if($callback!==null){ 180 | call_user_func_array($callback, array($temp)); 181 | } 182 | 183 | return $temp; 184 | } 185 | 186 | /* 187 | * 188 | * */ 189 | function reconPrivate(string $key){ 190 | $debug=$this->client->debug; 191 | if(empty($debug)){ 192 | $this->client->debug=[ 193 | 'private'=>[$key=>$key], 194 | ]; 195 | }else{ 196 | $this->client->debug=['private'=>array_merge($this->client->debug['private'],[$key=>$key])]; 197 | } 198 | } 199 | 200 | function reconPublic(){ 201 | $this->client->debug=[ 202 | 'public'=>['public'=>'close'], 203 | ]; 204 | } 205 | 206 | function test(){ 207 | echo 'all_sub'.PHP_EOL; 208 | print_r($this->client->all_sub); 209 | echo 'add_sub'.PHP_EOL; 210 | print_r($this->client->add_sub); 211 | echo 'del_sub'.PHP_EOL; 212 | print_r($this->client->del_sub); 213 | echo 'keysecret'.PHP_EOL; 214 | print_r($this->client->keysecret); 215 | echo 'global_key'.PHP_EOL; 216 | print_r($this->client->global_key); 217 | } 218 | 219 | function test2(){ 220 | $global_key=$this->client->global_key; 221 | foreach ($global_key as $k=>$v){ 222 | echo count($this->client->$v).'----'.$k.PHP_EOL; 223 | echo json_encode($this->client->$v).PHP_EOL; 224 | } 225 | } 226 | 227 | function test_reconnection2(){ 228 | $this->client->debug2=1; 229 | } 230 | } 231 | -------------------------------------------------------------------------------- /src/Api/WebSocketV5/SocketFunction.php: -------------------------------------------------------------------------------- 1 | 4 | * */ 5 | 6 | namespace Lin\Okex\Api\WebSocketV5; 7 | 8 | 9 | trait SocketFunction 10 | { 11 | //标记分隔符 12 | static $USER_DELIMITER='==='; 13 | 14 | /** 15 | * 标记订阅的频道是否需要有登陆的KEY 16 | */ 17 | protected function resub(array $sub=[]){ 18 | $new_sub=[]; 19 | $temp1=['account','positions','balance_and_position','orders','orders-algo']; 20 | 21 | foreach ($sub as $v) { 22 | foreach ($temp1 as $tv){ 23 | if(strpos($v['channel'], $tv) !== false && !empty($this->keysecret)){ 24 | $v['key']=$this->keysecret['key']; 25 | } 26 | } 27 | array_push($new_sub,$v); 28 | } 29 | 30 | return $new_sub; 31 | } 32 | 33 | /** 34 | * @param $global 35 | * @param $tag 36 | * @param $data 37 | * @param string $keysecret 38 | */ 39 | protected function errorMessage($global,$tag,$data,$keysecret=''){ 40 | $all_sub=$global->get('all_sub'); 41 | if(empty($all_sub)) return; 42 | 43 | if($tag=='public') { 44 | //查询 message 是否包含了关键词。并把错误信息写入频道记录 45 | foreach ($all_sub as $k=>$v){ 46 | if(is_array($v)) continue; 47 | $sub=strtolower($v); 48 | if(stristr(strtolower($data['message']),$v)!==false) $global->save($sub,$data); 49 | } 50 | }else{ 51 | //如果是用户单独订阅,则该用户所有相关的订阅都显示该错误 52 | /*foreach ($all_sub as $k=>$v){ 53 | if(!is_array($v)) continue; 54 | $sub=strtolower($v[0]); 55 | $global->add($keysecret['key'].$sub,$data); 56 | }*/ 57 | } 58 | } 59 | 60 | protected function log($message){ 61 | if (!is_string($message)) $message=json_encode($message); 62 | 63 | $time=time(); 64 | $tiemdate=date('Y-m-d H:i:s',$time); 65 | 66 | $message=$tiemdate.' '.$message.PHP_EOL; 67 | 68 | if(isset($this->config['log'])){ 69 | if(is_array($this->config['log']) && isset($this->config['log']['filename'])){ 70 | $filename=$this->config['log']['filename'].'-'.date('Y-m-d',$time).'.txt'; 71 | }else{ 72 | $filename=date('Y-m-d',$time).'.txt'; 73 | } 74 | 75 | file_put_contents($filename,$message,FILE_APPEND); 76 | } 77 | 78 | echo $message; 79 | } 80 | 81 | /** 82 | * 设置用户key 83 | * @param $keysecret 84 | */ 85 | protected function userKey(array $keysecret,string $sub){ 86 | return $keysecret['key'].self::$USER_DELIMITER.$sub; 87 | } 88 | 89 | /** 90 | * 重新订阅 91 | */ 92 | private function reconnection($global,$type='public',array $keysecret=[]){ 93 | $all_sub=$global->get('all_sub'); 94 | if(empty($all_sub)) return; 95 | 96 | if($type=='public'){ 97 | $temp=[]; 98 | foreach ($all_sub as $v){ 99 | $temp[]=$v; 100 | } 101 | }else{ 102 | $this->keysecret=$keysecret; 103 | 104 | $temp=[]; 105 | foreach ($all_sub as $k=>$v){ 106 | $t=explode(self::$USER_DELIMITER,$k); 107 | if(count($t)>1 && $t[0]==$keysecret['key']) { 108 | $temp[]=$v; 109 | } 110 | } 111 | } 112 | 113 | $add_sub=$global->get('add_sub'); 114 | if(empty($add_sub)) $global->save('add_sub',$this->resub($temp)); 115 | else $global->save('add_sub',array_merge($this->resub($temp),$add_sub)); 116 | } 117 | 118 | } 119 | -------------------------------------------------------------------------------- /src/Api/WebSocketV5/SocketGlobal.php: -------------------------------------------------------------------------------- 1 | 4 | * */ 5 | 6 | namespace Lin\Okex\Api\WebSocketV5; 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 | protected function server(){ 19 | $address=isset($this->config['global']) ? explode(':',$this->config['global']) : ['0.0.0.0','22075']; 20 | $this->server=new Server($address[0],$address[1]); 21 | return $this; 22 | } 23 | 24 | protected function client(){ 25 | $address=isset($this->config['global']) ? $this->config['global'] : '0.0.0.0:22075'; 26 | $this->client=new Client($address); 27 | return $this; 28 | } 29 | 30 | protected function add($key,$value){ 31 | $this->client->add($key,$value); 32 | 33 | $this->saveGlobalKey($key); 34 | } 35 | 36 | protected function get($key){ 37 | if(!isset($this->client->$key) || empty($this->client->$key)) return []; 38 | return $this->client->$key; 39 | } 40 | 41 | protected function save($key,$value){ 42 | if(!isset($this->client->$key)) $this->add($key,$value); 43 | else $this->client->$key=$value; 44 | } 45 | 46 | /** 47 | * 对了获取数据 48 | * @param $key 49 | * @return array 50 | */ 51 | protected function getQueue($key){ 52 | if(!isset($this->client->$key) || empty($this->client->$key)) return []; 53 | 54 | do{ 55 | $old_value=$new_value=$this->client->$key; 56 | 57 | if(empty($new_value)) return []; 58 | //队列先进先出。 59 | $value=array_shift($new_value); 60 | } 61 | while(!$this->client->cas($key, $old_value, $new_value)); 62 | 63 | return $value; 64 | } 65 | 66 | /** 67 | * 队列保存数据 68 | * @param $key 69 | * @param $value 70 | */ 71 | protected function saveQueue($key,$value){ 72 | //最大存储数据量,超过后保留一条最新的数据,其余数据全部删除。 73 | $max= isset($this->config['queue_count']) ? $this->config['queue_count'] : 100; 74 | 75 | if(!isset($this->client->$key)) $this->add($key,[$value]); 76 | else { 77 | do{ 78 | $old_value=$new_value=$this->client->$key; 79 | 80 | //超过最大数据量,保留最新数据 81 | if(count($new_value)>$max){ 82 | $new_value=[$value]; 83 | }else{ 84 | array_push($new_value,$value); 85 | } 86 | } 87 | while(!$this->client->cas($key, $old_value, $new_value)); 88 | } 89 | } 90 | 91 | protected function addSubUpdate($type='public',$data=[]){ 92 | do{ 93 | $old_value=$new_value=$this->client->add_sub; 94 | foreach ($new_value as $k=>$v){ 95 | if($type=='public' && !array_key_exists('key',$v)) unset($new_value[$k]); 96 | if($type=='private') { 97 | //添加的频道必须当前用户 98 | $key=$v['key']; 99 | if(array_key_exists('key',$v) && $key==$data['user_key']) unset($new_value[$k]); 100 | } 101 | } 102 | } 103 | while(!$this->client->cas('add_sub', $old_value, $new_value)); 104 | } 105 | 106 | protected function delSubUpdate($type='public',$data=[]){ 107 | do{ 108 | $old_value=$new_value=$this->client->del_sub; 109 | foreach ($new_value as $k=>$v){ 110 | if($type=='public' && !array_key_exists('key',$v)) unset($new_value[$k]); 111 | if($type=='private') { 112 | //添加的频道必须当前用户 113 | $key=$v['key']; 114 | if(array_key_exists('key',$v) && $key==$data['user_key']) unset($new_value[$k]); 115 | } 116 | } 117 | } 118 | while(!$this->client->cas('del_sub', $old_value, $new_value)); 119 | } 120 | 121 | protected function allSubUpdate($type='public',$data=[],$keysecret=''){ 122 | do{ 123 | $old_value=$new_value=$this->client->all_sub; 124 | foreach ($data['sub'] as $v){ 125 | if($type=='public') $key=json_encode($v); 126 | if($type=='private') { 127 | $key=$keysecret['key']; 128 | $key.=self::$USER_DELIMITER.json_encode($v); 129 | } 130 | $new_value[$key]=$v; 131 | } 132 | } 133 | while(!$this->client->cas('all_sub', $old_value, $new_value)); 134 | } 135 | 136 | protected function unAllSubUpdate($type='public',$data=[],$keysecret=''){ 137 | do{ 138 | $old_value=$new_value=$this->client->all_sub; 139 | foreach ($data['sub'] as $v){ 140 | if($type=='public') unset($new_value[json_encode($v)]); 141 | if($type=='private') { 142 | $key=$keysecret['key']; 143 | $key.=self::$USER_DELIMITER.json_encode($v); 144 | echo $key.PHP_EOL; 145 | unset($new_value[$key]); 146 | } 147 | } 148 | } 149 | while(!$this->client->cas('all_sub', $old_value, $new_value)); 150 | } 151 | 152 | protected function keysecretUpdate($key,$login=0){ 153 | do{ 154 | $old_client_keysecret=$new_client_keysecret=$this->client->keysecret; 155 | $new_client_keysecret[$key]['login']=$login; 156 | } 157 | while(!$this->client->cas('keysecret', $old_client_keysecret, $new_client_keysecret)); 158 | } 159 | 160 | protected function keysecretInit($keysecret){ 161 | do { 162 | $old_value = $new_value = $this->client->keysecret; 163 | 164 | if(!isset($new_value[$keysecret['key']])) { 165 | $new_value[$keysecret['key']]=$keysecret; 166 | $new_value[$keysecret['key']]['login']=0; 167 | } 168 | } 169 | while(!$this->client->cas('keysecret', $old_value, $new_value)); 170 | } 171 | 172 | protected function saveGlobalKey($key){ 173 | do { 174 | $old_value = $new_value = $this->client->global_key; 175 | $new_value[$key]=$key; 176 | } 177 | while(!$this->client->cas('global_key', $old_value, $new_value)); 178 | } 179 | } 180 | -------------------------------------------------------------------------------- /src/Exceptions/Exception.php: -------------------------------------------------------------------------------- 1 | 4 | * */ 5 | 6 | namespace Lin\Okex; 7 | 8 | use Lin\Okex\Api\AccountV3\Account; 9 | use Lin\Okex\Api\AccountV3\Currencies; 10 | use Lin\Okex\Api\AccountV3\Deposit; 11 | use Lin\Okex\Api\AccountV3\Ledger; 12 | use Lin\Okex\Api\AccountV3\Transfer; 13 | use Lin\Okex\Api\AccountV3\Wallet; 14 | use Lin\Okex\Api\AccountV3\Withdrawal; 15 | 16 | class OkexAccount 17 | { 18 | protected $key; 19 | protected $secret; 20 | protected $passphrase; 21 | protected $host; 22 | 23 | protected $options=[]; 24 | 25 | function __construct(string $key='',string $secret='',string $passphrase='',string $host='https://www.okex.com'){ 26 | $this->key=$key; 27 | $this->secret=$secret; 28 | $this->host=$host; 29 | $this->passphrase=$passphrase; 30 | } 31 | 32 | /** 33 | * 34 | * */ 35 | private function init(){ 36 | return [ 37 | 'key'=>$this->key, 38 | 'secret'=>$this->secret, 39 | 'passphrase'=>$this->passphrase, 40 | 'host'=>$this->host, 41 | 'options'=>$this->options, 42 | 43 | 'platform'=>'account', 44 | 'version'=>'v3', 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 currencies(){ 66 | return new Currencies($this->init()); 67 | } 68 | 69 | /** 70 | * 71 | * */ 72 | public function deposit(){ 73 | return new Deposit($this->init()); 74 | } 75 | 76 | /** 77 | * 78 | * */ 79 | public function ledger(){ 80 | return new Ledger($this->init()); 81 | } 82 | 83 | /** 84 | * 85 | * */ 86 | public function transfer(){ 87 | return new Transfer($this->init()); 88 | } 89 | 90 | /** 91 | * 92 | * */ 93 | public function wallet(){ 94 | return new Wallet($this->init()); 95 | } 96 | 97 | /** 98 | * 99 | * */ 100 | public function withdrawal(){ 101 | return new Withdrawal($this->init()); 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /src/OkexFuture.php: -------------------------------------------------------------------------------- 1 | 4 | * */ 5 | 6 | namespace Lin\Okex; 7 | 8 | 9 | use Lin\Okex\Api\FuturesV3\Accounts; 10 | use Lin\Okex\Api\FuturesV3\Fills; 11 | use Lin\Okex\Api\FuturesV3\Instruments; 12 | use Lin\Okex\Api\FuturesV3\Orders; 13 | use Lin\Okex\Api\FuturesV3\Position; 14 | 15 | class OkexFuture 16 | { 17 | protected $key; 18 | protected $secret; 19 | protected $passphrase; 20 | protected $host; 21 | 22 | protected $options=[]; 23 | 24 | function __construct(string $key='',string $secret='',string $passphrase='',string $host='https://www.okex.com'){ 25 | $this->key=$key; 26 | $this->secret=$secret; 27 | $this->host=$host; 28 | $this->passphrase=$passphrase; 29 | } 30 | 31 | /** 32 | * 33 | * */ 34 | private function init(){ 35 | return [ 36 | 'key'=>$this->key, 37 | 'secret'=>$this->secret, 38 | 'passphrase'=>$this->passphrase, 39 | 'host'=>$this->host, 40 | 'options'=>$this->options, 41 | 42 | 'platform'=>'future', 43 | 'version'=>'v3', 44 | ]; 45 | } 46 | 47 | /** 48 | * 49 | * */ 50 | function setOptions(array $options=[]){ 51 | $this->options=$options; 52 | } 53 | 54 | /** 55 | * 56 | * */ 57 | public function account(){ 58 | return new Accounts($this->init()); 59 | } 60 | 61 | /** 62 | * 63 | * */ 64 | public function fill(){ 65 | return new Fills($this->init()); 66 | } 67 | 68 | /** 69 | * 70 | * */ 71 | public function instrument(){ 72 | return new Instruments($this->init()); 73 | } 74 | 75 | /** 76 | * 77 | * */ 78 | public function order(){ 79 | return new Orders($this->init()); 80 | } 81 | 82 | /** 83 | * 84 | * */ 85 | public function position(){ 86 | return new Position($this->init()); 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /src/OkexMargin.php: -------------------------------------------------------------------------------- 1 | 4 | * */ 5 | 6 | namespace Lin\Okex; 7 | 8 | 9 | use Lin\Okex\Api\MarginV3\Accounts; 10 | use Lin\Okex\Api\MarginV3\Fills; 11 | use Lin\Okex\Api\MarginV3\Orders; 12 | 13 | class OkexMargin 14 | { 15 | protected $key; 16 | protected $secret; 17 | protected $passphrase; 18 | protected $host; 19 | 20 | protected $options=[]; 21 | 22 | function __construct(string $key='',string $secret='',string $passphrase='',string $host='https://www.okex.com'){ 23 | $this->key=$key; 24 | $this->secret=$secret; 25 | $this->host=$host; 26 | $this->passphrase=$passphrase; 27 | } 28 | 29 | /** 30 | * 31 | * */ 32 | private function init(){ 33 | return [ 34 | 'key'=>$this->key, 35 | 'secret'=>$this->secret, 36 | 'passphrase'=>$this->passphrase, 37 | 'host'=>$this->host, 38 | 'options'=>$this->options, 39 | 40 | 'platform'=>'margin', 41 | 'version'=>'v3', 42 | ]; 43 | } 44 | 45 | /** 46 | * 47 | * */ 48 | function setOptions(array $options=[]){ 49 | $this->options=$options; 50 | } 51 | 52 | /** 53 | * 54 | * */ 55 | public function account(){ 56 | return new Accounts($this->init()); 57 | } 58 | 59 | /** 60 | * 61 | * */ 62 | public function fill(){ 63 | return new Fills($this->init()); 64 | } 65 | 66 | /** 67 | * 68 | * */ 69 | public function order(){ 70 | return new Orders($this->init()); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/OkexOption.php: -------------------------------------------------------------------------------- 1 | 4 | * */ 5 | 6 | namespace Lin\Okex; 7 | 8 | use Lin\Okex\Api\OptionV3\Accounts; 9 | use Lin\Okex\Api\OptionV3\Fills; 10 | use Lin\Okex\Api\OptionV3\Instruments; 11 | use Lin\Okex\Api\OptionV3\Orders; 12 | use Lin\Okex\Api\OptionV3\Position; 13 | 14 | class OkexOption 15 | { 16 | protected $key; 17 | protected $secret; 18 | protected $passphrase; 19 | protected $host; 20 | 21 | protected $options=[]; 22 | 23 | function __construct(string $key='',string $secret='',string $passphrase='',string $host='https://www.okex.com'){ 24 | $this->key=$key; 25 | $this->secret=$secret; 26 | $this->host=$host; 27 | $this->passphrase=$passphrase; 28 | } 29 | 30 | /** 31 | * 32 | * */ 33 | private function init(){ 34 | return [ 35 | 'key'=>$this->key, 36 | 'secret'=>$this->secret, 37 | 'passphrase'=>$this->passphrase, 38 | 'host'=>$this->host, 39 | 40 | 'options'=>$this->options, 41 | 42 | 'platform'=>'option', 43 | 'version'=>'v3', 44 | ]; 45 | } 46 | 47 | /** 48 | * 49 | * */ 50 | function setOptions(array $options=[]){ 51 | $this->options=$options; 52 | } 53 | 54 | /** 55 | * 56 | * */ 57 | public function account(){ 58 | return new Accounts($this->init()); 59 | } 60 | 61 | /** 62 | * 63 | * */ 64 | public function fill(){ 65 | return new Fills($this->init()); 66 | } 67 | 68 | /** 69 | * 70 | * */ 71 | public function instrument(){ 72 | return new Instruments($this->init()); 73 | } 74 | 75 | /** 76 | * 77 | * */ 78 | public function order(){ 79 | return new Orders($this->init()); 80 | } 81 | 82 | /** 83 | * 84 | * */ 85 | public function position(){ 86 | return new Position($this->init()); 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /src/OkexSpot.php: -------------------------------------------------------------------------------- 1 | 4 | * */ 5 | 6 | namespace Lin\Okex; 7 | 8 | 9 | use Lin\Okex\Api\SpotV3\Accounts; 10 | use Lin\Okex\Api\SpotV3\Fills; 11 | use Lin\Okex\Api\SpotV3\Instruments; 12 | use Lin\Okex\Api\SpotV3\Orders; 13 | use Lin\Okex\Api\SpotV3\Trade; 14 | 15 | class OkexSpot 16 | { 17 | protected $key; 18 | protected $secret; 19 | protected $passphrase; 20 | protected $host; 21 | 22 | protected $options=[]; 23 | 24 | function __construct(string $key='',string $secret='',string $passphrase='',string $host='https://www.okex.com'){ 25 | $this->key=$key; 26 | $this->secret=$secret; 27 | $this->host=$host; 28 | $this->passphrase=$passphrase; 29 | } 30 | 31 | /** 32 | * 33 | * */ 34 | private function init(){ 35 | return [ 36 | 'key'=>$this->key, 37 | 'secret'=>$this->secret, 38 | 'passphrase'=>$this->passphrase, 39 | 'host'=>$this->host, 40 | 'options'=>$this->options, 41 | 42 | 'platform'=>'spot', 43 | 'version'=>'v3', 44 | ]; 45 | } 46 | 47 | /** 48 | * 49 | * */ 50 | function setOptions(array $options=[]){ 51 | $this->options=$options; 52 | } 53 | 54 | /** 55 | * 56 | * */ 57 | public function account(){ 58 | return new Accounts($this->init()); 59 | } 60 | 61 | /** 62 | * 63 | * */ 64 | public function fill(){ 65 | return new Fills($this->init()); 66 | } 67 | 68 | /** 69 | * 70 | * */ 71 | public function instrument(){ 72 | return new Instruments($this->init()); 73 | } 74 | 75 | /** 76 | * 77 | * */ 78 | public function order(){ 79 | return new Orders($this->init()); 80 | } 81 | 82 | /** 83 | * 84 | * */ 85 | public function trade(){ 86 | return new Trade($this->init()); 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /src/OkexSwap.php: -------------------------------------------------------------------------------- 1 | 4 | * */ 5 | 6 | namespace Lin\Okex; 7 | 8 | 9 | use Lin\Okex\Api\SwapV3\Accounts; 10 | use Lin\Okex\Api\SwapV3\Fills; 11 | use Lin\Okex\Api\SwapV3\Instruments; 12 | use Lin\Okex\Api\SwapV3\Orders; 13 | use Lin\Okex\Api\SwapV3\Position; 14 | 15 | class OkexSwap 16 | { 17 | protected $key; 18 | protected $secret; 19 | protected $passphrase; 20 | protected $host; 21 | 22 | protected $options=[]; 23 | 24 | function __construct(string $key='',string $secret='',string $passphrase='',string $host='https://www.okex.com'){ 25 | $this->key=$key; 26 | $this->secret=$secret; 27 | $this->host=$host; 28 | $this->passphrase=$passphrase; 29 | } 30 | 31 | /** 32 | * 33 | * */ 34 | private function init(){ 35 | return [ 36 | 'key'=>$this->key, 37 | 'secret'=>$this->secret, 38 | 'passphrase'=>$this->passphrase, 39 | 'host'=>$this->host, 40 | 41 | 'options'=>$this->options, 42 | 43 | 'platform'=>'swap', 44 | 'version'=>'v3', 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 Accounts($this->init()); 60 | } 61 | 62 | /** 63 | * 64 | * */ 65 | public function fill(){ 66 | return new Fills($this->init()); 67 | } 68 | 69 | /** 70 | * 71 | * */ 72 | public function instrument(){ 73 | return new Instruments($this->init()); 74 | } 75 | 76 | /** 77 | * 78 | * */ 79 | public function order(){ 80 | return new Orders($this->init()); 81 | } 82 | 83 | /** 84 | * 85 | * */ 86 | public function position(){ 87 | return new Position($this->init()); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/OkexV5.php: -------------------------------------------------------------------------------- 1 | 4 | * */ 5 | 6 | namespace Lin\Okex; 7 | 8 | use Lin\Okex\Api\OkexV5\Account; 9 | use Lin\Okex\Api\OkexV5\Asset; 10 | use Lin\Okex\Api\OkexV5\Market; 11 | use Lin\Okex\Api\OkexV5\Publics; 12 | use Lin\Okex\Api\OkexV5\SubAccount; 13 | use Lin\Okex\Api\OkexV5\System; 14 | use Lin\Okex\Api\OkexV5\Trade; 15 | 16 | class OkexV5 17 | { 18 | protected $key; 19 | protected $secret; 20 | protected $passphrase; 21 | protected $host; 22 | 23 | protected $options=[]; 24 | 25 | function __construct(string $key='',string $secret='',string $passphrase='',string $host='https://www.okx.com'){ 26 | $this->key=$key; 27 | $this->secret=$secret; 28 | $this->host=$host; 29 | $this->passphrase=$passphrase; 30 | } 31 | 32 | /** 33 | * 34 | * */ 35 | private function init(){ 36 | return [ 37 | 'key'=>$this->key, 38 | 'secret'=>$this->secret, 39 | 'passphrase'=>$this->passphrase, 40 | 'host'=>$this->host, 41 | 'options'=>$this->options, 42 | 43 | 'platform'=>'okex', 44 | 'version'=>'v5', 45 | ]; 46 | } 47 | 48 | /** 49 | * 50 | * */ 51 | function setOptions(array $options=[]){ 52 | $this->options=$options; 53 | } 54 | 55 | 56 | /** 57 | * 58 | * */ 59 | public function account(){ 60 | return new Account($this->init()); 61 | } 62 | 63 | /** 64 | * 65 | * */ 66 | public function asset(){ 67 | return new Asset($this->init()); 68 | } 69 | 70 | /** 71 | * 72 | * */ 73 | public function market(){ 74 | return new Market($this->init()); 75 | } 76 | 77 | /** 78 | * 79 | * */ 80 | public function publics(){ 81 | return new Publics($this->init()); 82 | } 83 | 84 | /** 85 | * 86 | * */ 87 | public function subaccount(){ 88 | return new SubAccount($this->init()); 89 | } 90 | 91 | /** 92 | * 93 | * */ 94 | public function trade(){ 95 | return new Trade($this->init()); 96 | } 97 | 98 | /** 99 | * 100 | * */ 101 | public function system(){ 102 | return new System($this->init()); 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /src/OkexWebSocket.php: -------------------------------------------------------------------------------- 1 | 4 | * */ 5 | 6 | namespace Lin\Okex; 7 | 8 | use Lin\Okex\Api\WebSocketV3\SocketServer; 9 | use Lin\Okex\Api\WebSocketV3\SocketClient; 10 | 11 | 12 | class OkexWebSocket 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/OkexWebSocketV5.php: -------------------------------------------------------------------------------- 1 | 4 | * */ 5 | 6 | namespace Lin\Okex; 7 | 8 | use Lin\Okex\Api\WebSocketV5\SocketServer; 9 | use Lin\Okex\Api\WebSocketV5\SocketClient; 10 | 11 | 12 | class OkexWebSocketV5 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\Okex; 7 | 8 | use GuzzleHttp\Exception\RequestException; 9 | use Lin\Okex\Exceptions\Exception; 10 | 11 | class Request 12 | { 13 | protected $key=''; 14 | 15 | protected $secret=''; 16 | 17 | protected $host=''; 18 | 19 | protected $passphrase=''; 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 | protected $platform=''; 38 | 39 | protected $version=''; 40 | 41 | protected $response_headers=[]; 42 | 43 | public function __construct(array $data) 44 | { 45 | $this->key=$data['key'] ?? ''; 46 | $this->secret=$data['secret'] ?? ''; 47 | $this->passphrase = $data['passphrase'] ?? ''; 48 | $this->host=$data['host'] ?? 'https://www.okx.com/'; 49 | 50 | $this->options=$data['options'] ?? []; 51 | 52 | $this->platform=$data['platform'] ?? []; 53 | $this->version=$data['version'] ?? []; 54 | } 55 | 56 | /** 57 | * 认证 58 | * */ 59 | protected function auth(){ 60 | $this->nonce(); 61 | 62 | $this->signature(); 63 | 64 | $this->headers(); 65 | 66 | $this->options(); 67 | } 68 | 69 | /** 70 | * 71 | * */ 72 | protected function nonce(){ 73 | $this->nonce=gmdate('Y-m-d\TH:i:s\.000\Z'); 74 | } 75 | 76 | /** 77 | * 签名 78 | * */ 79 | protected function signature(){ 80 | $body=''; 81 | $path=$this->type.$this->path; 82 | 83 | if(!empty($this->data)) { 84 | if($this->type=='GET') { 85 | $path.='?'.http_build_query($this->data); 86 | }else{ 87 | $body=json_encode($this->data); 88 | } 89 | } 90 | 91 | $this->signature = base64_encode(hash_hmac('sha256', $this->nonce.$path.$body, $this->secret, true)); 92 | } 93 | 94 | /** 95 | * 96 | * */ 97 | protected function headers(){ 98 | $this->headers=[ 99 | 'Content-Type' => 'application/json', 100 | ]; 101 | 102 | if(!empty($this->key) && !empty($this->secret)) { 103 | $this->headers=array_merge($this->headers,[ 104 | 'OK-ACCESS-KEY'=> $this->key, 105 | 'OK-ACCESS-TIMESTAMP'=>$this->nonce, 106 | 'OK-ACCESS-PASSPHRASE' =>$this->passphrase, 107 | 'OK-ACCESS-SIGN' => $this->signature, 108 | ]); 109 | } 110 | } 111 | 112 | /** 113 | * 114 | * */ 115 | protected function options(){ 116 | if(isset($this->options['headers'])) $this->headers=array_merge($this->headers,$this->options['headers']); 117 | 118 | $this->options['headers']=$this->headers; 119 | $this->options['timeout'] = $this->options['timeout'] ?? 60; 120 | } 121 | 122 | /** 123 | * 124 | * */ 125 | protected function send(){ 126 | $client = new \GuzzleHttp\Client(); 127 | 128 | $url=$this->host.$this->path; 129 | 130 | if(!empty($this->data)) { 131 | if($this->type=='GET') { 132 | $url.='?'.http_build_query($this->data); 133 | }else{ 134 | $this->options['body']=json_encode($this->data); 135 | } 136 | } 137 | /*print_r($this->options); 138 | die;*/ 139 | $response = $client->request($this->type, $url, $this->options); 140 | 141 | $this->response_headers = $response->getHeaders(); 142 | 143 | 144 | return $response->getBody()->getContents(); 145 | } 146 | 147 | /* 148 | * 149 | * */ 150 | protected function exec(){ 151 | $this->auth(); 152 | 153 | try { 154 | return json_decode($this->send(),true); 155 | }catch (RequestException $e){ 156 | if(empty($e->getResponse()) || $e->getResponse()==null) throw new Exception(json_encode(['_message'=>'system error'])); 157 | 158 | if(method_exists($e->getResponse(),'getBody')){ 159 | $contents=$e->getResponse()->getBody()->getContents(); 160 | 161 | $temp=json_decode($contents,true); 162 | if(!empty($temp)) { 163 | $temp['_method']=$this->type; 164 | $temp['_url']=$this->host.$this->path; 165 | }else{ 166 | $temp['_message']=$e->getMessage(); 167 | } 168 | }else{ 169 | $temp['_message']=$e->getMessage(); 170 | } 171 | 172 | $temp['_httpcode']=$e->getCode(); 173 | 174 | throw new Exception(json_encode($temp)); 175 | } 176 | } 177 | 178 | /** 179 | * Get Response Headers 180 | * */ 181 | public function getResponseHeaders(){ 182 | return $this->response_headers; 183 | } 184 | } 185 | -------------------------------------------------------------------------------- /tests/account_v3/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\Okex\OkexAccount; 13 | 14 | require __DIR__ .'../../../vendor/autoload.php'; 15 | 16 | include 'key_secret.php'; 17 | 18 | $okex=new OkexAccount($key,$secret,$passphrase); 19 | 20 | //You can set special needs 21 | $okex->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=$okex->account()->getUid(); 40 | print_r($result); 41 | }catch (\Exception $e){ 42 | print_r(json_decode($e->getMessage(),true)); 43 | } 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /tests/account_v3/currencies.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\Okex\OkexAccount; 13 | 14 | require __DIR__ .'../../../vendor/autoload.php'; 15 | 16 | include 'key_secret.php'; 17 | 18 | $okex=new OkexAccount($key,$secret,$passphrase); 19 | 20 | //You can set special needs 21 | $okex->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=$okex->currencies()->get(); 40 | print_r($result); 41 | }catch (\Exception $e){ 42 | print_r(json_decode($e->getMessage(),true)); 43 | } 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /tests/account_v3/deposit.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\Okex\OkexAccount; 13 | 14 | require __DIR__ .'../../../vendor/autoload.php'; 15 | 16 | include 'key_secret.php'; 17 | 18 | $okex=new OkexAccount($key,$secret,$passphrase); 19 | 20 | //You can set special needs 21 | $okex->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=$okex->deposit()->getAddress([ 40 | 'currency'=>'btc' 41 | ]); 42 | print_r($result); 43 | }catch (\Exception $e){ 44 | print_r(json_decode($e->getMessage(),true)); 45 | } 46 | 47 | try { 48 | $result=$okex->deposit()->getHistoryAll(); 49 | print_r($result); 50 | }catch (\Exception $e){ 51 | print_r(json_decode($e->getMessage(),true)); 52 | } 53 | 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /tests/account_v3/ledger.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\Okex\OkexAccount; 13 | 14 | require __DIR__ .'../../../vendor/autoload.php'; 15 | 16 | include 'key_secret.php'; 17 | 18 | $okex=new OkexAccount($key,$secret,$passphrase); 19 | 20 | //You can set special needs 21 | $okex->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=$okex->ledger()->get([ 40 | //currency String 否 币种,如btc ,不填时返回所有的账单流水 41 | //type String 否 填写相应数字:1:充值2:提现13:撤销提现18:转入合约账户19:合约账户转出20:转入子账户21:子账户转出28:领取29:转入指数交易区30:指数交易区转出 31:转入点对点账户32:点对点账户转出 33:转入币币杠杆账户 34:币币杠杆账户转出 37:转入币币账户 38:币币账户转出 42 | //from String 否 请求此id之前(更旧的数据)的分页内容,传的值为对应接口的order_id、ledger_id或trade_id等; 43 | //to String 否 请求此id之后(更新的数据)的分页内容,传的值为对应接口的order_id、ledger_id或trade_id等; 44 | //limit String 否 分页返回的结果集数量,最大为100,不填默认返回100条 45 | 46 | 'currency'=>'btc' 47 | ]); 48 | print_r($result); 49 | }catch (\Exception $e){ 50 | print_r(json_decode($e->getMessage(),true)); 51 | } 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /tests/account_v3/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/okex-php.git 11 | * */ 12 | use Lin\Okex\OkexAccount; 13 | 14 | require __DIR__ .'../../../vendor/autoload.php'; 15 | 16 | include 'key_secret.php'; 17 | 18 | $okex=new OkexAccount($key,$secret,$passphrase); 19 | 20 | //You can set special needs 21 | $okex->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 | //Funds Transfer 38 | try { 39 | $result=$okex->transfer()->post([ 40 | //currency String Yes Token 41 | //amount String Yes Transfer amount 42 | //from String Yes the remitting account_v3 (0: sub account_v3 1: spot_v3 3: futures 4:C2C 5: margin_v3 6: Funding Account 8:PiggyBank 9:swap_v3) 43 | //to String Yes the beneficiary account_v3(0: sub account_v3 1:spot_v3 3: futures 4:C2C 5: margin_v3 6: Funding Account 8:PiggyBank 9 :swap_v3) 44 | //sub_account String No sub account_v3 name 45 | //instrument_id String No Margin trading pair transferred out, for supported pairs only 46 | //to_instrument_id String No Margin trading pair transferred in, for supported pairs only 47 | 48 | 'currency'=>'btc', 49 | 'amount'=>'0.001', 50 | 'from'=>'1', 51 | 'to'=>'3', 52 | ]); 53 | print_r($result); 54 | }catch (\Exception $e){ 55 | print_r(json_decode($e->getMessage(),true)); 56 | } 57 | 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /tests/account_v3/wallet.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\Okex\OkexAccount; 13 | 14 | require __DIR__ .'../../../vendor/autoload.php'; 15 | 16 | include 'key_secret.php'; 17 | 18 | $okex=new OkexAccount($key,$secret,$passphrase); 19 | 20 | //You can set special needs 21 | $okex->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 | //Funding Account Information 38 | try { 39 | $result=$okex->wallet()->getAll(); 40 | print_r($result); 41 | }catch (\Exception $e){ 42 | print_r(json_decode($e->getMessage(),true)); 43 | } 44 | 45 | //Funding Account of a Currency 46 | try { 47 | $result=$okex->wallet()->get([ 48 | 'currency'=>'BTC' 49 | ]); 50 | print_r($result); 51 | }catch (\Exception $e){ 52 | print_r(json_decode($e->getMessage(),true)); 53 | } 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /tests/account_v3/withdrawal.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\Okex\OkexAccount; 13 | 14 | require __DIR__ .'../../../vendor/autoload.php'; 15 | 16 | include 'key_secret.php'; 17 | 18 | $okex=new OkexAccount($key,$secret,$passphrase); 19 | 20 | //You can set special needs 21 | $okex->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 | //Withdrawal 38 | try { 39 | $result=$okex->withdrawal()->post([ 40 | //currency String Yes token 41 | //amount String Yes withdrawal amount 42 | //destination String Yes withdrawal address(2:OKCoin International 3:OKEx 4:others) 43 | //to_address String Yes verified digital asset address, email or mobile String,some digital asset address format is address+tag , eg: "ARDOR-7JF3-8F2E-QUWZ-CAN7F:123456" 44 | //trade_pwd String Yes fund password 45 | //fee String Yes Network transaction fee≥0. Withdrawals to OKCoin or OKEx are fee-free, please set as 0. Withdrawal to external digital asset address requires network transaction fee. 46 | ]); 47 | print_r($result); 48 | }catch (\Exception $e){ 49 | print_r(json_decode($e->getMessage(),true)); 50 | } 51 | 52 | try { 53 | $result=$okex->withdrawal()->getFee(); 54 | print_r($result); 55 | }catch (\Exception $e){ 56 | print_r(json_decode($e->getMessage(),true)); 57 | } 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /tests/future_v3/accounts.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\Okex\OkexFuture; 13 | 14 | require __DIR__ .'../../../vendor/autoload.php'; 15 | 16 | include 'key_secret.php'; 17 | 18 | $okex=new OkexFuture($key,$secret,$passphrase); 19 | 20 | //You can set special needs 21 | $okex->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 | try { 38 | $result=$okex->account()->postMarginMode([ 39 | 'currency'=>'trx', 40 | 'margin_mode'=>'crossed', 41 | ]); 42 | print_r($result); 43 | }catch (\Exception $e){ 44 | print_r(json_decode($e->getMessage(),true)); 45 | } 46 | 47 | //This endpoint supports getting the list of assets(only show pairs with balance larger than 0), the balances, amount available/on hold in spot_v3 accounts. 48 | try { 49 | $result=$okex->account()->getAll(); 50 | print_r($result); 51 | }catch (\Exception $e){ 52 | print_r(json_decode($e->getMessage(),true)); 53 | } 54 | 55 | //This endpoint supports getting the balance, amount available/on hold of a token in spot_v3 account_v3. 56 | try { 57 | $result=$okex->account()->get([ 58 | 'currency'=>'BTC' 59 | ]); 60 | print_r($result); 61 | }catch (\Exception $e){ 62 | print_r(json_decode($e->getMessage(),true)); 63 | } 64 | 65 | //All paginated requests return the latest information (newest) as the first page sorted by newest (in chronological time) first. 66 | try { 67 | $result=$okex->account()->getLedger([ 68 | 'currency'=>'btc', 69 | 'limit'=>2, 70 | ]); 71 | print_r($result); 72 | }catch (\Exception $e){ 73 | print_r(json_decode($e->getMessage(),true)); 74 | } 75 | -------------------------------------------------------------------------------- /tests/future_v3/instrument.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\Okex\OkexFuture; 13 | 14 | require __DIR__ .'../../../vendor/autoload.php'; 15 | 16 | $okex=new OkexFuture(); 17 | 18 | //You can set special needs 19 | $okex->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 | //List all contracts. This request does not support pagination. The full list will be returned for a request. 36 | try { 37 | $result=$okex->instrument()->getBook([ 38 | 'instrument_id'=>'BTC-USD-210925', 39 | 'size'=>20, 40 | ]); 41 | print_r($result); 42 | }catch (\Exception $e){ 43 | print_r(json_decode($e->getMessage(),true)); 44 | } 45 | 46 | //Get market data. This endpoint provides the snapshots of market data and can be used without verifications. 47 | try { 48 | $result=$okex->instrument()->get(); 49 | print_r($result); 50 | }catch (\Exception $e){ 51 | print_r(json_decode($e->getMessage(),true)); 52 | } 53 | -------------------------------------------------------------------------------- /tests/future_v3/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/okex-php.git 11 | * */ 12 | use Lin\Okex\OkexFuture; 13 | 14 | require __DIR__ .'../../../vendor/autoload.php'; 15 | 16 | include 'key_secret.php'; 17 | 18 | $okex=new OkexFuture($key,$secret,$passphrase); 19 | 20 | //You can set special needs 21 | $okex->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=$okex->order()->post([ 40 | 'instrument_id'=>'BTC-USD-210925', 41 | 'type'=>'1', 42 | 'price'=>'100', 43 | 'size'=>'1', 44 | ]); 45 | print_r($result); 46 | }catch (\Exception $e){ 47 | print_r(json_decode($e->getMessage(),true)); 48 | } 49 | sleep(1); 50 | 51 | //Get order details by order ID. 52 | try { 53 | $result=$okex->order()->get([ 54 | 'instrument_id'=>'BTC-USD-210925', 55 | 'order_id'=>'xxxxxxx', 56 | ]); 57 | print_r($result); 58 | }catch (\Exception $e){ 59 | print_r(json_decode($e->getMessage(),true)); 60 | } 61 | sleep(1); 62 | 63 | //Cancelling an unfilled order. 64 | try { 65 | $result=$okex->order()->postCancel([ 66 | 'instrument_id'=>'BTC-USD-210925', 67 | 'order_id'=>'xxxxxx', 68 | ]); 69 | print_r($result); 70 | }catch (\Exception $e){ 71 | print_r(json_decode($e->getMessage(),true)); 72 | } 73 | 74 | 75 | 76 | -------------------------------------------------------------------------------- /tests/future_v3/position.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\Okex\OkexFuture; 13 | 14 | require __DIR__ .'../../../vendor/autoload.php'; 15 | 16 | include 'key_secret.php'; 17 | 18 | $okex=new OkexFuture($key,$secret,$passphrase); 19 | 20 | //You can set special needs 21 | $okex->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 | //Get the information of holding positions of a contract. 38 | try { 39 | $result=$okex->position()->get([ 40 | 'instrument_id'=>'BTC-USD-210925', 41 | ]); 42 | print_r($result); 43 | }catch (\Exception $e){ 44 | print_r(json_decode($e->getMessage(),true)); 45 | } 46 | 47 | //Get the information of all holding positions in futures trading.Due to high energy consumption, you are advised to capture data with the "Futures Account of a Currency" API instead. 48 | try { 49 | $result=$okex->position()->getAll(); 50 | print_r($result); 51 | }catch (\Exception $e){ 52 | print_r(json_decode($e->getMessage(),true)); 53 | } 54 | -------------------------------------------------------------------------------- /tests/future_v3/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/okex-php.git 11 | * */ 12 | use Lin\Okex\OkexFuture; 13 | 14 | require __DIR__ .'../../../vendor/autoload.php'; 15 | 16 | include 'key_secret.php'; 17 | 18 | $okex=new OkexFuture($key,$secret,$passphrase); 19 | 20 | //You can set special needs 21 | $okex->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 | //Get the information of holding positions of a contract. 38 | try { 39 | $result=$okex->position()->get([ 40 | 'instrument_id'=>'BTC-USD-190628', 41 | ]); 42 | print_r($result); 43 | }catch (\Exception $e){ 44 | print_r(json_decode($e->getMessage(),true)); 45 | } 46 | 47 | //Get the information of all holding positions in futures trading.Due to high energy consumption, you are advised to capture data with the "Futures Account of a Currency" API instead. 48 | try { 49 | $result=$okex->position()->getAll(); 50 | print_r($result); 51 | }catch (\Exception $e){ 52 | print_r(json_decode($e->getMessage(),true)); 53 | } -------------------------------------------------------------------------------- /tests/margin_v3/accounts.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\Okex\OkexMargin; 13 | 14 | require __DIR__ .'../../../vendor/autoload.php'; 15 | 16 | include 'key_secret.php'; 17 | 18 | $okex=new OkexMargin($key,$secret,$passphrase); 19 | 20 | //You can set special needs 21 | $okex->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 | //This endpoint supports getting the list of assets(only show pairs with balance larger than 0), the balances, amount available/on hold in spot_v3 accounts. 38 | try { 39 | $result=$okex->account()->getAll(); 40 | print_r($result); 41 | }catch (\Exception $e){ 42 | print_r(json_decode($e->getMessage(),true)); 43 | } 44 | 45 | //This endpoint supports getting the balance, amount available/on hold of a token in spot_v3 account_v3. 46 | try { 47 | $result=$okex->account()->get([ 48 | 'instrument_id'=>'BTC-USDT' 49 | ]); 50 | print_r($result); 51 | }catch (\Exception $e){ 52 | print_r(json_decode($e->getMessage(),true)); 53 | } 54 | 55 | //All paginated requests return the latest information (newest) as the first page sorted by newest (in chronological time) first. 56 | try { 57 | $result=$okex->account()->getLedger([ 58 | 'instrument_id'=>'BTC-USDT', 59 | 'currency'=>'BTC', 60 | 'limit'=>2, 61 | ]); 62 | print_r($result); 63 | }catch (\Exception $e){ 64 | print_r(json_decode($e->getMessage(),true)); 65 | } 66 | -------------------------------------------------------------------------------- /tests/margin_v3/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/okex-php.git 11 | * */ 12 | use Lin\Okex\OkexMargin; 13 | 14 | require __DIR__ .'../../../vendor/autoload.php'; 15 | 16 | include 'key_secret.php'; 17 | 18 | $okex=new OkexMargin($key,$secret,$passphrase); 19 | 20 | //You can set special needs 21 | $okex->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=$okex->order()->post([ 40 | 'instrument_id'=>'btc-usdt', 41 | 'side'=>'buy', 42 | 'price'=>'100', 43 | 'size'=>'0.001', 44 | 'margin_trading'=>2, 45 | //'type'=>'market', 46 | //'notional'=>'100' 47 | ]); 48 | print_r($result); 49 | }catch (\Exception $e){ 50 | print_r(json_decode($e->getMessage(),true)); 51 | } 52 | sleep(1); 53 | 54 | //Get order details by order ID. 55 | try { 56 | $result=$okex->order()->get([ 57 | 'instrument_id'=>'btc-usdt', 58 | 'order_id'=>$result['order_id'], 59 | ]); 60 | print_r($result); 61 | }catch (\Exception $e){ 62 | print_r(json_decode($e->getMessage(),true)); 63 | } 64 | sleep(1); 65 | 66 | //Cancelling an unfilled order. 67 | try { 68 | $result=$okex->order()->postCancel([ 69 | 'instrument_id'=>'btc-usdt', 70 | 'order_id'=>$result['order_id'], 71 | ]); 72 | print_r($result); 73 | }catch (\Exception $e){ 74 | print_r(json_decode($e->getMessage(),true)); 75 | } 76 | 77 | 78 | 79 | -------------------------------------------------------------------------------- /tests/okex_v5/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\Okex\OkexV5; 13 | 14 | require __DIR__ .'../../../vendor/autoload.php'; 15 | 16 | include 'key_secret.php'; 17 | 18 | $okex=new OkexV5($key,$secret,$passphrase); 19 | 20 | //You can set special needs 21 | $okex->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 | //Set Demo Trading 37 | 'headers'=>['x-simulated-trading'=>1] 38 | ]); 39 | 40 | try { 41 | $result=$okex->account()->getBalance(); 42 | print_r($result); 43 | }catch (\Exception $e){ 44 | print_r(json_decode($e->getMessage(),true)); 45 | } 46 | 47 | try { 48 | $result=$okex->account()->getPositions(); 49 | print_r($result); 50 | }catch (\Exception $e){ 51 | print_r(json_decode($e->getMessage(),true)); 52 | } 53 | 54 | try { 55 | $result=$okex->account()->getBills(); 56 | print_r($result); 57 | }catch (\Exception $e){ 58 | print_r(json_decode($e->getMessage(),true)); 59 | } 60 | 61 | try { 62 | $result=$okex->account()->getBillsArchive(); 63 | print_r($result); 64 | }catch (\Exception $e){ 65 | print_r(json_decode($e->getMessage(),true)); 66 | } 67 | 68 | try { 69 | $result=$okex->account()->getConfig(); 70 | print_r($result); 71 | }catch (\Exception $e){ 72 | print_r(json_decode($e->getMessage(),true)); 73 | } 74 | 75 | try { 76 | $result=$okex->account()->postSetPositionMode([ 77 | 'posMode'=>'long_short_mode' 78 | ]); 79 | print_r($result); 80 | }catch (\Exception $e){ 81 | print_r(json_decode($e->getMessage(),true)); 82 | } 83 | 84 | try { 85 | $result=$okex->account()->postSetLeverage([ 86 | 'instId'=>'BTC-USDT', 87 | //'ccy'=>'', 88 | 'lever'=>'5', 89 | 'mgnMode'=>'cross', 90 | ]); 91 | print_r($result); 92 | }catch (\Exception $e){ 93 | print_r(json_decode($e->getMessage(),true)); 94 | } 95 | 96 | try { 97 | $result=$okex->account()->getMaxSize([ 98 | 'instId'=>'BTC-USDT', 99 | 'tdMode'=>'cross', 100 | ]); 101 | print_r($result); 102 | }catch (\Exception $e){ 103 | print_r(json_decode($e->getMessage(),true)); 104 | } 105 | 106 | 107 | 108 | 109 | 110 | 111 | -------------------------------------------------------------------------------- /tests/okex_v5/asset.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\Okex\OkexV5; 13 | 14 | require __DIR__ .'../../../vendor/autoload.php'; 15 | 16 | include 'key_secret.php'; 17 | 18 | $okex=new OkexV5($key,$secret,$passphrase); 19 | 20 | //You can set special needs 21 | $okex->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 | //set Demo Trading 37 | 'headers'=>['x-simulated-trading'=>1] 38 | ]); 39 | 40 | 41 | try { 42 | $result=$okex->asset()->getDepositAddress([ 43 | 'ccy'=>'btc', 44 | ]); 45 | print_r($result); 46 | }catch (\Exception $e){ 47 | print_r(json_decode($e->getMessage(),true)); 48 | } 49 | 50 | try { 51 | $result=$okex->asset()->getBalances([ 52 | 'ccy'=>'btc', 53 | ]); 54 | print_r($result); 55 | }catch (\Exception $e){ 56 | print_r(json_decode($e->getMessage(),true)); 57 | } 58 | 59 | try { 60 | $result=$okex->asset()->getDepositHistory(); 61 | print_r($result); 62 | }catch (\Exception $e){ 63 | print_r(json_decode($e->getMessage(),true)); 64 | } 65 | 66 | try { 67 | $result=$okex->asset()->getWithdrawalHistory(); 68 | print_r($result); 69 | }catch (\Exception $e){ 70 | print_r(json_decode($e->getMessage(),true)); 71 | } 72 | 73 | try { 74 | $result=$okex->asset()->postTransfer([ 75 | 'ccy'=>'btc', 76 | 'amt'=>'0.01', 77 | 'from'=>'1', 78 | 'to'=>'3', 79 | ]); 80 | print_r($result); 81 | }catch (\Exception $e){ 82 | print_r(json_decode($e->getMessage(),true)); 83 | } 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | -------------------------------------------------------------------------------- /tests/okex_v5/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\Okex\OkexV5; 13 | 14 | require __DIR__ .'../../../vendor/autoload.php'; 15 | 16 | include 'key_secret.php'; 17 | 18 | $okex=new OkexV5(); 19 | 20 | //You can set special needs 21 | $okex->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 | //set Demo Trading 37 | //'headers'=>['x-simulated-trading'=>1] 38 | ]); 39 | 40 | 41 | try { 42 | $result=$okex->market()->getTickers([ 43 | 'instType'=>'SPOT', 44 | ]); 45 | print_r($result); 46 | }catch (\Exception $e){ 47 | print_r(json_decode($e->getMessage(),true)); 48 | } 49 | 50 | try { 51 | $result=$okex->market()->getTicker([ 52 | 'instId'=>'BTC-USD-SWAP', 53 | ]); 54 | print_r($result); 55 | }catch (\Exception $e){ 56 | print_r(json_decode($e->getMessage(),true)); 57 | } 58 | 59 | try { 60 | $result=$okex->market()->getIndexTickers([ 61 | 'instId'=>'BTC-USD', 62 | ]); 63 | print_r($result); 64 | }catch (\Exception $e){ 65 | print_r(json_decode($e->getMessage(),true)); 66 | } 67 | 68 | try { 69 | $result=$okex->market()->getCandles([ 70 | 'instId'=>'BTC-USD', 71 | ]); 72 | print_r($result); 73 | }catch (\Exception $e){ 74 | print_r(json_decode($e->getMessage(),true)); 75 | } 76 | 77 | try { 78 | $result=$okex->market()->getIndexCandles([ 79 | 'instId'=>'BTC-USD', 80 | ]); 81 | print_r($result); 82 | }catch (\Exception $e){ 83 | print_r(json_decode($e->getMessage(),true)); 84 | } 85 | 86 | 87 | 88 | 89 | -------------------------------------------------------------------------------- /tests/okex_v5/publics.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\Okex\OkexV5; 13 | 14 | require __DIR__ .'../../../vendor/autoload.php'; 15 | 16 | include 'key_secret.php'; 17 | 18 | $okex=new OkexV5(); 19 | 20 | //You can set special needs 21 | $okex->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 | //set Demo Trading 37 | //'headers'=>['x-simulated-trading'=>1] 38 | ]); 39 | 40 | 41 | try { 42 | $result=$okex->publics()->getInstruments([ 43 | 'instType'=>'SPOT', 44 | ]); 45 | print_r($result); 46 | }catch (\Exception $e){ 47 | print_r(json_decode($e->getMessage(),true)); 48 | } 49 | 50 | try { 51 | $result=$okex->publics()->getDeliveryExerciseHistory([ 52 | 'instType'=>'OPTION', 53 | 'uly'=>'BTC-USD' 54 | ]); 55 | print_r($result); 56 | }catch (\Exception $e){ 57 | print_r(json_decode($e->getMessage(),true)); 58 | } 59 | 60 | try { 61 | $result=$okex->publics()->getOpenInterest([ 62 | 'instType'=>'OPTION', 63 | ]); 64 | print_r($result); 65 | }catch (\Exception $e){ 66 | print_r(json_decode($e->getMessage(),true)); 67 | } 68 | 69 | try { 70 | $result=$okex->publics()->getFundingRate([ 71 | 'instId'=>'BTC-USD-SWAP', 72 | ]); 73 | print_r($result); 74 | }catch (\Exception $e){ 75 | print_r(json_decode($e->getMessage(),true)); 76 | } 77 | 78 | try { 79 | $result=$okex->publics()->getPriceLimit([ 80 | 'instType'=>'SWAP', 81 | ]); 82 | print_r($result); 83 | }catch (\Exception $e){ 84 | print_r(json_decode($e->getMessage(),true)); 85 | } 86 | 87 | try { 88 | $result=$okex->publics()->getMarkPrice([ 89 | 'instType'=>'SWAP', 90 | ]); 91 | print_r($result); 92 | }catch (\Exception $e){ 93 | print_r(json_decode($e->getMessage(),true)); 94 | } 95 | 96 | 97 | 98 | 99 | -------------------------------------------------------------------------------- /tests/okex_v5/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\Okex\OkexV5; 13 | 14 | require __DIR__ .'../../../vendor/autoload.php'; 15 | 16 | include 'key_secret.php'; 17 | 18 | $okex=new OkexV5($key,$secret,$passphrase); 19 | 20 | //You can set special needs 21 | $okex->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 | //Set Demo Trading 37 | 'headers'=>['x-simulated-trading'=>1] 38 | ]); 39 | 40 | try { 41 | $result=$okex->trade()->postOrder([ 42 | 'instId'=>'BTC-USDT', 43 | 'tdMode'=>'cross', 44 | 'clOrdId'=>'xxxxxxxxxxx', 45 | 'side'=>'buy', 46 | 'ordType'=>'limit', 47 | 'sz'=>'0.01', 48 | 'px'=>'10000', 49 | ]); 50 | print_r($result); 51 | }catch (\Exception $e){ 52 | print_r(json_decode($e->getMessage(),true)); 53 | } 54 | 55 | try { 56 | $result=$okex->trade()->postCancelOrder([ 57 | 'instId'=>'BTC-USDT', 58 | 'ordId'=>'xxxxxxxxx', 59 | //'clOrdId'=>'xxxxxxxxxxx', 60 | ]); 61 | print_r($result); 62 | }catch (\Exception $e){ 63 | print_r(json_decode($e->getMessage(),true)); 64 | } 65 | 66 | 67 | try { 68 | $result=$okex->trade()->postAmendOrder([ 69 | 'instId'=>'BTC-USDT', 70 | 'ordId'=>'xxxxxxxxx', 71 | //'clOrdId'=>'xxxxxxxxxxx', 72 | 'newSz'=>'0.012', 73 | 'newPx'=>'11000', 74 | ]); 75 | print_r($result); 76 | }catch (\Exception $e){ 77 | print_r(json_decode($e->getMessage(),true)); 78 | } 79 | 80 | try { 81 | $result=$okex->trade()->getOrder([ 82 | 'instId'=>'BTC-USDT', 83 | 'ordId'=>'xxxxxxxxx', 84 | //'clOrdId'=>'xxxxxxxxxxx', 85 | ]); 86 | print_r($result); 87 | }catch (\Exception $e){ 88 | print_r(json_decode($e->getMessage(),true)); 89 | } 90 | 91 | 92 | try { 93 | $result=$okex->trade()->postOrderAlgo([ 94 | 'instId'=>'BTC-USDT', 95 | 'tdMode'=>'cross', 96 | 'clOrdId'=>'xxxxxxxxxxx', 97 | 'side'=>'buy', 98 | 'ordType'=>'trigger', 99 | 'sz'=>'0.01', 100 | ]); 101 | print_r($result); 102 | }catch (\Exception $e){ 103 | print_r(json_decode($e->getMessage(),true)); 104 | } 105 | 106 | 107 | -------------------------------------------------------------------------------- /tests/spot_v3/accounts.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\Okex\OkexSpot; 13 | 14 | require __DIR__ .'../../../vendor/autoload.php'; 15 | 16 | include 'key_secret.php'; 17 | 18 | $okex=new OkexSpot($key,$secret,$passphrase); 19 | 20 | //You can set special needs 21 | $okex->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 | //This endpoint supports getting the list of assets(only show pairs with balance larger than 0), the balances, amount available/on hold in spot_v3 accounts. 38 | try { 39 | $result=$okex->account()->getAll(); 40 | print_r($result); 41 | }catch (\Exception $e){ 42 | print_r(json_decode($e->getMessage(),true)); 43 | } 44 | 45 | //This endpoint supports getting the balance, amount available/on hold of a token in spot_v3 account_v3. 46 | try { 47 | $result=$okex->account()->get([ 48 | 'currency'=>'BTC' 49 | ]); 50 | print_r($result); 51 | }catch (\Exception $e){ 52 | print_r(json_decode($e->getMessage(),true)); 53 | } 54 | 55 | //All paginated requests return the latest information (newest) as the first page sorted by newest (in chronological time) first. 56 | try { 57 | $result=$okex->account()->getLedger([ 58 | 'currency'=>'btc', 59 | 'limit'=>2, 60 | ]); 61 | print_r($result); 62 | }catch (\Exception $e){ 63 | print_r(json_decode($e->getMessage(),true)); 64 | } 65 | -------------------------------------------------------------------------------- /tests/spot_v3/fills.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\Okex\OkexSpot; 13 | 14 | require __DIR__ .'../../../vendor/autoload.php'; 15 | 16 | include 'key_secret.php'; 17 | 18 | $okex=new OkexSpot($key,$secret,$passphrase); 19 | 20 | //You can set special needs 21 | $okex->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=$okex->fill()->get([ 40 | 'instrument_id'=>'eth-usdt', 41 | 42 | //'order_id'=>$result['order_id'], 43 | ]); 44 | print_r($result); 45 | }catch (\Exception $e){ 46 | print_r(json_decode($e->getMessage(),true)); 47 | } 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /tests/spot_v3/instrument.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * Your 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\Okex\OkexSpot; 13 | 14 | require __DIR__ .'../../../vendor/autoload.php'; 15 | 16 | $okex=new OkexSpot(); 17 | 18 | //You can set special needs 19 | $okex->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 | //Getting the order book of a trading pair. Pagination is not supported here. The whole book will be returned for one request. WebSocket is recommended here. 36 | try { 37 | $result=$okex->instrument()->getBook([ 38 | 'instrument_id'=>'BTC-USDT', 39 | 'size'=>20 40 | ]); 41 | print_r($result); 42 | }catch (\Exception $e){ 43 | print_r(json_decode($e->getMessage(),true)); 44 | } 45 | 46 | //Get market data. This endpoint provides the snapshots of market data and can be used without verifications. 47 | //List trading pairs and get the trading limit, price, and more information of different trading pairs. 48 | try { 49 | $result=$okex->instrument()->get(); 50 | print_r($result); 51 | }catch (\Exception $e){ 52 | print_r(json_decode($e->getMessage(),true)); 53 | } 54 | 55 | -------------------------------------------------------------------------------- /tests/spot_v3/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/okex-php.git 11 | * */ 12 | use Lin\Okex\OkexSpot; 13 | 14 | require __DIR__ .'../../../vendor/autoload.php'; 15 | 16 | include 'key_secret.php'; 17 | 18 | $okex=new OkexSpot($key,$secret,$passphrase); 19 | 20 | //You can set special needs 21 | $okex->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=$okex->order()->post([ 40 | 'instrument_id'=>'btc-usdt', 41 | 'side'=>'buy', 42 | 'price'=>'100', 43 | 'size'=>'0.001', 44 | 45 | //'type'=>'market', 46 | //'notional'=>'100' 47 | ]); 48 | print_r($result); 49 | }catch (\Exception $e){ 50 | print_r(json_decode($e->getMessage(),true)); 51 | } 52 | sleep(1); 53 | 54 | //Get order details by order ID. 55 | try { 56 | $result=$okex->order()->get([ 57 | 'instrument_id'=>'btc-usdt', 58 | 'order_id'=>'xxxxxxx', 59 | ]); 60 | print_r($result); 61 | }catch (\Exception $e){ 62 | print_r(json_decode($e->getMessage(),true)); 63 | } 64 | sleep(1); 65 | 66 | //Cancelling an unfilled order. 67 | try { 68 | $result=$okex->order()->postCancel([ 69 | 'instrument_id'=>'btc-usdt', 70 | 'order_id'=>'xxxxxxxx', 71 | ]); 72 | print_r($result); 73 | }catch (\Exception $e){ 74 | print_r(json_decode($e->getMessage(),true)); 75 | } 76 | 77 | 78 | //*******************Simulation Test 79 | 80 | $key = "09d4ed9e-6c2b-4652-9119-5c8eea078904"; 81 | $secret = "AE06CAA53CAB76CACDEE6001ACDABB11"; 82 | $passphrase = "test123"; 83 | 84 | $okex=new OkexSpot($key,$secret,$passphrase); 85 | 86 | //You can set special needs 87 | $okex->setOptions([ 88 | 'timeout'=>10, 89 | 'headers'=>['x-simulated-trading'=>1], 90 | ]); 91 | 92 | try { 93 | $result=$okex->instrument()->get(); 94 | }catch (\Exception $e){ 95 | print_r(json_decode($e->getMessage(),true)); 96 | } 97 | 98 | //Place an Order 99 | try { 100 | $result=$okex->order()->post([ 101 | 'instrument_id'=>'MNBTC-MNUSDT', 102 | 'side'=>'buy', 103 | 'price'=>'100', 104 | 'size'=>'0.001', 105 | 106 | //'type'=>'market', 107 | //'notional'=>'100' 108 | ]); 109 | print_r($result); 110 | }catch (\Exception $e){ 111 | print_r(json_decode($e->getMessage(),true)); 112 | } 113 | sleep(1); 114 | 115 | //Get order details by order ID. 116 | try { 117 | $result=$okex->order()->get([ 118 | 'instrument_id'=>'MNBTC-MNUSDT', 119 | 'order_id'=>$result['order_id'], 120 | ]); 121 | print_r($result); 122 | }catch (\Exception $e){ 123 | print_r(json_decode($e->getMessage(),true)); 124 | } 125 | sleep(1); 126 | 127 | //Cancelling an unfilled order. 128 | try { 129 | $result=$okex->order()->postCancel([ 130 | 'instrument_id'=>'MNBTC-MNUSDT', 131 | 'order_id'=>$result['order_id'], 132 | ]); 133 | print_r($result); 134 | }catch (\Exception $e) { 135 | print_r(json_decode($e->getMessage(), true)); 136 | } 137 | 138 | 139 | 140 | -------------------------------------------------------------------------------- /tests/spot_v3/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/okex-php.git 11 | * */ 12 | use Lin\Okex\OkexSpot; 13 | 14 | require __DIR__ .'../../../vendor/autoload.php'; 15 | 16 | include 'key_secret.php'; 17 | 18 | $okex=new OkexSpot($key,$secret,$passphrase); 19 | 20 | //You can set special needs 21 | $okex->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 | //This endpoint supports getting the list of assets(only show pairs with balance larger than 0), the balances, amount available/on hold in spot_v3 accounts. 38 | try { 39 | $result=$okex->account()->getAll(); 40 | print_r($result); 41 | }catch (\Exception $e){ 42 | print_r(json_decode($e->getMessage(),true)); 43 | } 44 | 45 | //This endpoint supports getting the balance, amount available/on hold of a token in spot_v3 account_v3. 46 | try { 47 | $result=$okex->account()->get([ 48 | 'currency'=>'BTC' 49 | ]); 50 | print_r($result); 51 | }catch (\Exception $e){ 52 | print_r(json_decode($e->getMessage(),true)); 53 | } 54 | 55 | //All paginated requests return the latest information (newest) as the first page sorted by newest (in chronological time) first. 56 | try { 57 | $result=$okex->account()->getLedger([ 58 | 'currency'=>'btc', 59 | 'limit'=>2, 60 | ]); 61 | print_r($result); 62 | }catch (\Exception $e){ 63 | print_r(json_decode($e->getMessage(),true)); 64 | } 65 | -------------------------------------------------------------------------------- /tests/spot_v3/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\Okex\OkexSpot; 13 | 14 | require __DIR__ .'../../../vendor/autoload.php'; 15 | 16 | include 'key_secret.php'; 17 | 18 | $okex=new OkexSpot($key,$secret,$passphrase); 19 | 20 | //You can set special needs 21 | $okex->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 | try { 38 | $result=$okex->trade()->getFee(); 39 | print_r($result); 40 | }catch (\Exception $e){ 41 | print_r(json_decode($e->getMessage(),true)); 42 | } 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /tests/swap_v3/accounts.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\Okex\OkexSwap; 13 | 14 | require __DIR__ .'../../../vendor/autoload.php'; 15 | 16 | include 'key_secret.php'; 17 | 18 | $okex=new OkexSwap($key,$secret,$passphrase); 19 | 20 | //You can set special needs 21 | $okex->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 | //This endpoint supports getting the list of assets(only show pairs with balance larger than 0), the balances, amount available/on hold in spot_v3 accounts. 38 | try { 39 | $result=$okex->account()->getAll(); 40 | print_r($result); 41 | }catch (\Exception $e){ 42 | print_r(json_decode($e->getMessage(),true)); 43 | } 44 | 45 | //This endpoint supports getting the balance, amount available/on hold of a token in spot_v3 account_v3. 46 | try { 47 | $result=$okex->account()->get([ 48 | 'instrument_id'=>'BTC-USD-SWAP' 49 | ]); 50 | print_r($result); 51 | }catch (\Exception $e){ 52 | print_r(json_decode($e->getMessage(),true)); 53 | } 54 | 55 | //All paginated requests return the latest information (newest) as the first page sorted by newest (in chronological time) first. 56 | try { 57 | $result=$okex->account()->getLedger([ 58 | 'instrument_id'=>'BTC-USD-SWAP', 59 | 'limit'=>2, 60 | //'type'=>'1', 61 | //'from'=>'', 62 | //'to'=>'', 63 | ]); 64 | print_r($result); 65 | }catch (\Exception $e){ 66 | print_r(json_decode($e->getMessage(),true)); 67 | } 68 | -------------------------------------------------------------------------------- /tests/swap_v3/instrument.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\Okex\OkexSwap; 13 | 14 | require __DIR__ .'../../../vendor/autoload.php'; 15 | 16 | $okex=new OkexSwap(); 17 | 18 | //You can set special needs 19 | $okex->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 | //List all contracts. This request does not support pagination. The full list will be returned for a request. 36 | try { 37 | $result=$okex->instrument()->getDepth([ 38 | 'instrument_id'=>'BTC-USD-SWAP', 39 | 'size'=>10, 40 | ]); 41 | 42 | print_r($result); 43 | }catch (\Exception $e){ 44 | print_r(json_decode($e->getMessage(),true)); 45 | } 46 | 47 | //Get market data. This endpoint provides the snapshots of market data and can be used without verifications. 48 | try { 49 | $result=$okex->instrument()->get(); 50 | print_r($result); 51 | }catch (\Exception $e){ 52 | print_r(json_decode($e->getMessage(),true)); 53 | } 54 | -------------------------------------------------------------------------------- /tests/swap_v3/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/okex-php.git 11 | * */ 12 | use Lin\Okex\OkexSwap; 13 | 14 | require __DIR__ .'../../../vendor/autoload.php'; 15 | 16 | include 'key_secret.php'; 17 | 18 | $okex=new OkexSwap($key,$secret,$passphrase); 19 | 20 | //You can set special needs 21 | $okex->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=$okex->order()->post([ 40 | 'instrument_id'=>'BTC-USD-SWAP', 41 | 'type'=>'1', 42 | 'price'=>'5000', 43 | 'size'=>'1', 44 | ]); 45 | print_r($result); 46 | }catch (\Exception $e){ 47 | print_r(json_decode($e->getMessage(),true)); 48 | } 49 | sleep(1); 50 | 51 | //Get order details by order ID. 52 | try { 53 | $result=$okex->order()->get([ 54 | 'instrument_id'=>'BTC-USD-SWAP', 55 | 'order_id'=>'xxxxxx', 56 | ]); 57 | print_r($result); 58 | }catch (\Exception $e){ 59 | print_r(json_decode($e->getMessage(),true)); 60 | } 61 | sleep(1); 62 | 63 | //Cancelling an unfilled order. 64 | try { 65 | $result=$okex->order()->postCancel([ 66 | 'instrument_id'=>'BTC-USD-SWAP', 67 | 'order_id'=>'xxxxxx', 68 | ]); 69 | print_r($result); 70 | }catch (\Exception $e){ 71 | print_r(json_decode($e->getMessage(),true)); 72 | } 73 | 74 | 75 | 76 | -------------------------------------------------------------------------------- /tests/swap_v3/position.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\Okex\OkexSwap; 13 | 14 | require __DIR__ .'../../../vendor/autoload.php'; 15 | 16 | include 'key_secret.php'; 17 | 18 | $okex=new OkexSwap($key,$secret,$passphrase); 19 | 20 | //You can set special needs 21 | $okex->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 | //Get the information of holding positions of a contract. 38 | try { 39 | $result=$okex->position()->get([ 40 | 'instrument_id'=>'BTC-USD-SWAP', 41 | ]); 42 | print_r($result); 43 | }catch (\Exception $e){ 44 | print_r(json_decode($e->getMessage(),true)); 45 | } 46 | 47 | //Get the information of all holding positions in futures trading.Due to high energy consumption, you are advised to capture data with the "Futures Account of a Currency" API instead. 48 | try { 49 | $result=$okex->position()->getAll(); 50 | print_r($result); 51 | }catch (\Exception $e){ 52 | print_r(json_decode($e->getMessage(),true)); 53 | } 54 | -------------------------------------------------------------------------------- /tests/swap_v3/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/okex-php.git 11 | * */ 12 | use Lin\Okex\OkexFuture; 13 | 14 | require __DIR__ .'../../../vendor/autoload.php'; 15 | 16 | include 'key_secret.php'; 17 | 18 | $okex=new OkexFuture($key,$secret,$passphrase); 19 | 20 | //You can set special needs 21 | $okex->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 | //More flexible Settings 38 | $okex->setProxy([ 39 | 'http' => 'http://127.0.0.1:12333', 40 | 'https' => 'http://127.0.0.1:12333', 41 | ]); 42 | 43 | //Get the information of holding positions of a contract. 44 | try { 45 | $result=$okex->position()->get([ 46 | 'instrument_id'=>'BTC-USD-190628', 47 | ]); 48 | print_r($result); 49 | }catch (\Exception $e){ 50 | print_r(json_decode($e->getMessage(),true)); 51 | } 52 | 53 | //Get the information of all holding positions in futures trading.Due to high energy consumption, you are advised to capture data with the "Futures Account of a Currency" API instead. 54 | try { 55 | $result=$okex->position()->getAll(); 56 | print_r($result); 57 | }catch (\Exception $e){ 58 | print_r(json_decode($e->getMessage(),true)); 59 | } -------------------------------------------------------------------------------- /tests/websocket_v3/client.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\Okex\OkexWebSocket; 13 | 14 | require __DIR__ .'../../../vendor/autoload.php'; 15 | 16 | include 'key_secret.php'; 17 | 18 | $okex=new OkexWebSocket(); 19 | 20 | $okex->config([ 21 | //Do you want to enable local logging,default false 22 | 'log'=>true, 23 | //Or set the log name 24 | //'log'=>['filename'=>'okex'], 25 | 26 | //Daemons address and port,default 0.0.0.0:2207 27 | //'global'=>'127.0.0.1:22080', 28 | 29 | //Heartbeat time,default 20 seconds 30 | //'ping_time'=>20, 31 | 32 | //Channel subscription monitoring time,2 seconds 33 | //'listen_time'=>2, 34 | 35 | //Channel data update time,0.1 seconds 36 | //'data_time'=>0.1, 37 | ]); 38 | 39 | $action=intval($_GET['action'] ?? 0);//http pattern 40 | if(empty($action)) $action=intval($argv[1]);//cli pattern 41 | 42 | switch ($action){ 43 | //**************public 44 | 45 | //subscribe 46 | case 1:{ 47 | $okex->subscribe([ 48 | 'spot/depth5:BCH-USDT', 49 | 'futures/depth5:BCH-USD-210924', 50 | 'swap/depth5:BCH-USD-SWAP', 51 | ]); 52 | 53 | break; 54 | } 55 | 56 | //unsubscribe 57 | case 2:{ 58 | $okex->unsubscribe([ 59 | 'spot/depth5:BCH-USDT', 60 | 'futures/depth5:BCH-USD-210326', 61 | 'swap/depth5:BCH-USD-SWAP', 62 | 'option/depth5:BTCUSD-20201021-11750-C', 63 | ]); 64 | 65 | break; 66 | } 67 | 68 | //**************private 69 | //subscribe 70 | case 10:{ 71 | $okex->keysecret($key_secret[0]); 72 | $okex->subscribe([ 73 | /*'spot/depth5:BCH-USDT', 74 | 'futures/depth5:BCH-USD-210924', 75 | 'swap/depth5:BCH-USD-SWAP',*/ 76 | 77 | 'futures/position:BCH-USD-210924', 78 | 'futures/account:BCH-USDT', 79 | 'swap/position:BCH-USD-SWAP', 80 | ]); 81 | break; 82 | } 83 | 84 | //unsubscribe 85 | case 11:{ 86 | $okex->keysecret($key_secret[0]); 87 | $okex->unsubscribe([ 88 | 'spot/depth5:BCH-USDT', 89 | 'futures/depth5:BCH-USD-210326', 90 | 'swap/depth5:BCH-USD-SWAP', 91 | 92 | 'futures/position:BCH-USD-210326', 93 | 'futures/account:BCH-USDT', 94 | 'swap/position:BCH-USD-SWAP', 95 | ]); 96 | 97 | break; 98 | } 99 | 100 | case 15:{ 101 | $okex->keysecret([ 102 | 'key'=>'xxxxxxxxx', 103 | 'secret'=>'xxxxxxxxx', 104 | 'passphrase'=>'xxxxxxxxx', 105 | ]); 106 | $okex->subscribe([ 107 | 'spot/depth5:BTC-USDT', 108 | 'futures/depth5:BTC-USD-210326', 109 | 'swap/depth5:BTC-USD-SWAP', 110 | 111 | 'futures/position:BTC-USD-210326', 112 | 'swap/position:BTC-USD-SWAP', 113 | ]); 114 | break; 115 | } 116 | 117 | case 20:{ 118 | //****Three ways to get all data 119 | 120 | //The first way 121 | $data=$okex->getSubscribes(); 122 | print_r(json_encode($data)); 123 | 124 | 125 | //The second way callback 126 | $okex->getSubscribes(function($data){ 127 | print_r(json_encode($data)); 128 | }); 129 | 130 | //The third way is to guard the process 131 | $okex->getSubscribes(function($data){ 132 | print_r(json_encode($data)); 133 | },true); 134 | 135 | break; 136 | } 137 | 138 | case 21:{ 139 | //****Three ways return to the specified channel data 140 | 141 | //The first way 142 | $data=$okex->getSubscribe([ 143 | 'spot/depth5:BCH-USDT', 144 | 'futures/depth5:BCH-USD-210326', 145 | ]); 146 | print_r(json_encode($data)); 147 | 148 | //The second way callback 149 | $okex->getSubscribe([ 150 | 'spot/depth5:BCH-USDT', 151 | 'futures/depth5:BCH-USD-210326', 152 | ],function($data){ 153 | print_r(json_encode($data)); 154 | }); 155 | 156 | //The third way is to guard the process 157 | $okex->getSubscribe([ 158 | 'spot/depth5:BCH-USDT', 159 | 'futures/depth5:BCH-USD-210326', 160 | ],function($data){ 161 | print_r(json_encode($data)); 162 | },true); 163 | 164 | break; 165 | } 166 | 167 | case 22:{ 168 | //****Three ways return to the specified channel data 169 | 170 | //The first way 171 | $okex->keysecret($key_secret[0]); 172 | $data=$okex->getSubscribe([ 173 | 'futures/depth5:BCH-USD-210326', 174 | 'futures/position:BCH-USD-210326',//If there are private channels, $okex->keysecret() must be set 175 | ]); 176 | print_r(json_encode($data)); 177 | die; 178 | 179 | //The second way callback 180 | $okex->keysecret($key_secret[0]); 181 | $okex->getSubscribe([ 182 | 'futures/depth5:BCH-USD-210326', 183 | 'futures/position:BCH-USD-210326',//If there are private channels, $okex->keysecret() must be set 184 | ],function($data){ 185 | print_r(json_encode($data)); 186 | }); 187 | 188 | //The third way is to guard the process 189 | $okex->keysecret($key_secret[0]); 190 | $okex->getSubscribe([ 191 | 'futures/depth5:BCH-USD-210326', 192 | 'futures/position:BCH-USD-210326',//If there are private channels, $okex->keysecret() must be set 193 | ],function($data){ 194 | print_r(json_encode($data)); 195 | },true); 196 | 197 | break; 198 | } 199 | 200 | case 99:{ 201 | $okex->client()->test(); 202 | break; 203 | } 204 | 205 | //Simulation error message 206 | case 10001:{ 207 | $okex->subscribe([ 208 | 'spot/depth5:BCH-USDT-xx', 209 | ]); 210 | break; 211 | } 212 | 213 | case 10002:{ 214 | $okex->keysecret([ 215 | 'key'=>'xxxxxxxxx', 216 | 'secret'=>'xxxxxxxxx', 217 | 'passphrase'=>'xxxxxxxxx', 218 | ]); 219 | $okex->subscribe([ 220 | 'swap/depth5:BTC-USD-SWAP-xxx', 221 | 222 | 'futures/position:BTC-USD-210326', 223 | 'swap/position:BTC-USD-SWAP', 224 | ]); 225 | break; 226 | } 227 | 228 | case 10003:{ 229 | $okex->subscribe([ 230 | 'spot/depth5:BCH-USDT', 231 | 'futures/depth5:BCH-USD-210326', 232 | 'swap/depth5:BCH-USD-SWAP', 233 | 'option/depth5:BTCUSD-20201021-11750-C', 234 | 235 | 'futures/position:BTC-USD-210326', 236 | 'swap/position:BTC-USD-SWAP', 237 | ]); 238 | break; 239 | } 240 | 241 | case 10004:{ 242 | $okex->client()->test2(); 243 | break; 244 | } 245 | 246 | case 10005:{ 247 | $okex->client()->test_reconnection(); 248 | break; 249 | } 250 | 251 | case 10006:{ 252 | $okex->reconPublic(); 253 | break; 254 | } 255 | 256 | case 10007:{ 257 | //private 258 | //print_r($key_secret[0]); 259 | $okex->reconPrivate($key_secret[0]['key']); 260 | break; 261 | } 262 | } 263 | 264 | 265 | -------------------------------------------------------------------------------- /tests/websocket_v3/server.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\Okex\OkexWebSocket; 13 | 14 | require __DIR__ .'../../../vendor/autoload.php'; 15 | 16 | $okex=new OkexWebSocket(); 17 | 18 | $okex->config([ 19 | //Do you want to enable local logging,default false 20 | 'log'=>true, 21 | //Or set the log name 22 | //'log'=>['filename'=>'okex'], 23 | 24 | //Daemons address and port,default 0.0.0.0:2207 25 | 'global'=>'127.0.0.1:22080', 26 | 27 | //Heartbeat time,default 20 seconds 28 | //'ping_time'=>20, 29 | 30 | //Channel subscription monitoring time,2 seconds 31 | //'listen_time'=>2, 32 | 33 | //Channel data update time,0.1 seconds 34 | //'data_time'=>0.1, 35 | ]); 36 | 37 | $okex->start(); 38 | 39 | -------------------------------------------------------------------------------- /tests/websocket_v5/client.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\Okex\OkexWebSocketV5; 13 | 14 | require __DIR__ .'../../../vendor/autoload.php'; 15 | 16 | include 'key_secret.php'; 17 | 18 | $okex=new OkexWebSocketV5(); 19 | 20 | $okex->config([ 21 | //Do you want to enable local logging,default false 22 | 'log'=>true, 23 | //Or set the log name 24 | //'log'=>['filename'=>'okex'], 25 | 26 | //Daemons address and port,default 0.0.0.0:22075 27 | 'global'=>'127.0.0.1:22075', 28 | 29 | //Heartbeat time,default 20 seconds 30 | //'ping_time'=>20, 31 | 32 | //Channel subscription monitoring time,2 seconds 33 | //'listen_time'=>2, 34 | 35 | //Channel data update time,0.1 seconds 36 | //'data_time'=>0.1, 37 | 38 | //Set Demo Trading Services 39 | /*'baseurl'=>[ 40 | 'public'=>'ws://wspap.okex.com:8443/ws/v5/public?brokerId=9999', 41 | 'private'=>'ws://wspap.okex.com:8443/ws/v5/private?brokerId=9999', 42 | ],*/ 43 | ]); 44 | 45 | $action=intval($_GET['action'] ?? 0);//http pattern 46 | if(empty($action)) $action=intval($argv[1]);//cli pattern 47 | 48 | switch ($action){ 49 | //**************public 50 | 51 | case 0:{ 52 | $okex->subscribe([ 53 | ["channel"=>"instruments","instType"=>"SPOT"], 54 | ["channel"=>"instruments","instType"=>"SWAP"], 55 | ["channel"=>"instruments","instType"=>"FUTURES"], 56 | ["channel"=>"instruments","instType"=>"OPTION"], 57 | ]); 58 | break; 59 | } 60 | 61 | //subscribe 62 | case 1:{ 63 | $okex->subscribe([ 64 | ["channel"=>"tickers","instId"=>"BTC-USDT"], 65 | ["channel"=>"tickers","instId"=>"BTC-USD-SWAP"], 66 | ["channel"=>"tickers","instId"=>"BTC-USD-210924"], 67 | 68 | ["channel"=>"books","instId"=>"BTC-USDT"], 69 | ["channel"=>"books","instId"=>"BTC-USD-SWAP"], 70 | ["channel"=>"books","instId"=>"BTC-USD-210924"], 71 | 72 | ["channel"=>"candle5m","instId"=>"BTC-USDT"], 73 | ["channel"=>"candle15m","instId"=>"BTC-USD-SWAP"], 74 | ["channel"=>"candle30m","instId"=>"BTC-USD-210924"], 75 | ]); 76 | break; 77 | } 78 | 79 | //unsubscribe 80 | case 2:{ 81 | $okex->unsubscribe([ 82 | ["channel"=>"tickers","instId"=>"BTC-USDT"], 83 | ["channel"=>"tickers","instId"=>"BTC-USD-SWAP"], 84 | ["channel"=>"tickers","instId"=>"BTC-USD-210924"], 85 | 86 | ["channel"=>"books","instId"=>"BTC-USDT"], 87 | ["channel"=>"books","instId"=>"BTC-USD-SWAP"], 88 | ["channel"=>"books","instId"=>"BTC-USD-210924"], 89 | 90 | ["channel"=>"candle5m","instId"=>"BTC-USDT"], 91 | ["channel"=>"candle15m","instId"=>"BTC-USD-SWAP"], 92 | ["channel"=>"candle30m","instId"=>"BTC-USD-210924"], 93 | ]); 94 | 95 | break; 96 | } 97 | 98 | //**************private 99 | //subscribe 100 | case 10:{ 101 | $okex->keysecret($key_secret[0]); 102 | $okex->subscribe([ 103 | //public 104 | ["channel"=>"tickers","instId"=>"BTC-USDT"], 105 | ["channel"=>"tickers","instId"=>"BTC-USD-SWAP"], 106 | ["channel"=>"tickers","instId"=>"BTC-USD-210924"], 107 | 108 | ["channel"=>"books","instId"=>"BTC-USDT"], 109 | ["channel"=>"books","instId"=>"BTC-USD-SWAP"], 110 | ["channel"=>"books","instId"=>"BTC-USD-210924"], 111 | 112 | ["channel"=>"candle5m","instId"=>"BTC-USDT"], 113 | ["channel"=>"candle15m","instId"=>"BTC-USD-SWAP"], 114 | ["channel"=>"candle30m","instId"=>"BTC-USD-210924"], 115 | 116 | //private 117 | ["channel"=>"account","ccy"=>"BTC"], 118 | ["channel"=>"positions","instType"=>"FUTURES","uly"=>"BTC-USD","instId"=>"BTC-USD-210924"], 119 | ["channel"=>"balance_and_position"], 120 | ["channel"=>"orders","instType"=>"FUTURES","uly"=>"BTC-USD","instId"=>"BTC-USD-210924"], 121 | ["channel"=>"orders-algo","instType"=>"FUTURES","uly"=>"BTC-USD","instId"=>"BTC-USD-210924"], 122 | ]); 123 | break; 124 | } 125 | 126 | //unsubscribe 127 | case 11:{ 128 | $okex->keysecret($key_secret[0]); 129 | $okex->unsubscribe([ 130 | //public 131 | ["channel"=>"tickers","instId"=>"BTC-USDT"], 132 | ["channel"=>"tickers","instId"=>"BTC-USD-SWAP"], 133 | ["channel"=>"tickers","instId"=>"BTC-USD-210924"], 134 | 135 | ["channel"=>"books","instId"=>"BTC-USDT"], 136 | ["channel"=>"books","instId"=>"BTC-USD-SWAP"], 137 | ["channel"=>"books","instId"=>"BTC-USD-210924"], 138 | 139 | ["channel"=>"candle5m","instId"=>"BTC-USDT"], 140 | ["channel"=>"candle15m","instId"=>"BTC-USD-SWAP"], 141 | ["channel"=>"candle30m","instId"=>"BTC-USD-210924"], 142 | 143 | //private 144 | ["channel"=>"account","ccy"=>"BTC"], 145 | ["channel"=>"positions","instType"=>"FUTURES","uly"=>"BTC-USD","instId"=>"BTC-USD-210924"], 146 | ["channel"=>"balance_and_position"], 147 | ["channel"=>"orders","instType"=>"FUTURES","uly"=>"BTC-USD","instId"=>"BTC-USD-210924"], 148 | ["channel"=>"orders-algo","instType"=>"FUTURES","uly"=>"BTC-USD","instId"=>"BTC-USD-210924"], 149 | ]); 150 | 151 | break; 152 | } 153 | 154 | case 20:{ 155 | //****Three ways to get all data 156 | 157 | //The first way 158 | $data=$okex->getSubscribes(); 159 | print_r(json_encode($data)); 160 | 161 | 162 | //The second way callback 163 | $okex->getSubscribes(function($data){ 164 | print_r(json_encode($data)); 165 | }); 166 | 167 | //The third way is to guard the process 168 | $okex->getSubscribes(function($data){ 169 | print_r(json_encode($data)); 170 | },true); 171 | 172 | break; 173 | } 174 | 175 | case 21:{ 176 | //****Three ways return to the specified channel data 177 | 178 | //The first way 179 | $data=$okex->getSubscribe([ 180 | ["channel"=>"tickers","instId"=>"BTC-USDT"], 181 | ["channel"=>"tickers","instId"=>"BTC-USD-SWAP"], 182 | ["channel"=>"tickers","instId"=>"BTC-USD-210924"], 183 | ]); 184 | 185 | //The second way callback 186 | $okex->getSubscribe([ 187 | ["channel"=>"books","instId"=>"BTC-USDT"], 188 | ["channel"=>"books","instId"=>"BTC-USD-SWAP"], 189 | ["channel"=>"books","instId"=>"BTC-USD-210924"], 190 | ],function($data){ 191 | print_r(json_encode($data)); 192 | }); 193 | 194 | //The third way is to guard the process 195 | $okex->getSubscribe([ 196 | ["channel"=>"candle5m","instId"=>"BTC-USDT"], 197 | ["channel"=>"candle15m","instId"=>"BTC-USD-SWAP"], 198 | ["channel"=>"candle30m","instId"=>"BTC-USD-210924"], 199 | ],function($data){ 200 | print_r(json_encode($data)); 201 | },true); 202 | 203 | break; 204 | } 205 | 206 | case 22:{ 207 | //****Three ways return to the specified channel data 208 | 209 | //The first way 210 | $okex->keysecret($key_secret[0]); 211 | $data=$okex->getSubscribes(); 212 | print_r(json_encode($data)); 213 | die; 214 | 215 | //The second way callback 216 | $okex->keysecret($key_secret[0]); 217 | $okex->getSubscribe([ 218 | ["channel"=>"books","instId"=>"BTC-USDT"], 219 | ["channel"=>"books","instId"=>"BTC-USD-SWAP"], 220 | 221 | ["channel"=>"account","ccy"=>"BTC"], 222 | ["channel"=>"positions","instType"=>"FUTURES","uly"=>"BTC-USD","instId"=>"BTC-USD-210924"], 223 | ],function($data){ 224 | print_r(json_encode($data)); 225 | }); 226 | 227 | //The third way is to guard the process 228 | $okex->keysecret($key_secret[0]); 229 | $okex->getSubscribe([ 230 | ["channel"=>"books","instId"=>"BTC-USDT"], 231 | ["channel"=>"books","instId"=>"BTC-USD-SWAP"], 232 | 233 | ["channel"=>"account","ccy"=>"BTC"], 234 | ["channel"=>"positions","instType"=>"FUTURES","uly"=>"BTC-USD","instId"=>"BTC-USD-210924"], 235 | ],function($data){ 236 | print_r(json_encode($data)); 237 | },true); 238 | 239 | break; 240 | } 241 | 242 | case 99:{ 243 | $okex->client()->test(); 244 | break; 245 | } 246 | 247 | case 10004:{ 248 | $okex->client()->test2(); 249 | break; 250 | } 251 | 252 | case 10005:{ 253 | $okex->client()->test_reconnection(); 254 | break; 255 | } 256 | 257 | case 10006:{ 258 | $okex->reconPublic(); 259 | break; 260 | } 261 | 262 | case 10007:{ 263 | //private 264 | //print_r($key_secret[0]); 265 | $okex->reconPrivate($key_secret[0]['key']); 266 | break; 267 | } 268 | } 269 | 270 | 271 | -------------------------------------------------------------------------------- /tests/websocket_v5/server.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\Okex\OkexWebSocketV5; 13 | 14 | require __DIR__ .'../../../vendor/autoload.php'; 15 | 16 | $okex=new OkexWebSocketV5(); 17 | 18 | $okex->config([ 19 | //Do you want to enable local logging,default false 20 | 'log'=>true, 21 | //Or set the log name 22 | //'log'=>['filename'=>'okex'], 23 | 24 | //Daemons address and port,default 0.0.0.0:22075 25 | 'global'=>'127.0.0.1:22075', 26 | 27 | //Heartbeat time,default 20 seconds 28 | //'ping_time'=>20, 29 | 30 | //Channel subscription monitoring time,2 seconds 31 | //'listen_time'=>2, 32 | 33 | //Channel data update time,0.1 seconds 34 | //'data_time'=>0.1, 35 | 36 | //Set Demo Trading Services 37 | /*'baseurl'=>[ 38 | 'public'=>'ws://wspap.okex.com:8443/ws/v5/public?brokerId=9999', 39 | 'private'=>'ws://wspap.okex.com:8443/ws/v5/private?brokerId=9999', 40 | ],*/ 41 | ]); 42 | 43 | $okex->start(); 44 | 45 | --------------------------------------------------------------------------------