WsDataTrade.php
2.8 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
<?php
namespace trader\struct;
require_once __DIR__ . '/SymbolInfo.php';
use trader\struct\SymbolInfo;
class WsDataTrade
{
public string $platform;
public string $posSide; //大写
public string $symbol; //大写
public string $side; //大写
public float $price; //成交价格
public float $qty; //币种真实数量
public float $lot; //合约张数
public float $pnl; //盈亏
public float $fee; //手续费
public float $quoteVol; //计价货币数量 成交额
public int $ts; //时间戳 ms
public string $tradeId;
public int $lever;
public function __construct($platform, $posSide, $symbol, $side, $price, $qty, $lot, $pnl, $fee, $quoteVol, $ts, $tradeId, $lever)
{
$this->platform = $platform;
$this->posSide = $posSide;
$this->symbol = $symbol;
$this->side = $side;
$this->price = $price;
$this->qty = $qty;
$this->lot = $lot;
$this->pnl = $pnl;
$this->fee = $fee;
$this->quoteVol = $quoteVol;
$this->ts = $ts;
$this->tradeId = $tradeId;
$this->lever = $lever;
}
public function toArray()
{
return [
'platform' => $this->platform,
'posSide' => $this->posSide,
'symbol' => $this->symbol,
'side' => $this->side,
'price' => $this->price,
'qty' => $this->qty,
'lot' => $this->lot,
'pnl' => $this->pnl,
'fee' => $this->fee,
'quoteVol' => $this->quoteVol,
'ts' => $this->ts,
'tradeId' => $this->tradeId,
'lever' => $this->lever,
];
}
public static function TransferOkxOrder(array $data, array $symbolInfos, callable $toSymbolSt): WsDataTrade|null
{
if ($data['fillSz'] != "" && $data['fillSz'] != "0") {
$symbol = call_user_func($toSymbolSt, $data['instId']);
/** @var SymbolInfo $symbolInfo */
$symbolInfo = $symbolInfos[$symbol] ?? null;
if ($symbolInfo == null) {
return null;
}
$platform = 'okx';
$posSide = strtoupper($data['posSide']);
$side = strtoupper($data['side']);
$price = (float)$data['fillPx'];
$lot = (float)$data['fillSz'];
$qty = round($lot * $symbolInfo->ctVal, $symbolInfo->qtyPrec);
$pnl = (float)$data['fillPnl'];
$fee = (float)$data['fillFee'];
$quoteVol = $price * $qty;
$ts = $data['uTime'];
$tradeId = $data['tradeId'];
$lever = (int)$data['lever'];
return new WsDataTrade($platform, $posSide, $symbol, $side, $price, $qty, $lot, $pnl, $fee, $quoteVol, $ts, $tradeId, $lever);
}
return null;
}
}