From 9e15c5272ea460ee3f72110f077c8489ecf68da3 Mon Sep 17 00:00:00 2001 From: bludnic Date: Mon, 6 May 2024 23:24:48 +0100 Subject: [PATCH] refactor(order-synchronizer): remove deprecated method --- .../order-synchronizer-polling.watcher.ts | 77 +------------------ 1 file changed, 1 insertion(+), 76 deletions(-) diff --git a/apps/processor/src/processing/order-synchronizer/order-synchronizer-polling.watcher.ts b/apps/processor/src/processing/order-synchronizer/order-synchronizer-polling.watcher.ts index b24a8829..ab485c2d 100644 --- a/apps/processor/src/processing/order-synchronizer/order-synchronizer-polling.watcher.ts +++ b/apps/processor/src/processing/order-synchronizer/order-synchronizer-polling.watcher.ts @@ -1,8 +1,5 @@ -import { NetworkError, OrderNotFound, RequestTimeout } from "ccxt"; -import { subHours } from "date-fns"; -import { exchangeProvider } from "@opentrader/exchanges"; +import { NetworkError, RequestTimeout } from "ccxt"; import { ExchangeAccountProcessor } from "@opentrader/processing"; -import { xprisma } from "@opentrader/db"; import { OrderSynchronizerWatcher } from "./order-synchronizer-watcher.abstract"; /** @@ -52,76 +49,4 @@ export class OrderSynchronizerPollingWatcher extends OrderSynchronizerWatcher { } } } - - private async syncOrders__deprecated() { - // Find orders with `status == Placed` and the last sync was >1 hour ago. - const ONE_HOUR_AGO = subHours(new Date(), 1); - - console.debug("Querying orders which last sync was done >1 hour ago"); - const orders = await xprisma.order.findMany({ - where: { - status: "Placed", - syncedAt: { - lt: ONE_HOUR_AGO, - }, - }, - orderBy: { - syncedAt: "asc", - }, - include: { - smartTrade: { - include: { - exchangeAccount: true, - }, - }, - }, - }); - - for (const order of orders) { - if (!order.exchangeOrderId) { - throw new Error("Order: Missing `exchangeOrderId`"); - } - - const { smartTrade } = order; - const { exchangeAccount } = smartTrade; - - const exchange = exchangeProvider.fromAccount(exchangeAccount); - - console.debug( - `Synchronize order #${order.id}: exchangeOrderId "${order.exchangeOrderId}": price: ${order.price}: status: ${order.status}`, - ); - try { - const exchangeOrder = await exchange.getLimitOrder({ - orderId: order.exchangeOrderId, - symbol: smartTrade.exchangeSymbolId, - }); - - await xprisma.order.updateSyncedAt(order.id); - - if (exchangeOrder.status === "filled") { - const statusChanged = order.status !== "Filled"; - if (statusChanged) { - this.emit("onFilled", [exchangeOrder, order]); - } - } else if (exchangeOrder.status === "canceled") { - const statusChanged = order.status !== "Canceled"; - if (statusChanged) { - this.emit("onCanceled", [exchangeOrder, order]); - } - } - } catch (err) { - if (err instanceof OrderNotFound) { - await xprisma.order.updateStatus("Deleted", order.id); - - console.debug( - `Order not found on the exchange. Change status to "Deleted"`, - ); - } else { - throw err; - } - } - } - - return orders.length; - } }