-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6943b08
commit 81c058e
Showing
4 changed files
with
270 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,222 @@ | ||
<?php | ||
/** | ||
* @author lin <[email protected]> | ||
* */ | ||
|
||
namespace Lin\Exchange\Exchanges; | ||
use Lin\Bitget\BitgetContractV2; | ||
use Lin\Bitget\BitgetSpotV2; | ||
use Lin\Exchange\Interfaces\AccountInterface; | ||
use Lin\Exchange\Interfaces\MarketInterface; | ||
use Lin\Exchange\Interfaces\TraderInterface; | ||
|
||
|
||
class BaseBitget | ||
{ | ||
protected $platform_future=null; | ||
protected $platform_spot=null; | ||
protected $platform_swap=null; | ||
|
||
protected $platform_account=null; | ||
protected $platform_margin=null; | ||
protected $platform_option=null; | ||
|
||
protected $platform=''; | ||
protected $version=''; | ||
protected $options=''; | ||
|
||
protected $key; | ||
protected $secret; | ||
protected $passphrase; | ||
protected $host=''; | ||
|
||
function __construct($key,$secret,$passphrase,$host=''){ | ||
$this->key=$key; | ||
$this->secret=$secret; | ||
$this->passphrase=$passphrase; | ||
$this->host=$host; | ||
} | ||
|
||
protected function checkType($symbol){ | ||
return ''; | ||
} | ||
|
||
/** | ||
Set exchange transaction category, default "spot" transaction. Other options "spot" "margin" "future" "swap" | ||
*/ | ||
public function setPlatform(string $platform=''){ | ||
$this->platform=$platform; | ||
return $this; | ||
} | ||
|
||
/** | ||
Set exchange API interface version. for example "v1" "v3" "v5" | ||
*/ | ||
public function setVersion(string $version=''){ | ||
$this->version=$version; | ||
return $this; | ||
} | ||
|
||
/** | ||
* Support for more request Settings | ||
* */ | ||
function setOptions(array $options=[]){ | ||
$this->options=$options; | ||
return $this; | ||
} | ||
|
||
/*** | ||
*Initialize exchange | ||
*/ | ||
function getPlatform(string $type=''){ | ||
switch (strtolower($type)){ | ||
case 'contract': | ||
case 'future':{ | ||
if($this->platform_future == null) $this->platform_future=new BitgetContractV2($this->key,$this->secret,$this->passphrase,$this->host); | ||
$this->platform_future->setOptions($this->options); | ||
return $this->platform_future; | ||
} | ||
case 'spot': | ||
default:{ | ||
if($this->platform_spot == null) $this->platform_spot=new BitgetSpotV2($this->key,$this->secret,$this->passphrase,$this->host); | ||
$this->platform_spot->setOptions($this->options); | ||
return $this->platform_spot; | ||
} | ||
} | ||
return null; | ||
} | ||
} | ||
|
||
class AccountBitget extends BaseBitget implements AccountInterface | ||
{ | ||
/** | ||
* | ||
* */ | ||
function get(array $data){ | ||
return []; | ||
} | ||
} | ||
|
||
class MarketBitget extends BaseBitget implements MarketInterface | ||
{ | ||
/** | ||
* | ||
* */ | ||
function depth(array $data){ | ||
return []; | ||
} | ||
} | ||
|
||
class TraderBitget extends BaseBitget implements TraderInterface | ||
{ | ||
/** | ||
* | ||
* */ | ||
function sell(array $data){ | ||
return []; | ||
} | ||
|
||
/** | ||
* | ||
* */ | ||
function buy(array $data){ | ||
return []; | ||
} | ||
|
||
/** | ||
* | ||
* */ | ||
function cancel(array $data){ | ||
return []; | ||
} | ||
|
||
/** | ||
* | ||
* */ | ||
function update(array $data){ | ||
return []; | ||
} | ||
|
||
/** | ||
* | ||
* */ | ||
function show(array $data){ | ||
return []; | ||
} | ||
|
||
/** | ||
* | ||
* */ | ||
function showAll(array $data){ | ||
return []; | ||
} | ||
} | ||
|
||
class Bitget | ||
{ | ||
protected $platform=''; | ||
protected $version=''; | ||
protected $options=[]; | ||
|
||
protected $key; | ||
protected $secret; | ||
protected $passphrase; | ||
protected $host=''; | ||
|
||
protected $exchange=null; | ||
|
||
function __construct($key,$secret,$passphrase,$host=''){ | ||
$this->key=$key; | ||
$this->secret=$secret; | ||
$this->passphrase=$passphrase; | ||
$this->host= empty($host) ? 'https://api.bitget.com' : $host ; | ||
} | ||
|
||
function account(){ | ||
$this->exchange= new AccountBitget($this->key,$this->secret,$this->passphrase,$this->host); | ||
$this->exchange->setPlatform($this->platform)->setVersion($this->version)->setOptions($this->options); | ||
return $this->exchange; | ||
} | ||
|
||
function market(){ | ||
$this->exchange= new MarketBitget($this->key,$this->secret,$this->passphrase,$this->host); | ||
$this->exchange->setPlatform($this->platform)->setVersion($this->version)->setOptions($this->options); | ||
return $this->exchange; | ||
} | ||
|
||
function trader(){ | ||
$this->exchange= new TraderBitget($this->key,$this->secret,$this->passphrase,$this->host); | ||
$this->exchange->setPlatform($this->platform)->setVersion($this->version)->setOptions($this->options); | ||
return $this->exchange; | ||
} | ||
|
||
function getPlatform(string $type=''){ | ||
if($this->exchange==null) $this->exchange=$this->trader(); | ||
return $this->exchange->getPlatform($type); | ||
} | ||
|
||
/** | ||
Set exchange transaction category, default "spot" transaction. Other options "spot" "margin" "future" "swap" | ||
*/ | ||
public function setPlatform(string $platform=''){ | ||
$this->platform=$platform ?? 'spot'; | ||
return $this; | ||
} | ||
|
||
/** | ||
Set exchange API interface version. for example "v1" "v3" "v5" | ||
*/ | ||
public function setVersion(string $version=''){ | ||
$this->version=$version; | ||
return $this; | ||
} | ||
|
||
|
||
/** | ||
* Support for more request Settings | ||
* */ | ||
function setOptions(array $options=[]){ | ||
$this->options=$options; | ||
return $this; | ||
} | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
/** | ||
* @author lin <[email protected]> | ||
* | ||
* Most of them are unfinished and need your help | ||
* https://github.com/zhouaini528/zb-php.git | ||
* */ | ||
|
||
use Lin\Exchange\Exchanges; | ||
|
||
require __DIR__ .'../../vendor/autoload.php'; | ||
|
||
include 'key_secret.php'; | ||
$key=$keysecret['bitget']['key']; | ||
$secret=$keysecret['bitget']['secret']; | ||
$passphrase=$keysecret['bitget']['passphrase']; | ||
|
||
$exchanges=new Exchanges('bitget',$key,$secret,$passphrase); | ||
|
||
//Support for more request Settings | ||
$exchanges->setOptions([ | ||
//Set the request timeout to 60 seconds by default | ||
'timeout'=>10, | ||
|
||
]); | ||
|
||
$action=intval($_GET['action'] ?? 0);//http pattern | ||
if(empty($action)) $action=intval($argv[1]);//cli pattern | ||
|
||
switch ($action){ | ||
case 2001:{ | ||
$result=$exchanges->getPlatform('spot')->account()->getAssets(); | ||
print_r($result); | ||
break; | ||
} | ||
|
||
|
||
default:{ | ||
echo 'nothing'; | ||
//exit; | ||
} | ||
} |