SymbolInfo.php
4.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?php
namespace trader\struct;
require_once __DIR__ . '/../../jytools/func.php';
use function jytools\getPrecision;
class SymbolInfo
{
public string $symbolOri; // 原始交易对
public string $symbol; // 标准交易对
public string $ctVal; // 合约面值
public string $pricePrec;
public string $qtyPrec;
public string $lotPrec;
public string $minLot; // 最小下单张数
public string $minQty; // 最小下单数量
public int $mul; // 合约乘数//放大倍数,比如币安 1000CATUSDT,乘数为1000
public function __construct($symbolOri, $symbol, $ctVal, $pricePrec, $qtyPrec, $lotPrec, $minLot, $minQty, $mul = 1)
{
$this->symbolOri = $symbolOri;
$this->symbol = $symbol;
$this->ctVal = $ctVal;
$this->pricePrec = $pricePrec;
$this->qtyPrec = $qtyPrec;
$this->lotPrec = $lotPrec;
$this->minLot = $minLot;
$this->minQty = $minQty;
$this->mul = $mul;
}
public function toArray()
{
return [
'symbolOri' => $this->symbolOri,
'symbol' => $this->symbol,
'ctVal' => $this->ctVal,
'pricePrec' => $this->pricePrec,
'qtyPrec' => $this->qtyPrec,
'lotPrec' => $this->lotPrec,
'minLot' => $this->minLot,
'minQty' => $this->minQty,
'mul' => $this->mul,
];
}
public static function transferOkx($data, callable $getSymbolSt): SymbolInfo
{
$symbolSt = $getSymbolSt($data["instId"]); //转换为标准交易对
$pricePrec = getPrecision($data['tickSz']);
$ctVal = $data['ctVal'];
$minLot = $data['minSz'];
$minQty = $minLot * $ctVal;
$qtyPrec = getPrecision($minQty);
$lotPrec = getPrecision($minLot);
$info = new SymbolInfo($data["instId"], $symbolSt, $ctVal, $pricePrec, $qtyPrec, $lotPrec, $minLot, $minQty);
return $info;
}
public static function transferBinance($data, callable $getSymbolSt): SymbolInfo
{
$symbolOri = $data['symbol'];
$symbolSt = $getSymbolSt($symbolOri); //转换为标准交易对
$ctVal = 1;
$pricePrec = 0;
$qtyPrec = 0;
$lotPrec = 0;
$minLot = 0;
foreach ($data['filters'] as $v) {
if ($v['filterType'] == 'PRICE_FILTER') {
$pricePrec = getPrecision($v['tickSize']);
}
if ($v['filterType'] == 'LOT_SIZE') {
$minLot = $v['minQty'];
$minQty = $minLot * $ctVal;
$qtyPrec = getPrecision($minLot);
$lotPrec = getPrecision($minLot);
}
}
$mul = self::extractNumber($symbolOri);
$info = new SymbolInfo($symbolOri, $symbolSt, $ctVal, $pricePrec, $qtyPrec, $lotPrec, $minLot, $minQty, $mul);
return $info;
}
public static function transferBybit($data, callable $getSymbolSt): SymbolInfo
{
$symbolOri = $data['symbol'];
$symbolSt = $getSymbolSt($symbolOri); //转换为标准交易对
$ctVal = 1;
$pricePrec = getPrecision($data['priceFilter']['tickSize']);
$qtyPrec = getPrecision($data['lotSizeFilter']['qtyStep']);
$lotPrec = $qtyPrec;
$minQty = $data['lotSizeFilter']['minOrderQty'];
$minLot = $minQty * $ctVal;
$mul = self::extractNumber($symbolOri);
$info = new SymbolInfo($symbolOri, $symbolSt, $ctVal, $pricePrec, $qtyPrec, $lotPrec, $minLot, $minQty, $mul);
return $info;
}
public static function transferBitget($data, callable $getSymbolSt): SymbolInfo
{
$symbolOri = $data['symbol'];
$symbolSt = $getSymbolSt($symbolOri); //转换为标准交易对
$ctVal = 1; // Bitget合约面值为1
$pricePrec = (int)$data['pricePlace'];
$qtyPrec = (int)$data['volumePlace'];
$lotPrec = $qtyPrec;
$minQty = $data['minTradeNum'];
$minLot = $minQty * $ctVal;
$mul = self::extractNumber($symbolOri);
return new SymbolInfo(
$symbolOri,
$symbolSt,
$ctVal,
$pricePrec,
$qtyPrec,
$lotPrec,
$minLot,
$minQty,
$mul
);
}
public static function extractNumber($str)
{
// 示例
// echo extractNumber("1000CATUSDT") . PHP_EOL; // 输出:1000
// echo extractNumber("1000PEPEUSDT") . PHP_EOL; // 输出:1000
// echo extractNumber("1000000MOGUSDT") . PHP_EOL; // 输出:1000000
if (preg_match('/^\d+/', $str, $matches)) {
return (int)$matches[0]; // 返回整数
}
return 1;
}
}