diff --git a/README.md b/README.md index ae0e5b2..37759be 100644 --- a/README.md +++ b/README.md @@ -281,13 +281,134 @@ try { } ``` +### Swap Trading API + +Instrument related API [More](https://github.com/zhouaini528/okex-php/blob/master/tests/swap/instrument.php) +```php +$okex=new OkexFuture(); + +//List all contracts. This request does not support pagination. The full list will be returned for a request. +try { + $result=$okex->instrument()->getDepth([ + 'instrument_id'=>'BTC-USD-SWAP', + 'size'=>10, + ]); + + print_r($result); +}catch (\Exception $e){ + print_r(json_decode($e->getMessage(),true)); +} + +//Get market data. This endpoint provides the snapshots of market data and can be used without verifications. +try { + $result=$okex->instrument()->get(); + print_r($result); +}catch (\Exception $e){ + print_r(json_decode($e->getMessage(),true)); +} +``` + +Order related API [More](https://github.com/zhouaini528/okex-php/blob/master/tests/swap/order.php) +```php +$okex=new OkexFuture($key,$secret,$passphrase); + +//Place an Order +try { + $result=$okex->order()->post([ + 'instrument_id'=>'BTC-USD-SWAP', + 'type'=>'1', + 'price'=>'5000', + 'size'=>'1', + ]); + print_r($result); +}catch (\Exception $e){ + print_r(json_decode($e->getMessage(),true)); +} +sleep(1); + +//Get order details by order ID. +try { + $result=$okex->order()->get([ + 'instrument_id'=>'BTC-USD-SWAP', + 'order_id'=>$result['order_id'], + ]); + print_r($result); +}catch (\Exception $e){ + print_r(json_decode($e->getMessage(),true)); +} +sleep(1); + +//Cancelling an unfilled order. +try { + $result=$okex->order()->postCancel([ + 'instrument_id'=>'BTC-USD-SWAP', + 'order_id'=>$result['order_id'], + ]); + print_r($result); +}catch (\Exception $e){ + print_r(json_decode($e->getMessage(),true)); +} +``` + +Accounts related API [More](https://github.com/zhouaini528/okex-php/blob/master/tests/swap/accounts.php) +```php +$okex=new OkexSpot($key,$secret,$passphrase); +//This endpoint supports getting the list of assets(only show pairs with balance larger than 0), the balances, amount available/on hold in spot accounts. +try { + $result=$okex->account()->getAll(); + print_r($result); +}catch (\Exception $e){ + print_r(json_decode($e->getMessage(),true)); +} + +//This endpoint supports getting the balance, amount available/on hold of a token in spot account. +try { + $result=$okex->account()->get([ + 'instrument_id'=>'BTC-USD-SWAP' + ]); + print_r($result); +}catch (\Exception $e){ + print_r(json_decode($e->getMessage(),true)); +} + +//All paginated requests return the latest information (newest) as the first page sorted by newest (in chronological time) first. +try { + $result=$okex->account()->getLedger([ + 'instrument_id'=>'BTC-USD-SWAP', + 'limit'=>2, + //'type'=>'1', + //'from'=>'', + //'to'=>'', + ]); + print_r($result); +}catch (\Exception $e){ + print_r(json_decode($e->getMessage(),true)); +} +``` + +Position related API [More](https://github.com/zhouaini528/okex-php/blob/master/tests/swap/position.php) +```php +$okex=new OkexFuture($key,$secret,$passphrase); + +//Get the information of holding positions of a contract. +try { + $result=$okex->position()->get([ + 'instrument_id'=>'BTC-USD-SWAP', + ]); + print_r($result); +}catch (\Exception $e){ + print_r(json_decode($e->getMessage(),true)); +} + +//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. +try { + $result=$okex->position()->getAll(); + print_r($result); +}catch (\Exception $e){ + print_r(json_decode($e->getMessage(),true)); +} +``` + [More Test](https://github.com/zhouaini528/okex-php/tree/master/tests/future) [More API](https://github.com/zhouaini528/okex-php/tree/master/src/Api/Futures) - -### Margin Trading API -being developed -### Futures Trading API -being developed -### Perpetual Swap API -being developed diff --git a/README_CN.md b/README_CN.md index daca73a..8c2f90d 100644 --- a/README_CN.md +++ b/README_CN.md @@ -152,7 +152,7 @@ try { [更多API请查看](https://github.com/zhouaini528/okex-php/tree/master/src/Api/Spot) -### 期货交易 API +### 期货交割 API Instrument related API [More](https://github.com/zhouaini528/okex-php/blob/master/tests/future/instrument.php) ```php @@ -277,13 +277,137 @@ try { } ``` +### 期货永续 API + +Instrument related API [More](https://github.com/zhouaini528/okex-php/blob/master/tests/swap/instrument.php) +```php +$okex=new OkexFuture(); + +//List all contracts. This request does not support pagination. The full list will be returned for a request. +try { + $result=$okex->instrument()->getDepth([ + 'instrument_id'=>'BTC-USD-SWAP', + 'size'=>10, + ]); + + print_r($result); +}catch (\Exception $e){ + print_r(json_decode($e->getMessage(),true)); +} + +//Get market data. This endpoint provides the snapshots of market data and can be used without verifications. +try { + $result=$okex->instrument()->get(); + print_r($result); +}catch (\Exception $e){ + print_r(json_decode($e->getMessage(),true)); +} +``` + +Order related API [More](https://github.com/zhouaini528/okex-php/blob/master/tests/swap/order.php) +```php +$okex=new OkexFuture($key,$secret,$passphrase); + +//Place an Order +try { + $result=$okex->order()->post([ + 'instrument_id'=>'BTC-USD-SWAP', + 'type'=>'1', + 'price'=>'5000', + 'size'=>'1', + ]); + print_r($result); +}catch (\Exception $e){ + print_r(json_decode($e->getMessage(),true)); +} +sleep(1); + +//Get order details by order ID. +try { + $result=$okex->order()->get([ + 'instrument_id'=>'BTC-USD-SWAP', + 'order_id'=>$result['order_id'], + ]); + print_r($result); +}catch (\Exception $e){ + print_r(json_decode($e->getMessage(),true)); +} +sleep(1); + +//Cancelling an unfilled order. +try { + $result=$okex->order()->postCancel([ + 'instrument_id'=>'BTC-USD-SWAP', + 'order_id'=>$result['order_id'], + ]); + print_r($result); +}catch (\Exception $e){ + print_r(json_decode($e->getMessage(),true)); +} +``` + +Accounts related API [More](https://github.com/zhouaini528/okex-php/blob/master/tests/swap/accounts.php) +```php +$okex=new OkexSpot($key,$secret,$passphrase); +//This endpoint supports getting the list of assets(only show pairs with balance larger than 0), the balances, amount available/on hold in spot accounts. +try { + $result=$okex->account()->getAll(); + print_r($result); +}catch (\Exception $e){ + print_r(json_decode($e->getMessage(),true)); +} + +//This endpoint supports getting the balance, amount available/on hold of a token in spot account. +try { + $result=$okex->account()->get([ + 'instrument_id'=>'BTC-USD-SWAP' + ]); + print_r($result); +}catch (\Exception $e){ + print_r(json_decode($e->getMessage(),true)); +} + +//All paginated requests return the latest information (newest) as the first page sorted by newest (in chronological time) first. +try { + $result=$okex->account()->getLedger([ + 'instrument_id'=>'BTC-USD-SWAP', + 'limit'=>2, + //'type'=>'1', + //'from'=>'', + //'to'=>'', + ]); + print_r($result); +}catch (\Exception $e){ + print_r(json_decode($e->getMessage(),true)); +} +``` + +Position related API [More](https://github.com/zhouaini528/okex-php/blob/master/tests/swap/position.php) +```php +$okex=new OkexFuture($key,$secret,$passphrase); + +//Get the information of holding positions of a contract. +try { + $result=$okex->position()->get([ + 'instrument_id'=>'BTC-USD-SWAP', + ]); + print_r($result); +}catch (\Exception $e){ + print_r(json_decode($e->getMessage(),true)); +} + +//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. +try { + $result=$okex->position()->getAll(); + print_r($result); +}catch (\Exception $e){ + print_r(json_decode($e->getMessage(),true)); +} +``` + + + + [更多用例请查看](https://github.com/zhouaini528/okex-php/tree/master/tests/future) [更多API请查看](https://github.com/zhouaini528/okex-php/tree/master/src/Api/Futures) - -### Margin Trading API -being developed -### Futures Trading API -being developed -### Perpetual Swap API -being developed diff --git a/src/Api/Swap/Accounts.php b/src/Api/Swap/Accounts.php index 79a26c9..7c3a09c 100644 --- a/src/Api/Swap/Accounts.php +++ b/src/Api/Swap/Accounts.php @@ -5,35 +5,74 @@ namespace Lin\Okex\Api\Swap; +use Lin\Okex\Request; - -class Accounts +class Accounts extends Request { public function getAll(){ + $this->type='GET'; + $this->path='/api/swap/v3/accounts'; + return $this->exec(); } - public function get(){ + /** + * GET GET /api/swap/v3//accounts + * */ + public function get(array $data=[]){ + $this->type='GET'; + $this->path='/api/swap/v3/'.$data['instrument_id'].'/accounts'; + + $this->data=$data; + return $this->exec(); } - public function getSettings(){ + /** + * GET /api/swap/v3/accounts//settings + * */ + public function getSettings(array $data=[]){ + $this->type='GET'; + $this->path='/api/swap/v3/accounts/'.$data['instrument_id'].'/settings'; + + $this->data=$data; + return $this->exec(); } - /* public function getLeverage(){ + /** + * POST /api/swap/v3/accounts//leverage + * */ + public function postLeverage(array $data=[]){ + $this->type='POST'; + $this->path='/api/swap/v3/accounts/'.$data['instrument_id'].'/leverage'; - } */ - - public function postLeverage(){ + $this->data=$data; + return $this->exec(); } - public function getLedger(){ + /** + * GET /api/swap/v3/accounts//ledger + * */ + public function getLedger(array $data=[]){ + $this->type='GET'; + $this->path='/api/swap/v3/accounts/'.$data['instrument_id'].'/ledger'; + + $this->data=$data; + return $this->exec(); } - public function getHolds(){ + /** + * GET /api/swap/v3/accounts//holds + * */ + public function getHolds(array $data=[]){ + $this->type='GET'; + $this->path='/api/swap/v3/accounts/'.$data['instrument_id'].'/holds'; + + $this->data=$data; + return $this->exec(); } } \ No newline at end of file diff --git a/src/Api/Swap/Fills.php b/src/Api/Swap/Fills.php index 4d9ce49..7c46177 100644 --- a/src/Api/Swap/Fills.php +++ b/src/Api/Swap/Fills.php @@ -5,11 +5,17 @@ namespace Lin\Okex\Api\Swap; +use Lin\Okex\Request; - -class Fills +class Fills extends Request { + /** + * GET /api/swap/v3/fills + * */ public function get(){ + $this->type='GET'; + $this->path='/api/swap/v3/fills'; + return $this->exec(); } } \ No newline at end of file diff --git a/src/Api/Swap/Instrments.php b/src/Api/Swap/Instrments.php deleted file mode 100644 index c191160..0000000 --- a/src/Api/Swap/Instrments.php +++ /dev/null @@ -1,66 +0,0 @@ - - * */ - -namespace Lin\Okex\Api\Swap; - - -class Instruments -{ - public function get(){ - - } - - public function getDepth(){ - - } - - public function getTickerAll(){ - - } - - public function getTicker(){ - - } - - public function getTrades(){ - - } - - public function getCandles(){ - - } - - public function getIndex(){ - - } - - public function getOpenInterest(){ - - } - - public function getPriceLimit(){ - - } - - public function getLiquidation(){ - - } - - public function getHolds(){ - - } - - public function getFundingTime(){ - - } - - public function getMarkPrice(){ - - } - - public function getHistoricalFundingRate(){ - - } -} \ No newline at end of file diff --git a/src/Api/Swap/Instruments.php b/src/Api/Swap/Instruments.php new file mode 100644 index 0000000..a759270 --- /dev/null +++ b/src/Api/Swap/Instruments.php @@ -0,0 +1,139 @@ + + * */ + +namespace Lin\Okex\Api\Swap; + +use Lin\Okex\Request; + +class Instruments extends Request +{ + /** + * GET /api/swap/v3/instruments + * */ + public function get(){ + $this->type='GET'; + $this->path='/api/swap/v3/instruments'; + + return $this->exec(); + } + + /** + * /api/swap/v3/instruments//depth + * */ + public function getDepth(array $data=[]){ + $this->type='GET'; + $this->path='/api/swap/v3/instruments/'.$data['instrument_id'].'/depth'; + + $this->data=$data; + + return $this->exec(); + } + + public function getTickerAll(){ + $this->type='GET'; + $this->path='/api/swap/v3/instruments/ticker'; + + return $this->exec(); + } + + public function getTicker(array $data=[]){ + $this->type='GET'; + $this->path='/api/swap/v3/instruments/'.$data['instrument_id'].'/ticker'; + + $this->data=$data; + + return $this->exec(); + } + + public function getTrades(array $data=[]){ + $this->type='GET'; + $this->path='/api/swap/v3/instruments/'.$data['instrument_id'].'/trades'; + + $this->data=$data; + + return $this->exec(); + } + + public function getCandles(array $data=[]){ + $this->type='GET'; + $this->path='/api/swap/v3/instruments/'.$data['instrument_id'].'/candles'; + + $this->data=$data; + + return $this->exec(); + } + + public function getIndex(array $data=[]){ + $this->type='GET'; + $this->path='/api/swap/v3/instruments/'.$data['instrument_id'].'/index'; + + $this->data=$data; + + return $this->exec(); + } + + public function getOpenInterest(array $data=[]){ + $this->type='GET'; + $this->path='/api/swap/v3/instruments/'.$data['instrument_id'].'/open_interest'; + + $this->data=$data; + + return $this->exec(); + } + + public function getPriceLimit(array $data=[]){ + $this->type='GET'; + $this->path='/api/swap/v3/instruments/'.$data['instrument_id'].'/price_limit'; + + $this->data=$data; + + return $this->exec(); + } + + public function getLiquidation(array $data=[]){ + $this->type='GET'; + $this->path='/api/swap/v3/instruments/'.$data['instrument_id'].'/liquidation'; + + $this->data=$data; + + return $this->exec(); + } + + public function getHolds(array $data=[]){ + $this->type='GET'; + $this->path='/api/swap/v3/accounts/'.$data['instrument_id'].'/holds'; + + $this->data=$data; + + return $this->exec(); + } + + public function getFundingTime(array $data=[]){ + $this->type='GET'; + $this->path='/api/swap/v3/instruments/'.$data['instrument_id'].'/funding_time'; + + $this->data=$data; + + return $this->exec(); + } + + public function getMarkPrice(array $data=[]){ + $this->type='GET'; + $this->path='/api/swap/v3/instruments/'.$data['instrument_id'].'/mark_price'; + + $this->data=$data; + + return $this->exec(); + } + + public function getHistoricalFundingRate(array $data=[]){ + $this->type='GET'; + $this->path='/api/swap/v3/instruments/'.$data['instrument_id'].'/historical_funding_rate'; + + $this->data=$data; + + return $this->exec(); + } +} \ No newline at end of file diff --git a/src/Api/Swap/Orders.php b/src/Api/Swap/Orders.php index c3014f9..2cd6bbc 100644 --- a/src/Api/Swap/Orders.php +++ b/src/Api/Swap/Orders.php @@ -7,29 +7,69 @@ -class Orders +use Lin\Okex\Request; + +class Orders extends Request { - public function post(){ + public function post(array $data=[]){ + $this->type='POST'; + $this->path='/api/swap/v3/order'; + + $this->data=$data; + return $this->exec(); } - public function postBatch(){ + public function postBatch(array $data=[]){ + $this->type='POST'; + $this->path='/api/swap/v3/orders'; + + $this->data=$data; + return $this->exec(); } - public function postCancel(){ + public function postCancel(array $data=[]){ + $id=$data['order_id'] ?? $data['client_oid']; + unset($data['order_id']); + unset($data['client_oid']); + + $this->type='POST'; + $this->path='/api/swap/v3/cancel_order/'.$data['instrument_id'].'/'.$id; + + $this->data=$data; + return $this->exec(); } - public function postCancelBatch(){ + public function postCancelBatch(array $data=[]){ + $this->type='POST'; + $this->path='/api/swap/v3/cancel_batch_orders/'.$data['instrument_id']; + $this->data=$data; + + return $this->exec(); } - public function getAll(){ + public function getAll(array $data=[]){ + $this->type='GET'; + $this->path='/api/swap/v3/orders/'.$data['instrument_id']; + + $this->data=$data; + return $this->exec(); } - public function get(){ + public function get(array $data=[]){ + $id=$data['order_id'] ?? $data['client_oid']; + unset($data['order_id']); + unset($data['client_oid']); + + $this->type='GET'; + $this->path='/api/swap/v3/orders/'.$data['instrument_id'].'/'.$id; + + $this->data=$data; + return $this->exec(); } } \ No newline at end of file diff --git a/src/Api/Swap/Position.php b/src/Api/Swap/Position.php index 9ee65b2..bbe8c74 100644 --- a/src/Api/Swap/Position.php +++ b/src/Api/Swap/Position.php @@ -7,13 +7,26 @@ -class Position +use Lin\Okex\Request; + +class Position extends Request { public function getAll(){ + $this->type='GET'; + $this->path='/api/swap/v3/position'; + return $this->exec(); } - public function get(){ + /** + * GET /api/swap/v3/BTC-USD-SWAP/position + * */ + public function get(array $data=[]){ + $this->type='GET'; + $this->path='/api/swap/v3/'.$data['instrument_id'].'/position'; + + $this->data=$data; + return $this->exec(); } } \ No newline at end of file diff --git a/src/Api/Swap/Rate.php b/src/Api/Swap/Rate.php index 3f2dd57..6131745 100644 --- a/src/Api/Swap/Rate.php +++ b/src/Api/Swap/Rate.php @@ -7,9 +7,14 @@ -class Rate +use Lin\Okex\Request; + +class Rate extends Request { public function get(){ + $this->type='GET'; + $this->path='/api/swap/v3/rate'; + return $this->exec(); } } \ No newline at end of file diff --git a/src/OkexSwap.php b/src/OkexSwap.php new file mode 100644 index 0000000..c5f569c --- /dev/null +++ b/src/OkexSwap.php @@ -0,0 +1,114 @@ + + * */ + +namespace Lin\Okex; + + +use Lin\Okex\Api\Swap\Accounts; +use Lin\Okex\Api\Swap\Fills; +use Lin\Okex\Api\Swap\Instruments; +use Lin\Okex\Api\Swap\Orders; +use Lin\Okex\Api\Swap\Position; +use Lin\Okex\Api\Swap\Rate; + +class OkexSwap +{ + protected $key; + protected $secret; + protected $passphrase; + protected $host; + + protected $proxy=false; + + function __construct(string $key='',string $secret='',string $passphrase='',string $host='https://www.okex.com'){ + $this->key=$key; + $this->secret=$secret; + $this->host=$host; + $this->passphrase=$passphrase; + } + + /** + * + * */ + private function init(){ + return [ + 'key'=>$this->key, + 'secret'=>$this->secret, + 'passphrase'=>$this->passphrase, + 'host'=>$this->host, + ]; + } + + /** + * Local development sets the proxy + * @param bool|array + * $proxy=false Default + * $proxy=true Local proxy http://127.0.0.1:12333 + * + * Manual proxy + * $proxy=[ + 'http' => 'http://127.0.0.1:12333', + 'https' => 'http://127.0.0.1:12333', + 'no' => ['.cn'] + * ] + * */ + function setProxy($proxy=true){ + $this->proxy=$proxy; + } + + /** + * + * */ + public function account(){ + $account= new Accounts($this->init()); + $account->proxy($this->proxy); + return $account; + } + + /** + * + * */ + public function fill(){ + $fill= new Fills($this->init()); + $fill->proxy($this->proxy); + return $fill; + } + + /** + * + * */ + public function instrument(){ + $instrument= new Instruments($this->init()); + $instrument->proxy($this->proxy); + return $instrument; + } + + /** + * + * */ + public function order(){ + $order= new Orders($this->init()); + $order->proxy($this->proxy); + return $order; + } + + /** + * + * */ + public function position(){ + $position= new Position($this->init()); + $position->proxy($this->proxy); + return $position; + } + + /** + * + * */ + public function rate(){ + $rate= new Rate($this->init()); + $rate->proxy($this->proxy); + return $rate; + } +} \ No newline at end of file diff --git a/tests/swap/accounts.php b/tests/swap/accounts.php new file mode 100644 index 0000000..90292aa --- /dev/null +++ b/tests/swap/accounts.php @@ -0,0 +1,51 @@ + + * + * Fill in your key and secret and pass can be directly run + * + * Most of them are unfinished and need your help + * https://github.com/zhouaini528/okex-php.git + * */ +use Lin\Okex\OkexSwap; + +require __DIR__ .'../../../vendor/autoload.php'; + +include 'key_secret.php'; + +$okex=new OkexSwap($key,$secret,$passphrase); +$okex->setProxy(); + +//This endpoint supports getting the list of assets(only show pairs with balance larger than 0), the balances, amount available/on hold in spot accounts. +try { + $result=$okex->account()->getAll(); + print_r($result); +}catch (\Exception $e){ + print_r(json_decode($e->getMessage(),true)); +} + +//This endpoint supports getting the balance, amount available/on hold of a token in spot account. +try { + $result=$okex->account()->get([ + 'instrument_id'=>'BTC-USD-SWAP' + ]); + print_r($result); +}catch (\Exception $e){ + print_r(json_decode($e->getMessage(),true)); +} + +//All paginated requests return the latest information (newest) as the first page sorted by newest (in chronological time) first. +try { + $result=$okex->account()->getLedger([ + 'instrument_id'=>'BTC-USD-SWAP', + 'limit'=>2, + //'type'=>'1', + //'from'=>'', + //'to'=>'', + ]); + print_r($result); +}catch (\Exception $e){ + print_r(json_decode($e->getMessage(),true)); +} diff --git a/tests/swap/instrument.php b/tests/swap/instrument.php new file mode 100644 index 0000000..5ebfc44 --- /dev/null +++ b/tests/swap/instrument.php @@ -0,0 +1,37 @@ + + * + * Fill in your key and secret and pass can be directly run + * + * Most of them are unfinished and need your help + * https://github.com/zhouaini528/okex-php.git + * */ +use Lin\Okex\OkexSwap; + +require __DIR__ .'../../../vendor/autoload.php'; + +$okex=new OkexSwap(); +$okex->setProxy(); + +//List all contracts. This request does not support pagination. The full list will be returned for a request. +try { + $result=$okex->instrument()->getDepth([ + 'instrument_id'=>'BTC-USD-SWAP', + 'size'=>10, + ]); + + print_r($result); +}catch (\Exception $e){ + print_r(json_decode($e->getMessage(),true)); +} + +//Get market data. This endpoint provides the snapshots of market data and can be used without verifications. +try { + $result=$okex->instrument()->get(); + print_r($result); +}catch (\Exception $e){ + print_r(json_decode($e->getMessage(),true)); +} \ No newline at end of file diff --git a/tests/swap/key_secret.php b/tests/swap/key_secret.php new file mode 100644 index 0000000..b977e5c --- /dev/null +++ b/tests/swap/key_secret.php @@ -0,0 +1,4 @@ + + * + * Fill in your key and secret and pass can be directly run + * + * Most of them are unfinished and need your help + * https://github.com/zhouaini528/okex-php.git + * */ +use Lin\Okex\OkexSwap; + +require __DIR__ .'../../../vendor/autoload.php'; + +include 'key_secret.php'; + +$okex=new OkexSwap($key,$secret,$passphrase); +$okex->setProxy(); + +//Place an Order +try { + $result=$okex->order()->post([ + 'instrument_id'=>'BTC-USD-SWAP', + 'type'=>'1', + 'price'=>'5000', + 'size'=>'1', + ]); + print_r($result); +}catch (\Exception $e){ + print_r(json_decode($e->getMessage(),true)); +} +sleep(1); + +//Get order details by order ID. +try { + $result=$okex->order()->get([ + 'instrument_id'=>'BTC-USD-SWAP', + 'order_id'=>$result['order_id'], + ]); + print_r($result); +}catch (\Exception $e){ + print_r(json_decode($e->getMessage(),true)); +} +sleep(1); + +//Cancelling an unfilled order. +try { + $result=$okex->order()->postCancel([ + 'instrument_id'=>'BTC-USD-SWAP', + 'order_id'=>$result['order_id'], + ]); + print_r($result); +}catch (\Exception $e){ + print_r(json_decode($e->getMessage(),true)); +} + + + diff --git a/tests/swap/position.php b/tests/swap/position.php new file mode 100644 index 0000000..b58a0af --- /dev/null +++ b/tests/swap/position.php @@ -0,0 +1,37 @@ + + * + * Fill in your key and secret and pass can be directly run + * + * Most of them are unfinished and need your help + * https://github.com/zhouaini528/okex-php.git + * */ +use Lin\Okex\OkexSwap; + +require __DIR__ .'../../../vendor/autoload.php'; + +include 'key_secret.php'; + +$okex=new OkexSwap($key,$secret,$passphrase); +$okex->setProxy(); + +//Get the information of holding positions of a contract. +try { + $result=$okex->position()->get([ + 'instrument_id'=>'BTC-USD-SWAP', + ]); + print_r($result); +}catch (\Exception $e){ + print_r(json_decode($e->getMessage(),true)); +} + +//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. +try { + $result=$okex->position()->getAll(); + print_r($result); +}catch (\Exception $e){ + print_r(json_decode($e->getMessage(),true)); +} \ No newline at end of file diff --git a/tests/swap/proxy.php b/tests/swap/proxy.php new file mode 100644 index 0000000..e944c78 --- /dev/null +++ b/tests/swap/proxy.php @@ -0,0 +1,45 @@ + + * + * Fill in your key and secret and pass can be directly run + * + * Most of them are unfinished and need your help + * https://github.com/zhouaini528/okex-php.git + * */ +use Lin\Okex\OkexFuture; + +require __DIR__ .'../../../vendor/autoload.php'; + +include 'key_secret.php'; + +$okex=new OkexFuture($key,$secret,$passphrase); + +//If you are developing locally and need an agent, you can set this +$okex->setProxy(); + +//More flexible Settings +$okex->setProxy([ + 'http' => 'http://127.0.0.1:12333', + 'https' => 'http://127.0.0.1:12333', +]); + +//Get the information of holding positions of a contract. +try { + $result=$okex->position()->get([ + 'instrument_id'=>'BTC-USD-190628', + ]); + print_r($result); +}catch (\Exception $e){ + print_r(json_decode($e->getMessage(),true)); +} + +//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. +try { + $result=$okex->position()->getAll(); + print_r($result); +}catch (\Exception $e){ + print_r(json_decode($e->getMessage(),true)); +} \ No newline at end of file