Skip to content

Commit 9d6cb43

Browse files
add order id to fib and plan commands saved plan
1 parent 5b83e06 commit 9d6cb43

3 files changed

Lines changed: 11 additions & 11 deletions

File tree

src/apps/cb/commands/fib-handlers.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,9 @@ export async function handleFibAction(product: string, options: FibOptions): Pro
230230
console.log(` Stop Price: ${limitTpSlOptions.stopPrice}`);
231231
console.log(` Post Only: ${limitTpSlOptions.postOnly}`);
232232

233-
const placed = await placeLimitTpSlOrder(getProductId(product), limitTpSlOptions);
234-
if (placed) {
235-
const filePath = savePlanFile(plan, limitTpSlOptions.postOnly ?? true);
233+
const orderId = await placeLimitTpSlOrder(getProductId(product), limitTpSlOptions);
234+
if (orderId) {
235+
const filePath = savePlanFile(plan, limitTpSlOptions.postOnly ?? true, orderId);
236236
console.log(`Plan saved: ${filePath}`);
237237
}
238238
}

src/apps/cb/commands/plan-handlers.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,14 @@ type TradePlanBuildSuccess = {
7777

7878
type TradePlanBuildResult = TradePlanBuildFailure | TradePlanBuildSuccess;
7979

80-
export function savePlanFile(plan: TradePlanBuildSuccess, postOnly: boolean): string {
80+
export function savePlanFile(plan: TradePlanBuildSuccess, postOnly: boolean, orderId: string): string {
8181
const configDir = process.env["XDG_CONFIG_HOME"] ?? path.join(os.homedir(), ".config");
8282
const plansDir = path.join(configDir, "helper", "plans");
8383
mkdirSync(plansDir, { recursive: true });
8484
const timestamp = new Date().toISOString().replace(/[:.]/g, "-");
8585
const filename = `${plan.product.toLowerCase()}-${timestamp}.json`;
8686
const filePath = path.join(plansDir, filename);
87-
writeFileSync(filePath, serializeJson({ ...plan, orderOptions: { ...plan.orderOptions, postOnly } } as Record<string, unknown>));
87+
writeFileSync(filePath, serializeJson({ ...plan, orderId, orderOptions: { ...plan.orderOptions, postOnly } } as Record<string, unknown>));
8888
return filePath;
8989
}
9090

@@ -384,9 +384,9 @@ export async function handlePlanAction(product: string, options: PlanOptions): P
384384
console.log(` Stop Price: ${limitTpSlOptions.stopPrice}`);
385385
console.log(` Post Only: ${limitTpSlOptions.postOnly}`);
386386

387-
const placed = await placeLimitTpSlOrder(getProductId(product), limitTpSlOptions);
388-
if (placed) {
389-
const filePath = savePlanFile(plan, limitTpSlOptions.postOnly ?? true);
387+
const orderId = await placeLimitTpSlOrder(getProductId(product), limitTpSlOptions);
388+
if (orderId) {
389+
const filePath = savePlanFile(plan, limitTpSlOptions.postOnly ?? true, orderId);
390390
console.log(`Plan saved: ${filePath}`);
391391
}
392392
}

src/apps/cb/service/order-service.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export async function placeLimitOrder(productId: string, options: LimitOptions):
104104
export async function placeLimitTpSlOrder(
105105
productId: string,
106106
options: LimitTpSlOptions,
107-
): Promise<boolean> {
107+
): Promise<string | false> {
108108
const values = buildLimitTpSlValues(options);
109109

110110
if (
@@ -117,15 +117,15 @@ export async function placeLimitTpSlOrder(
117117
values.orderValue,
118118
)
119119
) {
120-
await createLimitTpSlOrder(
120+
const orderId = await createLimitTpSlOrder(
121121
productId,
122122
options.baseSize,
123123
options.limitPrice,
124124
options.stopPrice,
125125
options.takeProfitPrice,
126126
values.postOnly,
127127
);
128-
return true;
128+
return orderId;
129129
} else {
130130
console.log("Action canceled.");
131131
return false;

0 commit comments

Comments
 (0)