SymbolInfo.php
2.6 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
<?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 function __construct($symbolOri, $symbol, $ctVal, $pricePrec, $qtyPrec, $lotPrec, $minLot, $minQty)
{
$this->symbolOri = $symbolOri;
$this->symbol = $symbol;
$this->ctVal = $ctVal;
$this->pricePrec = $pricePrec;
$this->qtyPrec = $qtyPrec;
$this->lotPrec = $lotPrec;
$this->minLot = $minLot;
$this->minQty = $minQty;
}
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,
];
}
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);
}
}
$info = new SymbolInfo($symbolOri, $symbolSt, $ctVal, $pricePrec, $qtyPrec, $lotPrec, $minLot, $minQty);
return $info;
}
}