type EntryType = "Order" | "Ladder"
type TakeProfitType = "Order" | "Ladder"
Therefore there are 4 possible varieties of SmartTrade:
Buy
Sell
Order
Order
Order
Ladder
Ladder
Order
Ladder
Ladder
Need to create a package for processing every type and variety of SmartTrade. The API may be something like this:
SmartTrade
const entity = prisma.smartTrade.findUnique({ where: { id: 1 } })
const smartTrade = new SmartTradeProcessor(entity)
// must cancel all open orders and mark SmartTrade as closed
await smartTrade.cancel()
// place the entry order (entryType == "Order")
// or the first order of ladder (entryType == "Ladder")
await smartTrade.entry()
// OR using hooks
// e.g. using WebSockets and receiving events from the exchange
await smartTrade.handleOrderFilled(orderId) // the processor will decide by itself what to do with that event
await smartTrade.handleOrderCanceled(orderId)
// @internal
// place the next entry buy order if needed (entryType === "Ladder")
// place TP sell order if entry buy order was filled (entryType === "Order")
await smartTrade.publishNext()
DCA
const entity = prisma.smartTrade.findUnique({ where: { id: 2 } })
const dca = new DCATradeProcessor(entity)
await dca.cancel() // same as for SmartTrade
await dca.entry() // same as for SmartTrade
// if TP was filled, then mark DCA as completed
// if SO (Safety Order) was filled, then it must update the TP order limit price
// if SL was filled, the mark DCA as completed
await dca.handleOrderFilled(orderId)
// @internal
await dca.updateTakeProfit()
Currently we have two types of SmartTrades:
Entry and TakeProfit may be Order or Ladder.
Therefore there are 4 possible varieties of SmartTrade:
Need to create a package for processing every type and variety of SmartTrade. The API may be something like this:
SmartTrade
DCA