|
@@ -134,27 +134,36 @@ class WsDataOrder |
|
@@ -134,27 +134,36 @@ class WsDataOrder |
|
134
|
}
|
134
|
}
|
|
135
|
public static function TransferBybitOrder($data, $symbolInfos, callable $toSymbolSt): WsDataOrder|null
|
135
|
public static function TransferBybitOrder($data, $symbolInfos, callable $toSymbolSt): WsDataOrder|null
|
|
136
|
{
|
136
|
{
|
|
137
|
- $order = $data['data'];
|
|
|
|
138
|
- $symbol = call_user_func($toSymbolSt, $order['symbol']);
|
137
|
+ $symbol = call_user_func($toSymbolSt, $data['symbol']);
|
|
139
|
/** @var SymbolInfo $symbolInfo */
|
138
|
/** @var SymbolInfo $symbolInfo */
|
|
140
|
$symbolInfo = $symbolInfos[$symbol] ?? null;
|
139
|
$symbolInfo = $symbolInfos[$symbol] ?? null;
|
|
141
|
if ($symbolInfo == null) {
|
140
|
if ($symbolInfo == null) {
|
|
142
|
return null;
|
141
|
return null;
|
|
143
|
}
|
142
|
}
|
|
144
|
$platform = 'bybit';
|
143
|
$platform = 'bybit';
|
|
145
|
- $posSide = strtoupper($order['side']);
|
|
|
|
146
|
- $side = strtoupper($order['side']);
|
|
|
|
147
|
- $price = (float)$order['price'];
|
|
|
|
148
|
- $avgPx = (float)$order['avg_price'];
|
|
|
|
149
|
- $lot = (float)$order['qty'];
|
144
|
+ $posSide = "BOTH";
|
|
|
|
145
|
+ if ($data['positionIdx'] == 1) {
|
|
|
|
146
|
+ $posSide = "LONG";
|
|
|
|
147
|
+ }
|
|
|
|
148
|
+ if ($data['positionIdx'] == 2) {
|
|
|
|
149
|
+ $posSide = "SHORT";
|
|
|
|
150
|
+ }
|
|
|
|
151
|
+ $side = strtoupper($data['side']);
|
|
|
|
152
|
+ $price = (float)$data['price'];
|
|
|
|
153
|
+ $avgPx = (float)$data['avgPrice'];
|
|
|
|
154
|
+ $lot = (float)$data['qty'];
|
|
150
|
$qty = $lot;
|
155
|
$qty = $lot;
|
|
151
|
- $pnl = (float)$order['realised_pnl'];
|
|
|
|
152
|
- $ts = (int)$order['transact_time'];
|
|
|
|
153
|
- $uts = (int)$order['transact_time'];
|
|
|
|
154
|
- $ordType = strtoupper($order['order_type']);
|
|
|
|
155
|
- $cliOrdId = $order['order_link_id'];
|
|
|
|
156
|
- $ordId = $order['order_id'];
|
|
|
|
157
|
- $status = self::getBnStatus($order['order_status']);
|
156
|
+ $pnl = (float)$data['closedPnl']; //去除手续费资金费的盈亏
|
|
|
|
157
|
+ $ts = (int)$data['updatedTime'];
|
|
|
|
158
|
+ $uts = (int)$data['updatedTime'];
|
|
|
|
159
|
+ $ordType = strtoupper($data['orderType']);
|
|
|
|
160
|
+ $timeInForce = $data['timeInForce'];
|
|
|
|
161
|
+ if ($timeInForce == 'IOC' && $ordType == "LIMIT") {
|
|
|
|
162
|
+ $ordType = "IOC";
|
|
|
|
163
|
+ }
|
|
|
|
164
|
+ $cliOrdId = $data['orderLinkId'];
|
|
|
|
165
|
+ $ordId = $data['orderId'];
|
|
|
|
166
|
+ $status = self::getBybitStatus($data['orderStatus']);
|
|
158
|
return new WsDataOrder($platform, $posSide, $symbol, $side, $price, $avgPx, $qty, $lot, $pnl, $ts, $uts, $ordType, $cliOrdId, $ordId, $status);
|
167
|
return new WsDataOrder($platform, $posSide, $symbol, $side, $price, $avgPx, $qty, $lot, $pnl, $ts, $uts, $ordType, $cliOrdId, $ordId, $status);
|
|
159
|
}
|
168
|
}
|
|
160
|
private static function getBnStatus(string $state)
|
169
|
private static function getBnStatus(string $state)
|
|
@@ -176,4 +185,20 @@ class WsDataOrder |
|
@@ -176,4 +185,20 @@ class WsDataOrder |
|
176
|
}
|
185
|
}
|
|
177
|
return 'UNKNOWN';
|
186
|
return 'UNKNOWN';
|
|
178
|
}
|
187
|
}
|
|
|
|
188
|
+ private static function getBybitStatus(string $state)
|
|
|
|
189
|
+ {
|
|
|
|
190
|
+ if ($state == 'New') {
|
|
|
|
191
|
+ return 'LIVE';
|
|
|
|
192
|
+ }
|
|
|
|
193
|
+ if ($state == 'PartiallyFilled') {
|
|
|
|
194
|
+ return 'PARTIALLY_FILLED';
|
|
|
|
195
|
+ }
|
|
|
|
196
|
+ if ($state == 'Filled') {
|
|
|
|
197
|
+ return 'FILLED';
|
|
|
|
198
|
+ }
|
|
|
|
199
|
+ if ($state == 'Cancelled' || $state == "Rejected") {
|
|
|
|
200
|
+ return 'CANCELED';
|
|
|
|
201
|
+ }
|
|
|
|
202
|
+ return 'UNKNOWN';
|
|
|
|
203
|
+ }
|
|
179
|
} |
204
|
} |