From 81c058ef6ac02dc5271943780b331eab081ee179 Mon Sep 17 00:00:00 2001 From: zhouaini528 <465382251@qq.com> Date: Thu, 21 Dec 2023 11:45:16 +0800 Subject: [PATCH] add bitget --- src/Api/Base.php | 5 + src/Exchanges/Bitget.php | 222 +++++++++++++++++++++++++++++++++++++++ tests/README.md | 0 tests/bitget.php | 43 ++++++++ 4 files changed, 270 insertions(+) create mode 100644 src/Exchanges/Bitget.php delete mode 100644 tests/README.md create mode 100644 tests/bitget.php diff --git a/src/Api/Base.php b/src/Api/Base.php index 5b34507..7e0c200 100644 --- a/src/Api/Base.php +++ b/src/Api/Base.php @@ -5,6 +5,7 @@ namespace Lin\Exchange\Api; +use Lin\Exchange\Exchanges\Bitget; use Lin\Exchange\Exchanges\Bybit; use Lin\Exchange\Exchanges\Crex; use Lin\Exchange\Map\Map; @@ -48,6 +49,10 @@ function __construct(string $exchange,string $key,string $secret,string $extra=' $this->exchange=new Bitmex($key,$secret,$host); break; } + case 'bitget':{ + $this->exchange=new Bitget($key,$secret,$extra,$host); + break; + } case 'okex':{ $this->exchange=new Okex($key,$secret,$extra,$host); break; diff --git a/src/Exchanges/Bitget.php b/src/Exchanges/Bitget.php new file mode 100644 index 0000000..d7d59dd --- /dev/null +++ b/src/Exchanges/Bitget.php @@ -0,0 +1,222 @@ + + * */ + +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; + } +} diff --git a/tests/README.md b/tests/README.md deleted file mode 100644 index e69de29..0000000 diff --git a/tests/bitget.php b/tests/bitget.php new file mode 100644 index 0000000..1141247 --- /dev/null +++ b/tests/bitget.php @@ -0,0 +1,43 @@ + + * + * 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; + } +}