Skip to content

Commit

Permalink
optimize structure
Browse files Browse the repository at this point in the history
  • Loading branch information
zhouaini528 committed Sep 16, 2021
1 parent 820a0bc commit 16ceaaf
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 41 deletions.
27 changes: 13 additions & 14 deletions src/Exchanges/Bitmex.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ class AccountBitmex extends BaseBitmex implements AccountInterface
*
* */
function get(array $data){
return $this->platform->position()->get($data);
$this->platform_future=$this->getPlatform('future');
return $this->platform_future->position()->get($data);
}
}

Expand All @@ -95,21 +96,24 @@ class TraderBitmex extends BaseBitmex implements TraderInterface
*
* */
function sell(array $data){
return $this->platform->order()->post($data);
$this->platform_future=$this->getPlatform('future');
return $this->platform_future->order()->post($data);
}

/**
*
* */
function buy(array $data){
return $this->platform->order()->post($data);
$this->platform_future=$this->getPlatform('future');
return $this->platform_future->order()->post($data);
}

/**
*
* */
function cancel(array $data){
return current($this->platform->order()->delete($data));
$this->platform_future=$this->getPlatform('future');
return current($this->platform_future->order()->delete($data));
}

/**
Expand All @@ -123,7 +127,8 @@ function update(array $data){
*
* */
function show(array $data){
return $this->platform->order()->getOne($data);
$this->platform_future=$this->getPlatform('future');
return $this->platform_future->order()->getOne($data);
}

/**
Expand All @@ -146,32 +151,26 @@ class Bitmex

protected $exchange=null;

/*function __construct($key,$secret,$host=''){
$host=empty($host) ? 'https://www.bitmex.com' : $host ;
$this->platform=new BitmexApi($key,$secret,$host);
}*/

function __construct($key,$secret,$host=''){
$this->key=$key;
$this->secret=$secret;
$this->host=$host;
}

function account(){
$this->exchange= new AccountBitmex($this->platform);
$this->exchange= new AccountBitmex($this->key,$this->secret,$this->host);
$this->exchange->setPlatform($this->platform)->setVersion($this->version)->setOptions($this->options);
return $this->exchange;
}

function market(){
$this->exchange= new MarketBitmex($this->platform);
$this->exchange= new MarketBitmex($this->key,$this->secret,$this->host);
$this->exchange->setPlatform($this->platform)->setVersion($this->version)->setOptions($this->options);
return $this->exchange;
}

function trader(){
$this->exchange= new TraderBitmex($this->platform);
$this->exchange= new TraderBitmex($this->key,$this->secret,$this->host);
$this->exchange->setPlatform($this->platform)->setVersion($this->version)->setOptions($this->options);
return $this->exchange;
}
Expand Down
54 changes: 27 additions & 27 deletions tests/bitmex.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/**
* @author lin <[email protected]>
*
*
* Most of them are unfinished and need your help
* https://github.com/zhouaini528/bitmex-php.git
* */
Expand All @@ -22,7 +22,7 @@
$exchanges->setOptions([
//Set the request timeout to 60 seconds by default
'timeout'=>10,

//If you are developing locally and need an agent, you can set this
//'proxy'=>true,
//More flexible Settings
Expand All @@ -46,7 +46,7 @@
'_symbol'=>'exception testing',
'_number'=>'1',
]);

/*
Array
(
Expand All @@ -65,15 +65,15 @@
*/
break;
}

case 2:{
//Default return all
$result=$exchanges->account()->get([
//'_symbol'=>'XBTUSD'
]);
break;
}

//***********Trader Market
case 100:{
$result=$exchanges->trader()->buy([
Expand All @@ -91,7 +91,7 @@
]);
break;
}

case 110:{
//The original parameters
$result=$exchanges->trader()->buy([
Expand All @@ -110,7 +110,7 @@
]);
break;
}

//***********Trader Limit
case 200:{
$result=$exchanges->trader()->buy([
Expand All @@ -130,7 +130,7 @@
]);
break;
}

case 211:{
//The original parameters
$result=$exchanges->trader()->buy([
Expand All @@ -141,7 +141,7 @@
]);
break;
}

case 212:{
//The original parameters
$result=$exchanges->trader()->sell([
Expand All @@ -152,7 +152,7 @@
]);
break;
}

case 300:{
$result=$exchanges->trader()->show([
'_symbol'=>'XBTUSD',
Expand All @@ -161,7 +161,7 @@
]);
break;
}

case 301:{
//The original parameters
$result=$exchanges->trader()->show([
Expand All @@ -170,7 +170,7 @@
]);
break;
}

case 302:{
//The original parameters
$result=$exchanges->trader()->cancel([
Expand All @@ -179,40 +179,40 @@
]);
break;
}

case 303:{
//bargaining transaction
$result=$exchanges->account()->get([
'_symbol'=>'XBTUSD'
]);
break;
}

//***********Complete flow
case 400:{
$result=$exchanges->trader()->buy([
'_symbol'=>'XBTUSD',
'_number'=>'1',
'_price'=>100
'_number'=>'100',
'_price'=>40000
//'_client_id'=>'custom ID',
]);
print_r($result);

$result=$exchanges->trader()->cancel([
'_symbol'=>'XBTUSD',
'_order_id'=>$result['_order_id'],
//'_client_id'=>'custom ID',
]);

break;
}

case 401:{
/* $result=$exchanges->trader()->show([
'_symbol'=>'XBTUSD',
'_order_id'=>'63d0550b-1f3f-9ea5-ec6c-32d416a3ee85',
]); */

/* $_client_id=rand(11111,99999).rand(11111,99999).rand(11111,99999);
$result=$exchanges->trader()->buy([
'_symbol'=>'XBTUSD',
Expand All @@ -221,21 +221,21 @@
'_client_id'=>$_client_id,
]);
print_r($result);
$result=$exchanges->trader()->cancel([
'_symbol'=>'XBTUSD',
//'_order_id'=>$result['_order_id'],
'_client_id'=>$_client_id,
]); */

$result=$exchanges->trader()->show([
'_symbol'=>'XBTUSD',
'_order_id'=>'a0283eec-d6a9-a30f-08a2-1f9f250189bc',
//'_client_id'=>'971668136216134',
]);
break;
}

//
case 500:{
//The original object,
Expand All @@ -248,7 +248,7 @@
]);
break;
}

case 1001:{
//Public API
$exchanges=new Exchanges('bitmex');
Expand All @@ -263,12 +263,12 @@
]);
break;
}


default:{
echo 'nothing';
//exit;
}
}

print_r($result);
print_r($result);

0 comments on commit 16ceaaf

Please sign in to comment.