-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
539 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { USE_DCA } from "./types/index.js"; | ||
import { makeEffect } from "./utils/index.js"; | ||
|
||
type SafetyOrder = { | ||
quantity: number; | ||
relativePrice: number; | ||
}; | ||
|
||
type UseDcaPayload = { | ||
/** | ||
* Entry order quantity | ||
*/ | ||
quantity: number; | ||
/** | ||
* The Limit entry price of the order. If not provided, a market order will be placed. | ||
*/ | ||
price?: number; | ||
/** | ||
* The Limit exit price of the order (e.g. 0.01 is 10%) | ||
*/ | ||
tpPercent: number; | ||
/** | ||
* Safety orders to be placed when price goes down | ||
*/ | ||
safetyOrders: SafetyOrder[]; | ||
/** | ||
* The symbol to trade, e.g. BTC/USDT. | ||
*/ | ||
symbol?: string; | ||
}; | ||
|
||
export function useDca(params: UseDcaPayload, ref = "0") { | ||
return makeEffect(USE_DCA, params, ref); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { z } from "zod"; | ||
import { cancelSmartTrade, TBotContext, useDca } from "@opentrader/bot-processor"; | ||
import { logger } from "@opentrader/logger"; | ||
|
||
export function* testDca(ctx: TBotContext<any>) { | ||
if (ctx.onStart) { | ||
logger.info(`[Test DCA] Bot started`); | ||
} | ||
if (ctx.onStop) { | ||
logger.info(`[Test DCA] Bot stopped`); | ||
|
||
yield cancelSmartTrade(); | ||
|
||
return; | ||
} | ||
|
||
logger.info("[Test DCA] Executing strategy template"); | ||
yield useDca({ | ||
quantity: 0.001, | ||
tpPercent: 0.03, // +3% | ||
safetyOrders: [ | ||
{ relativePrice: -0.01, quantity: 0.002 }, | ||
{ relativePrice: -0.02, quantity: 0.004 }, | ||
{ relativePrice: -0.03, quantity: 0.006 }, | ||
], | ||
}); | ||
} | ||
|
||
testDca.displayName = "Test DCA"; | ||
testDca.hidden = true; | ||
testDca.schema = z.object({}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.