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 f57d23f commit f3fcb51
Show file tree
Hide file tree
Showing 6 changed files with 358 additions and 1 deletion.
183 changes: 183 additions & 0 deletions src/Api/Orders.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
<?php
/**
* @author lin <[email protected]>
* */

namespace Lin\Ftx\Api;

use Lin\Ftx\Request;

class Orders extends Request
{
//authenticat requests signature
protected $authorization=true;

/**
*GET /orders?market={market}
* */
public function gets(array $data=[]){
$this->type='GET';
$this->path='/orders';
$this->data=$data;
return $this->exec();
}

/**
*GET /orders/history?market={market}
* */
public function getHistory(array $data=[]){
$this->type='GET';
$this->path='/orders/history';
$this->data=$data;
return $this->exec();
}

/**
*GET /conditional_orders?market={market}
* */
public function getConditionalOrders(array $data=[]){
$this->type='GET';
$this->path='/conditional_orders';
$this->data=$data;
return $this->exec();
}

/**
*GET /conditional_orders/{conditional_order_id}/triggers
* */
public function getConditionalOrderId(array $data=[]){
$this->type='GET';
$this->path='/conditional_orders/'.$data['conditional_order_id'].'/triggers';
unset($data['conditional_order_id']);
$this->data=$data;
return $this->exec();
}

/**
*GET /conditional_orders/history?market={market}
* */
public function getConditionalOrdersHistory(array $data=[]){
$this->type='GET';
$this->path='/conditional_orders/history';
$this->data=$data;
return $this->exec();
}

/**
*POST /orders
* */
public function post(array $data=[]){
$this->type='POST';
$this->path='/orders';
$this->data=$data;
return $this->exec();
}

/**
*POST /conditional_orders
* */
public function postConditionalOrders(array $data=[]){
$this->type='POST';
$this->path='/conditional_orders';
$this->data=$data;
return $this->exec();
}

/**
*POST /orders/{order_id}/modify
* */
public function postModify(array $data=[]){
$this->type='POST';
$this->path='/orders/'.$data['order_id'].'/modify';
unset($data['order_id']);
$this->data=$data;
return $this->exec();
}

/**
*POST /orders/by_client_id/{client_order_id}/modify
* */
public function postByClientIdModify(array $data=[]){
$this->type='POST';
$this->path='/orders/by_client_id/'.$data['client_order_id'].'/modify';
unset($data['client_order_id']);
$this->data=$data;
return $this->exec();
}

/**
*POST /conditional_orders/{order_id}/modify
* */
public function postConditionalOrdersModify(array $data=[]){
$this->type='POST';
$this->path='/conditional_orders/'.$data['order_id'].'/modify';
unset($data['order_id']);
$this->data=$data;
return $this->exec();
}

/**
*GET /orders/{order_id}
* */
public function get(array $data=[]){
$this->type='GET';
$this->path='/orders/'.$data['order_id'];
unset($data['order_id']);
$this->data=$data;
return $this->exec();
}

/**
*GET /orders/by_client_id/{client_order_id}
* */
public function getByClientId(array $data=[]){
$this->type='GET';
$this->path='/orders/by_client_id/'.$data['client_order_id'];
unset($data['client_order_id']);
$this->data=$data;
return $this->exec();
}

/**
*DELETE /orders/{order_id}
* */
public function delete(array $data=[]){
$this->type='DELETE';
$this->path='/orders/'.$data['order_id'];
unset($data['order_id']);
$this->data=$data;
return $this->exec();
}

/**
*DELETE /orders/by_client_id/{client_order_id}
* */
public function deleteByClientId(array $data=[]){
$this->type='DELETE';
$this->path='/orders/by_client_id/'.$data['client_order_id'];
unset($data['client_order_id']);
$this->data=$data;
return $this->exec();
}

/**
*DELETE /conditional_orders/{id}
* */
public function deleteConditionalOrders(array $data=[]){
$this->type='DELETE';
$this->path='/conditional_orders/'.$data['id'];
unset($data['id']);
$this->data=$data;
return $this->exec();
}

/**
*DELETE /orders
* */
public function deletes(array $data=[]){
$this->type='DELETE';
$this->path='/orders';
$this->data=$data;
return $this->exec();
}
}
8 changes: 8 additions & 0 deletions src/Ftx.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

use Lin\Ftx\Api\Account;
use Lin\Ftx\Api\Markets;
use Lin\Ftx\Api\Orders;
use Lin\Ftx\Api\Wallet;

class Ftx
Expand Down Expand Up @@ -67,4 +68,11 @@ function markets(array $options=[]){
function wallet(array $options=[]){
return new Wallet($this->init());
}

/**
*
* */
function orders(array $options=[]){
return new Orders($this->init());
}
}
8 changes: 8 additions & 0 deletions tests/account.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,11 @@
print_r($e->getMessage());
}


try {
$result=$ftx->account()->getPositions();
print_r($result);
}catch (\Exception $e){
print_r($e->getMessage());
}

73 changes: 73 additions & 0 deletions tests/markets.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php
use Lin\Ftx\Ftx;


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

include 'key_secret.php';

$ftx=new Ftx($key,$secret);

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

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

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

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

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

try {
$result=$ftx->markets()->get([
'market_name'=>'BTC/USD',// BTC/USD BTC-PERP BTC-0626
//'depth'=>'10'
]);
print_r($result);
}catch (\Exception $e){
print_r($e->getMessage());
}

try {
$result=$ftx->markets()->getOrderBook([
'market_name'=>'BTC-PERP',// BTC/USD BTC-PERP BTC-0626
//'depth'=>'10'
]);
print_r($result);
}catch (\Exception $e){
print_r($e->getMessage());
}

try {
$result=$ftx->markets()->getTrades([
'market_name'=>'BTC-0626',// BTC/USD BTC-PERP BTC-0626
//'depth'=>'10'
]);
print_r($result);
}catch (\Exception $e){
print_r($e->getMessage());
}

try {
$result=$ftx->markets()->getCandles([
'market_name'=>'BTC-0628',// BTC/USD BTC-PERP BTC-0626
'resolution'=>'60'
]);
print_r($result);
}catch (\Exception $e){
print_r($e->getMessage());
}


72 changes: 72 additions & 0 deletions tests/orders.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php
use Lin\Ftx\Ftx;


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

include 'key_secret.php';

$ftx=new Ftx($key,$secret);

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

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

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

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


try {
$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=$ftx->orders()->get([
'order_id'=>'1234567890',
]);
print_r($result);

$result=$ftx->orders()->getByClientId([
'client_order_id'=>'1234567890',
]);
print_r($result);
}catch (\Exception $e){
print_r($e->getMessage());
}


try {
$result=$ftx->orders()->delete([
'order_id'=>'1234567890',
]);
print_r($result);

$result=$ftx->orders()->deleteByClientId([
'client_order_id'=>'1234567890',
]);
print_r($result);
}catch (\Exception $e){
print_r($e->getMessage());
}




15 changes: 14 additions & 1 deletion tests/wallet.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,17 @@
//'headers'=>['FTX-SUBACCOUNT'=>'xxxx']
]);

$ftx->wallet()->getBalances();
try {
$result=$ftx->wallet()->getBalances();
print_r($result);
}catch (\Exception $e){
print_r($e->getMessage());
}

try {
$result=$ftx->wallet()->getAllBalances();
print_r($result);
}catch (\Exception $e){
print_r($e->getMessage());
}

0 comments on commit f3fcb51

Please sign in to comment.