@icgio/icg-exchanges-wrapper 1.15.9 → 1.15.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/middleware/orders.js +34 -0
- package/package.json +1 -1
package/middleware/orders.js
CHANGED
|
@@ -196,6 +196,7 @@ module.exports = class Orders {
|
|
|
196
196
|
this.rates_combined_good_with_buy_sell_limits_against_reserve_balance = {}
|
|
197
197
|
this.buy_sell_limits_against_reserve_balance = {}
|
|
198
198
|
this.order_info = {}
|
|
199
|
+
this.fill_records = [] // { side, usdt_amount, timestamp, order_type }
|
|
199
200
|
this.order_info_status = {}
|
|
200
201
|
this.function_enabled = settings.function_enabled || {
|
|
201
202
|
balances_check: true,
|
|
@@ -811,6 +812,21 @@ module.exports = class Orders {
|
|
|
811
812
|
}
|
|
812
813
|
// end: log every f-filled trade for future analysis
|
|
813
814
|
|
|
815
|
+
// Track fill amounts for imbalance detection
|
|
816
|
+
if (dict.status === 'F-FILLED') {
|
|
817
|
+
const order_info_full = _.get(this.order_info, [exchange, pair, type, order_id], {})
|
|
818
|
+
const tracked_types = ['maker_1', 'maker_2', 'maker_3', 'arb']
|
|
819
|
+
if (tracked_types.includes(order_info_full.order_type)) {
|
|
820
|
+
const usdt_amount = order_info_full.f_amount * order_info_full.price
|
|
821
|
+
this.fill_records.push({
|
|
822
|
+
side: type,
|
|
823
|
+
usdt_amount,
|
|
824
|
+
timestamp: Date.now(),
|
|
825
|
+
order_type: order_info_full.order_type,
|
|
826
|
+
})
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
|
|
814
830
|
// Send order update via WebSocket to dashboard backend
|
|
815
831
|
const order_data = _.get(this.order_info, [exchange, pair, type, order_id], {})
|
|
816
832
|
// Only send N-FILLED and later statuses (skip INIT which has temporary order_id)
|
|
@@ -1572,4 +1588,22 @@ module.exports = class Orders {
|
|
|
1572
1588
|
15 * 60 * 1000,
|
|
1573
1589
|
)
|
|
1574
1590
|
}
|
|
1591
|
+
get_fill_imbalance(window_ms = 3600000) {
|
|
1592
|
+
const cutoff = Date.now() - window_ms
|
|
1593
|
+
this.fill_records = this.fill_records.filter((r) => r.timestamp >= cutoff)
|
|
1594
|
+
let sell_sum = 0,
|
|
1595
|
+
buy_sum = 0
|
|
1596
|
+
for (const r of this.fill_records) {
|
|
1597
|
+
if (r.side === 'sell') sell_sum += r.usdt_amount
|
|
1598
|
+
else buy_sum += r.usdt_amount
|
|
1599
|
+
}
|
|
1600
|
+
const total = sell_sum + buy_sum
|
|
1601
|
+
return {
|
|
1602
|
+
sell_sum,
|
|
1603
|
+
buy_sum,
|
|
1604
|
+
total,
|
|
1605
|
+
sell_ratio: total > 0 ? sell_sum / total : 0.5,
|
|
1606
|
+
buy_ratio: total > 0 ? buy_sum / total : 0.5,
|
|
1607
|
+
}
|
|
1608
|
+
}
|
|
1575
1609
|
}
|