|
...
|
...
|
@@ -6,6 +6,7 @@ require_once __DIR__ . '/struct/ApiInfo.php'; |
|
|
|
require_once __DIR__ . '/exchange/okx/ExBroker.php';
|
|
|
|
require_once __DIR__ . '/exchange/binance/ExBroker.php';
|
|
|
|
require_once __DIR__ . '/exchange/bybit/ExBroker.php';
|
|
|
|
require_once __DIR__ . '/exchange/bitget/ExBroker.php';
|
|
|
|
require_once __DIR__ . '/struct/Kline.php';
|
|
|
|
require_once __DIR__ . '/struct/Order.php';
|
|
|
|
require_once __DIR__ . '/struct/WsData.php';
|
|
...
|
...
|
@@ -23,6 +24,7 @@ use trader\struct\ApiInfo; |
|
|
|
use trader\exchange\okx\ExBroker as OkxBroker;
|
|
|
|
use trader\exchange\binance\ExBroker as BinanceBroker;
|
|
|
|
use trader\exchange\bybit\ExBroker as BybitBroker;
|
|
|
|
use trader\exchange\bitget\ExBroker as BitgetBroker;
|
|
|
|
use trader\struct\Kline;
|
|
|
|
use trader\struct\Order;
|
|
|
|
use trader\struct\WsData;
|
|
...
|
...
|
@@ -52,7 +54,7 @@ class CmBroker |
|
|
|
* @see PLAT_BITGET
|
|
|
|
*/
|
|
|
|
public $plat;
|
|
|
|
private OkxBroker|BinanceBroker|BybitBroker $exBroker;
|
|
|
|
private OkxBroker|BinanceBroker|BybitBroker|BitgetBroker $exBroker;
|
|
|
|
/** @var SymbolInfo[] $symbolInfos */
|
|
|
|
public $symbolInfos = [];
|
|
|
|
/** @var Pos[] $positions */
|
|
...
|
...
|
@@ -75,14 +77,16 @@ class CmBroker |
|
|
|
if ($plat == self::PLAT_BYBIT) {
|
|
|
|
$exBroker = new BybitBroker($apiInfo);
|
|
|
|
}
|
|
|
|
if ($plat == self::PLAT_BITGET) {
|
|
|
|
$exBroker = new BitgetBroker($apiInfo);
|
|
|
|
}
|
|
|
|
$this->exBroker = $exBroker;
|
|
|
|
if ($wsHost) {
|
|
|
|
if ($wsHost && $wsHost != "") {
|
|
|
|
$this->exBroker->setWsHost($wsHost);
|
|
|
|
}
|
|
|
|
if ($restHost) {
|
|
|
|
if ($restHost && $restHost != "") {
|
|
|
|
$this->exBroker->setRestHost($restHost);
|
|
|
|
}
|
|
|
|
var_dump("初始化。。。。");
|
|
|
|
$this->init();
|
|
|
|
}
|
|
|
|
public function setName($name)
|
|
...
|
...
|
@@ -110,6 +114,9 @@ class CmBroker |
|
|
|
if ($this->plat == self::PLAT_BYBIT) {
|
|
|
|
$this->bybitAccDataHandle($data, $onData);
|
|
|
|
}
|
|
|
|
if ($this->plat == self::PLAT_BITGET) {
|
|
|
|
$this->bitgetAccDataHandle($data, $onData);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
//处理币安相关账户数据监听
|
|
...
|
...
|
@@ -248,6 +255,52 @@ class CmBroker |
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//处理bitget账户相关数据监听
|
|
|
|
private function bitgetAccDataHandle($data, $onData)
|
|
|
|
{
|
|
|
|
// 处理订单和成交数据
|
|
|
|
if (isset($data['arg']) && $data['arg']['channel'] == 'orders') {
|
|
|
|
foreach ($data['data'] as $value) {
|
|
|
|
// 处理成交数据
|
|
|
|
$wsDataTrade = WsDataTrade::TransferBitgetOrder($value, $this->symbolInfos, function ($symbol) {
|
|
|
|
return $this->getSymbolSt($symbol);
|
|
|
|
});
|
|
|
|
if ($wsDataTrade) {
|
|
|
|
$wsData = new WsData($this->plat, 'trade', $wsDataTrade);
|
|
|
|
$onData($wsData);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 处理订单数据
|
|
|
|
$wsDataOrder = WsDataOrder::TransferBitgetOrder($value, $this->symbolInfos, function ($symbol) {
|
|
|
|
return $this->getSymbolSt($symbol);
|
|
|
|
});
|
|
|
|
if ($wsDataOrder) {
|
|
|
|
$wsData = new WsData($this->plat, 'order', null, null, $wsDataOrder);
|
|
|
|
$onData($wsData);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 处理账户和持仓数据
|
|
|
|
if (isset($data['arg']) && $data['arg']['channel'] == 'account') {
|
|
|
|
foreach ($data['data'] as $value) {
|
|
|
|
if (isset($value['positions'])) {
|
|
|
|
foreach ($value['positions'] as $pos) {
|
|
|
|
$wsDataPos = WsDataPos::TransferBitgetPos($pos, $this->symbolInfos, function ($symbol) {
|
|
|
|
return $this->getSymbolSt($symbol);
|
|
|
|
});
|
|
|
|
if ($wsDataPos) {
|
|
|
|
$this->positions[$wsDataPos->symbol . "_" . $wsDataPos->posSide] = $wsDataPos;
|
|
|
|
$wsData = new WsData($this->plat, 'pos', null, $wsDataPos);
|
|
|
|
$onData($wsData);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public function klineListen($symbol, $peroid, $onData)
|
|
|
|
{
|
|
|
|
if ($this->plat == self::PLAT_BINANCE && $peroid == '1s') {
|
|
...
|
...
|
@@ -266,6 +319,9 @@ class CmBroker |
|
|
|
if ($this->plat == self::PLAT_BYBIT) {
|
|
|
|
$kline = Kline::transferBybit($data);
|
|
|
|
}
|
|
|
|
if ($this->plat == self::PLAT_BITGET) {
|
|
|
|
$kline = Kline::transferBitget($data);
|
|
|
|
}
|
|
|
|
$onData($kline);
|
|
|
|
});
|
|
|
|
}
|
|
...
|
...
|
@@ -455,6 +511,19 @@ class CmBroker |
|
|
|
}
|
|
|
|
$this->symbolInfos = $infos;
|
|
|
|
}
|
|
|
|
if ($this->plat == self::PLAT_BITGET) {
|
|
|
|
$res = $this->exBroker->getSymbolInfos();
|
|
|
|
$infos = [];
|
|
|
|
foreach ($res as $value) {
|
|
|
|
if ($value['quoteCoin'] == 'USDT' && $value['symbolStatus'] == 'normal') {
|
|
|
|
$info = SymbolInfo::transferBitget($value, function ($symbol) {
|
|
|
|
return $this->getSymbolSt($symbol);
|
|
|
|
});
|
|
|
|
$infos[$info->symbol] = $info;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$this->symbolInfos = $infos;
|
|
|
|
}
|
|
|
|
if (count($this->symbolInfos) == 0) {
|
|
|
|
$this->initSymbolInfos($count + 1);
|
|
|
|
return;
|
...
|
...
|
|