mirror of
https://github.com/discountry/ritmex-bot.git
synced 2026-09-10 16:58:08 +00:00
Enhance CLI command mode for ritmex-bot (#23)
- Introduced a new command mode for `ritmex-bot`, allowing agent-friendly structured trading operations without entering the Ink interactive menu. - Updated `package.json` to include versioning and set the project as public with a new CLI entry point. - Enhanced documentation in both English and Chinese to provide comprehensive usage instructions for the new command mode. - Added a new executable script for `ritmex-bot` to facilitate command execution. - Improved error handling and command parsing for better user experience and clarity in command execution.
This commit is contained in:
@@ -100,6 +100,13 @@ class PythonSignerBridge {
|
||||
pending.reject(new Error(String(error)));
|
||||
return;
|
||||
}
|
||||
if (
|
||||
Object.prototype.hasOwnProperty.call(payload, "txHash") ||
|
||||
Object.prototype.hasOwnProperty.call(payload, "messageToSign")
|
||||
) {
|
||||
pending.resolve(payload);
|
||||
return;
|
||||
}
|
||||
pending.resolve(payload.result ?? null);
|
||||
}
|
||||
|
||||
@@ -181,7 +188,7 @@ export class LighterSigner {
|
||||
await this.ensureReady();
|
||||
const apiKeyIndex = params.apiKeyIndex ?? this.defaultKeyIndex;
|
||||
|
||||
const result = await this.bridge.call("sign_create_order", {
|
||||
const bridgePayload = await this.bridge.call("sign_create_order", {
|
||||
apiKeyIndex,
|
||||
marketIndex: params.marketIndex,
|
||||
clientOrderIndex: params.clientOrderIndex.toString(),
|
||||
@@ -193,13 +200,14 @@ export class LighterSigner {
|
||||
reduceOnly: params.reduceOnly,
|
||||
triggerPrice: params.triggerPrice,
|
||||
orderExpiry: params.orderExpiry.toString(),
|
||||
expiredAt: params.expiredAt?.toString(),
|
||||
nonce: params.nonce.toString(),
|
||||
accountIndex: this.accountIndex.toString(),
|
||||
});
|
||||
|
||||
const txInfo = String(result);
|
||||
const txInfo = this.resolveTxInfo(bridgePayload);
|
||||
let signature: string | undefined;
|
||||
let txHash: string | undefined;
|
||||
let txHash: string | undefined = this.resolveTxHash(bridgePayload);
|
||||
try {
|
||||
const parsed = JSON.parse(txInfo);
|
||||
if (typeof parsed?.Sig === "string") signature = parsed.Sig;
|
||||
@@ -220,7 +228,7 @@ export class LighterSigner {
|
||||
await this.ensureReady();
|
||||
const apiKeyIndex = params.apiKeyIndex ?? this.defaultKeyIndex;
|
||||
|
||||
const result = await this.bridge.call("sign_cancel_order", {
|
||||
const bridgePayload = await this.bridge.call("sign_cancel_order", {
|
||||
apiKeyIndex,
|
||||
marketIndex: params.marketIndex,
|
||||
orderIndex: params.orderIndex.toString(),
|
||||
@@ -228,7 +236,7 @@ export class LighterSigner {
|
||||
accountIndex: this.accountIndex.toString(),
|
||||
});
|
||||
|
||||
const txInfo = String(result);
|
||||
const txInfo = this.resolveTxInfo(bridgePayload);
|
||||
let signature: string | undefined;
|
||||
try {
|
||||
const parsed = JSON.parse(txInfo);
|
||||
@@ -248,7 +256,7 @@ export class LighterSigner {
|
||||
await this.ensureReady();
|
||||
const apiKeyIndex = params.apiKeyIndex ?? this.defaultKeyIndex;
|
||||
|
||||
const result = await this.bridge.call("sign_cancel_all", {
|
||||
const bridgePayload = await this.bridge.call("sign_cancel_all", {
|
||||
apiKeyIndex,
|
||||
timeInForce: params.timeInForce,
|
||||
scheduledTime: params.scheduledTime.toString(),
|
||||
@@ -256,7 +264,7 @@ export class LighterSigner {
|
||||
accountIndex: this.accountIndex.toString(),
|
||||
});
|
||||
|
||||
const txInfo = String(result);
|
||||
const txInfo = this.resolveTxInfo(bridgePayload);
|
||||
let signature: string | undefined;
|
||||
try {
|
||||
const parsed = JSON.parse(txInfo);
|
||||
@@ -282,4 +290,17 @@ export class LighterSigner {
|
||||
});
|
||||
return String(result ?? "");
|
||||
}
|
||||
|
||||
private resolveTxInfo(payload: unknown): string {
|
||||
if (payload && typeof payload === "object" && "result" in payload) {
|
||||
return String((payload as { result?: unknown }).result ?? "");
|
||||
}
|
||||
return String(payload ?? "");
|
||||
}
|
||||
|
||||
private resolveTxHash(payload: unknown): string | undefined {
|
||||
if (!payload || typeof payload !== "object") return undefined;
|
||||
const hash = (payload as { txHash?: unknown }).txHash;
|
||||
return typeof hash === "string" && hash.length > 0 ? hash : undefined;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user