Skip to content

Commit

Permalink
init ftx
Browse files Browse the repository at this point in the history
  • Loading branch information
zhouaini528 committed Oct 12, 2021
1 parent f3fcb51 commit 13045aa
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 230 deletions.
281 changes: 53 additions & 228 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,329 +62,154 @@ composer require linwj/ftx
Support for more request Settings
```php
//spot
use Lin\Coinex\CoinexExchange;
$coinex=new CoinexExchange();

//future
use Lin\Coinex\CoinexPerpetual;
$coinex=new CoinexPerpetual();
use Lin\Ftx\Ftx;
$ftx=new Ftx();
//or
$ftx=new Ftx($key,$secret);

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

//https://github.com/guzzle/guzzle
'proxy'=>[],
//'proxy'=>[],

//https://www.php.net/manual/en/book.curl.php
'curl'=>[],
//'curl'=>[],

//FTX-SUBACCOUNT (optional): URI-encoded name of the subaccount to use. Omit if not using subaccounts.
//'headers'=>['FTX-SUBACCOUNT'=>'xxxx']
]);
```

### Exchange Spot

Market API [More](https://github.com/zhouaini528/coinex-php/tree/master/src/Api/Exchange/Market.php)

```php
$coinex=new CoinexExchange();

try {
$result=$coinex->market()->getList();
print_r($result);
}catch (\Exception $e){
print_r(json_decode($e->getMessage(),true));
}

try {
$result=$coinex->market()->getTicker([
'market'=>'BCHBTC'
]);
print_r($result);
}catch (\Exception $e){
print_r(json_decode($e->getMessage(),true));
}

try {
$result=$coinex->market()->getDepth([
'market'=>'BCHBTC',
'merge'=>'0.1'
]);
print_r($result);
}catch (\Exception $e){
print_r(json_decode($e->getMessage(),true));
}

try {
$result=$coinex->market()->getKline([
'market'=>'BCHBTC',
'type'=>'4hour'
]);
print_r($result);
}catch (\Exception $e){
print_r(json_decode($e->getMessage(),true));
}
```

Account API [More](https://github.com/zhouaini528/coinex-php/tree/master/src/Api/Exchange/Account.php)
Market API [More](https://github.com/zhouaini528/ftx-php/tree/master/src/Api/Markets.php)

```php
$coinex=new CoinexExchange($key,$secret);
$ftx=new Ftx();

try {
$result=$coinex->account()->getBalanceInfo([
//You can 'access_id' and 'tonxe' leave it blank
'access_id'=>$key,
'tonce'=>time().'000',
]);

//You can 'access_id' and 'tonxe' leave it blank
$result=$coinex->account()->getBalanceInfo();
print_r($result);
}catch (\Exception $e){
print_r(json_decode($e->getMessage(),true));
}

try {
//You can 'access_id' and 'tonxe' leave it blank
$result=$coinex->account()->getBalanceCoinWithdraw();
$result=$ftx->markets()->gets();
print_r($result);
}catch (\Exception $e){
print_r(json_decode($e->getMessage(),true));
print_r($e->getMessage());
}

try {
$result=$coinex->account()->getCreditInfo();
print_r($result);
}catch (\Exception $e){
print_r(json_decode($e->getMessage(),true));
}
```


Trading API [More](https://github.com/zhouaini528/coinex-php/tree/master/src/Api/Exchange/Trading.php)

```php
$coinex=new CoinexExchange($key,$secret);

try {
//You can 'access_id' and 'tonxe' leave it blank
$result=$coinex->trading()->postMarket([
//'access_id'=>'xxxxx',
//'tonce'=>time().'000',
'market'=>'BCHBTC',
'type'=>'sell',
'amount'=>'1',
'client_id'=>'99999999',
$result=$ftx->markets()->get([
'market_name'=>'BTC/USD',// BTC/USD BTC-PERP BTC-0626
//'depth'=>'10'
]);
print_r($result);
}catch (\Exception $e){
print_r(json_decode($e->getMessage(),true));
print_r($e->getMessage());
}

try {
//You can 'access_id' and 'tonxe' leave it blank
$result=$coinex->trading()->getStatus([
//'access_id'=>'xxxxx',
//'tonce'=>time().'000',
'id'=>'99999999',
'market'=>'BCHBTC',
$result=$ftx->markets()->getOrderBook([
'market_name'=>'BTC-PERP',// BTC/USD BTC-PERP BTC-0626
//'depth'=>'10'
]);
print_r($result);
}catch (\Exception $e){
print_r(json_decode($e->getMessage(),true));
print_r($e->getMessage());
}

try {
//You can 'access_id' and 'tonxe' leave it blank
$result=$coinex->trading()->deletePending([
'id'=>'9999999',
'market'=>'BCHBTC',
'type'=>'0'
$result=$ftx->markets()->getTrades([
'market_name'=>'BTC-0626',// BTC/USD BTC-PERP BTC-0626
//'depth'=>'10'
]);
print_r($result);
}catch (\Exception $e){
print_r(json_decode($e->getMessage(),true));
print_r($e->getMessage());
}
```


Margin API [More](https://github.com/zhouaini528/coinex-php/tree/master/src/Api/Exchange/Margin.php)

```php
$coinex=new CoinexExchange($key,$secret);

try {
//You can 'access_id' and 'tonxe' leave it blank
$result=$coinex->margin()->getAccount([
'market'=>'BCHBTC'
$result=$ftx->markets()->getCandles([
'market_name'=>'BTC-0628',// BTC/USD BTC-PERP BTC-0626
'resolution'=>'60'
]);
print_r($result);
}catch (\Exception $e){
print_r(json_decode($e->getMessage(),true));
}

try {
$result=$coinex->margin()->getMarket();
print_r($result);
}catch (\Exception $e){
print_r(json_decode($e->getMessage(),true));
print_r($e->getMessage());
}
```

More Test [more](https://github.com/zhouaini528/coinex-php/blob/master/tests/exchange)

### Perpetual Futures


Market API [More](https://github.com/zhouaini528/coinex-php/tree/master/src/Api/Perpetual/Market.php)
Account API [More](https://github.com/zhouaini528/ftx-php/tree/master/src/Api/Account.php)

```php
$coinex=new CoinexPerpetual();
$ftx=new Ftx($key,$secret);

try {
$result=$coinex->market()->getList();
$result=$ftx->account()->get();
print_r($result);
}catch (\Exception $e){
print_r($e->getMessage());
}

try {
$result=$coinex->market()->getLimitConfig();
print_r($result);
}catch (\Exception $e){
print_r($e->getMessage());
}

try {
$result=$coinex->market()->getTicker([
'market'=>'BTCUSD'
]);
print_r($result);
}catch (\Exception $e){
print_r($e->getMessage());
}

try {
$result=$coinex->market()->getTickerAll();
print_r($result);
}catch (\Exception $e){
print_r($e->getMessage());
}

try {
$result=$coinex->market()->getDepth([
'market'=>'BTCUSD',
'merge'=>'0.1',
'limit'=>'10'
]);
print_r($result);
}catch (\Exception $e){
print_r($e->getMessage());
}

try {
$result=$coinex->market()->getDeals([
'market'=>'BTCUSD',
]);
$result=$ftx->account()->getPositions();
print_r($result);
}catch (\Exception $e){
print_r($e->getMessage());
}
```

Order API [More](https://github.com/zhouaini528/coinex-php/tree/master/src/Api/Perpetual/Order.php)

Orders API [More](https://github.com/zhouaini528/ftx-php/tree/master/src/Api/Orders.php)

```php
$coinex=new CoinexPerpetual($key,$secret);
$ftx=new Ftx($key,$secret);

try {
$result=$coinex->order()->postPutMarket([
'market'=>'BTCUSD',
'side'=>'2',
'amount'=>'10',
'client_id'=>'xxxxxx',
$result=$ftx->orders()->post([
'market'=>'BTC/USD',
'side'=>'buy',
'price'=>'10000',
'type'=>'limit',
'size'=>'1',
//'clientId'=>'1234567890',
]);
print_r($result);
}catch (\Exception $e){
print_r($e->getMessage());
}

try {
$result=$coinex->order()->postPutStopLimit([
'market'=>'BTCUSD',
'side'=>'2',
'amount'=>'10',
'client_id'=>'xxxxxx',

'stop_type'=>'2',
'stop_price'=>'10000',
'price'=>'9000',
$result=$ftx->orders()->get([
'order_id'=>'1234567890',
]);
print_r($result);
}catch (\Exception $e){
print_r($e->getMessage());
}

try {
$result=$coinex->order()->getStatus([
'market'=>'BTCUSD',
'order_id'=>'9999999',
$result=$ftx->orders()->getByClientId([
'client_order_id'=>'1234567890',
]);
print_r($result);
}catch (\Exception $e){
print_r($e->getMessage());
}

try {
$result=$coinex->order()->postCancel([
'market'=>'BTCUSD',
'order_id'=>'9999999',
]);
print_r($result);
}catch (\Exception $e){
print_r($e->getMessage());
}
```

Position API [More](https://github.com/zhouaini528/coinex-php/tree/master/src/Api/Perpetual/Position.php)

```php
$coinex=new CoinexPerpetual($key,$secret);

try {
$result=$coinex->position()->getPending([
'market'=>'BTCUSD',
]);
print_r($result);
}catch (\Exception $e){
print_r($e->getMessage());
}

try {
$result=$coinex->position()->getFunding([
'market'=>'BTCUSD',
'offset'=>'10',
'limit'=>'10'
$result=$ftx->orders()->delete([
'order_id'=>'1234567890',
]);
print_r($result);
}catch (\Exception $e){
print_r($e->getMessage());
}

try {
$result=$coinex->position()->postAdjustMargin([
'market'=>'BTCUSD',
'amount'=>'1',
'type'=>'1',
$result=$ftx->orders()->deleteByClientId([
'client_order_id'=>'1234567890',
]);
print_r($result);
}catch (\Exception $e){
print_r($e->getMessage());
}
```

More Test [more](https://github.com/zhouaini528/coinex-php/tree/master/tests/perpetual)
More Test [more](https://github.com/zhouaini528/ftx-php/tree/master/tests)



4 changes: 2 additions & 2 deletions tests/markets.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
//'headers'=>['FTX-SUBACCOUNT'=>'xxxx']
]);

/*try {
try {
$result=$ftx->markets()->gets();
print_r($result);
}catch (\Exception $e){
print_r($e->getMessage());
}*/
}

try {
$result=$ftx->markets()->get([
Expand Down

0 comments on commit 13045aa

Please sign in to comment.