Skip to content

Commit

Permalink
add v5 api
Browse files Browse the repository at this point in the history
  • Loading branch information
zhouaini528 committed Mar 25, 2021
1 parent d17eb3a commit 634485d
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 7 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ composer require linwj/okex
Support for more request Settings [More](https://github.com/zhouaini528/okex-php/blob/master/tests/spot/proxy.php#L21)
```php
$okex=new OkexSpot();
//or
$okex=new OkexSpot($key,$secret,$passphrase);

//You can set special needs
$okex->setOptions([
//Set the request timeout to 60 seconds by default
Expand All @@ -75,9 +78,16 @@ $okex->setOptions([
], */
//Close the certificate
//'verify'=>false,

//Set Demo Trading
//'headers'=>['x-simulated-trading'=>1]
]);
```

### Okex V5 API

[Click to view](https://github.com/zhouaini528/okex-php/blob/master/tests/okex_v5)

### Spot Trading API

Instrument related API [More](https://github.com/zhouaini528/okex-php/blob/master/tests/spot/instrument.php)
Expand Down
10 changes: 10 additions & 0 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ composer require linwj/okex
支持本地开发代理设置 [More](https://github.com/zhouaini528/okex-php/blob/master/tests/spot/proxy.php#L21)
```php
$okex=new OkexSpot();
//or
$okex=new OkexSpot($key,$secret,$passphrase);

//You can set special needs
$okex->setOptions([
//Set the request timeout to 60 seconds by default
Expand All @@ -77,9 +80,16 @@ $okex->setOptions([
], */
//Close the certificate
//'verify'=>false,

//Set Demo Trading
//'headers'=>['x-simulated-trading'=>1]
]);
```

### Okex V5 API

[点击查看](https://github.com/zhouaini528/okex-php/blob/master/tests/okex_v5)

### 现货交易 API

Instrument related API [More](https://github.com/zhouaini528/okex-php/blob/master/tests/spot/instrument.php)
Expand Down
8 changes: 4 additions & 4 deletions src/Api/OkexV5/Trade.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ public function getFills(array $data=[]){
/**
*POST /api/v5/trade/order-algo
* */
public function getOrderAlgo(array $data=[]){
$this->type='GET';
public function postOrderAlgo(array $data=[]){
$this->type='POST';
$this->path='/api/v5/trade/order-algo';

$this->data=$data;
Expand All @@ -155,8 +155,8 @@ public function getOrderAlgo(array $data=[]){
/**
*POST /api/v5/trade/cancel-algos
* */
public function getCancelAlgos(array $data=[]){
$this->type='GET';
public function postCancelAlgos(array $data=[]){
$this->type='POST';
$this->path='/api/v5/trade/cancel-algos';

$this->data=$data;
Expand Down
5 changes: 2 additions & 3 deletions tests/okex_v5/account.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
//Close the certificate
//'verify'=>false,

//set Demo Trading
//Set Demo Trading
'headers'=>['x-simulated-trading'=>1]
]);
/*

try {
$result=$okex->account()->getBalance();
print_r($result);
Expand Down Expand Up @@ -80,7 +80,6 @@
}catch (\Exception $e){
print_r(json_decode($e->getMessage(),true));
}
*/

try {
$result=$okex->account()->postSetLeverage([
Expand Down
106 changes: 106 additions & 0 deletions tests/okex_v5/trade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<?php


/**
* @author lin <[email protected]>
*
* Fill in your key and secret and pass can be directly run
*
* Most of them are unfinished and need your help
* https://github.com/zhouaini528/okex-php.git
* */
use Lin\Okex\OkexV5;

require __DIR__ .'../../../vendor/autoload.php';

include 'key_secret.php';

$okex=new OkexV5($key,$secret,$passphrase);

//You can set special needs
$okex->setOptions([
//Set the request timeout to 60 seconds by default
'timeout'=>10,

//If you are developing locally and need an agent, you can set this
//'proxy'=>true,
//More flexible Settings
/* 'proxy'=>[
'http' => 'http://127.0.0.1:12333',
'https' => 'http://127.0.0.1:12333',
'no' => ['.cn']
], */
//Close the certificate
//'verify'=>false,

//Set Demo Trading
'headers'=>['x-simulated-trading'=>1]
]);

try {
$result=$okex->trade()->postOrder([
'instId'=>'BTC-USDT',
'tdMode'=>'cross',
'clOrdId'=>'xxxxxxxxxxx',
'side'=>'buy',
'ordType'=>'limit',
'sz'=>'0.01',
'px'=>'10000',
]);
print_r($result);
}catch (\Exception $e){
print_r(json_decode($e->getMessage(),true));
}

try {
$result=$okex->trade()->postCancelOrder([
'instId'=>'BTC-USDT',
'ordId'=>'xxxxxxxxx',
//'clOrdId'=>'xxxxxxxxxxx',
]);
print_r($result);
}catch (\Exception $e){
print_r(json_decode($e->getMessage(),true));
}


try {
$result=$okex->trade()->postAmendOrder([
'instId'=>'BTC-USDT',
'ordId'=>'xxxxxxxxx',
//'clOrdId'=>'xxxxxxxxxxx',
'newSz'=>'0.012',
'newPx'=>'11000',
]);
print_r($result);
}catch (\Exception $e){
print_r(json_decode($e->getMessage(),true));
}

try {
$result=$okex->trade()->getOrder([
'instId'=>'BTC-USDT',
'ordId'=>'xxxxxxxxx',
//'clOrdId'=>'xxxxxxxxxxx',
]);
print_r($result);
}catch (\Exception $e){
print_r(json_decode($e->getMessage(),true));
}


try {
$result=$okex->trade()->postOrderAlgo([
'instId'=>'BTC-USDT',
'tdMode'=>'cross',
'clOrdId'=>'xxxxxxxxxxx',
'side'=>'buy',
'ordType'=>'trigger',
'sz'=>'0.01',
]);
print_r($result);
}catch (\Exception $e){
print_r(json_decode($e->getMessage(),true));
}


0 comments on commit 634485d

Please sign in to comment.