Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support DCA & Ladder orders #18

Open
bludnic opened this issue Apr 30, 2024 · 3 comments
Open

Support DCA & Ladder orders #18

bludnic opened this issue Apr 30, 2024 · 3 comments

Comments

@bludnic
Copy link
Owner

bludnic commented Apr 30, 2024

Currently we have two types of SmartTrades:

type SmartTradeType = "SmartTrade" | "DCA"

Entry and TakeProfit may be Order or Ladder.

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()
@bludnic bludnic added the enhancement New feature or request label Apr 30, 2024
@bludnic
Copy link
Owner Author

bludnic commented Apr 30, 2024

Introduced a new package @opentrader/processing. The processor can be added in that package.

@bludnic bludnic added processing and removed enhancement New feature or request labels Apr 30, 2024
@bludnic bludnic added this to the v0.1.0 milestone May 10, 2024
@bludnic
Copy link
Owner Author

bludnic commented May 16, 2024

Partially done in fa16fb4

Added:

  • OrderExecutor
  • TradeExecutor

@bludnic
Copy link
Owner Author

bludnic commented May 16, 2024

@bludnic bludnic added the idea label Jul 10, 2024
@bludnic bludnic removed this from the v0.1.0 milestone Jul 11, 2024
@bludnic bludnic changed the title Processing different types of SmartTrades Support DCA & Ladder orders Aug 31, 2024
bludnic added a commit that referenced this issue Oct 6, 2024
@bludnic bludnic removed the idea label Dec 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant