Skip to content

Commit

Permalink
add bitget
Browse files Browse the repository at this point in the history
  • Loading branch information
zhouaini528 committed Dec 21, 2023
1 parent 6943b08 commit 81c058e
Show file tree
Hide file tree
Showing 4 changed files with 270 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Api/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
222 changes: 222 additions & 0 deletions src/Exchanges/Bitget.php
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 removed tests/README.md
Empty file.
43 changes: 43 additions & 0 deletions tests/bitget.php
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;
}
}

0 comments on commit 81c058e

Please sign in to comment.