@icgio/icg-exchanges-wrapper 1.14.231 → 1.14.233
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/lib/order-status-store.js +44 -19
- package/middleware/orders.js +7 -1
- package/package.json +1 -1
|
@@ -84,6 +84,21 @@ class AllOrdersStore {
|
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
+
/**
|
|
88
|
+
* Remove all rows for a specific exchange/pair (fresh start).
|
|
89
|
+
* @param {string} exchange
|
|
90
|
+
* @param {string} pair
|
|
91
|
+
*/
|
|
92
|
+
async clear_orders(exchange, pair) {
|
|
93
|
+
if (!this.enabled || !this.table_ready) return
|
|
94
|
+
const client = await this.pool.connect()
|
|
95
|
+
try {
|
|
96
|
+
await client.query('DELETE FROM all_orders WHERE exchange = $1 AND pair = $2', [exchange, pair])
|
|
97
|
+
} finally {
|
|
98
|
+
client.release()
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
87
102
|
start_flush_interval() {
|
|
88
103
|
if (this.flush_interval) return
|
|
89
104
|
|
|
@@ -179,28 +194,38 @@ class AllOrdersStore {
|
|
|
179
194
|
updated_at = (NOW() AT TIME ZONE 'UTC')
|
|
180
195
|
`
|
|
181
196
|
|
|
197
|
+
const delete_all_orders_query = `
|
|
198
|
+
DELETE FROM all_orders
|
|
199
|
+
WHERE exchange = $1 AND pair = $2 AND type = $3 AND order_id = $4
|
|
200
|
+
`
|
|
201
|
+
|
|
182
202
|
const client = await this.pool.connect()
|
|
183
203
|
try {
|
|
184
204
|
for (const record of batch) {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
record.
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
205
|
+
if (record.status === 'DELETED') {
|
|
206
|
+
// Physically delete rows for deleted orders to limit DB size
|
|
207
|
+
await client.query(delete_all_orders_query, [record.exchange, record.pair, record.type, record.order_id])
|
|
208
|
+
} else {
|
|
209
|
+
// Upsert active / updated orders
|
|
210
|
+
await client.query(upsert_all_orders_query, [
|
|
211
|
+
record.id,
|
|
212
|
+
record.exchange,
|
|
213
|
+
record.pair,
|
|
214
|
+
record.type,
|
|
215
|
+
record.order_id,
|
|
216
|
+
record.order_type,
|
|
217
|
+
record.status,
|
|
218
|
+
record.price,
|
|
219
|
+
record.amount,
|
|
220
|
+
record.f_amount,
|
|
221
|
+
record.f_percentage,
|
|
222
|
+
record.t_amount,
|
|
223
|
+
record.fees,
|
|
224
|
+
record.open_time,
|
|
225
|
+
record.close_time,
|
|
226
|
+
record.note,
|
|
227
|
+
])
|
|
228
|
+
}
|
|
204
229
|
}
|
|
205
230
|
} catch (err) {
|
|
206
231
|
// Re-queue failed records
|
package/middleware/orders.js
CHANGED
|
@@ -765,7 +765,11 @@ module.exports = class Orders {
|
|
|
765
765
|
this.order_info[exchange][pair][type] = _.omit(this.order_info[exchange][pair][type], [order_id])
|
|
766
766
|
console.log('DELETE %s: %s %s %s %s', note, exchange, pair, type, order_id)
|
|
767
767
|
// Store deletion to PostgreSQL (non-blocking)
|
|
768
|
-
|
|
768
|
+
// Keep final F-FILLED / P-FILLED states in DB (do NOT mark them as DELETED)
|
|
769
|
+
if (order_data.status === 'F-FILLED' || order_data.status === 'P-FILLED') {
|
|
770
|
+
} else {
|
|
771
|
+
this.all_orders_store.store(exchange, pair, type, order_id, { ...order_data, status: 'DELETED' }, note)
|
|
772
|
+
}
|
|
769
773
|
}
|
|
770
774
|
check_balances() {
|
|
771
775
|
let balances_handler = (exchange, res) => {
|
|
@@ -886,6 +890,8 @@ module.exports = class Orders {
|
|
|
886
890
|
}
|
|
887
891
|
// cancel previous orders
|
|
888
892
|
else if (this.cancel_previous_orders && !this.previous_orders_canceled) {
|
|
893
|
+
// remove all previous orders for this exchange/pair from all_orders (fire-and-forget)
|
|
894
|
+
this.all_orders_store.clear_orders(exchange, pair).catch((err) => console.error('clear_all_orders error', exchange, pair, err.message))
|
|
889
895
|
if (this.cancel_previous_orders_with_delay) {
|
|
890
896
|
setTimeout(() => {
|
|
891
897
|
orders.map((order) => {
|