mirror of
https://github.com/discountry/ritmex-bot.git
synced 2026-09-11 09:18:08 +00:00
Add changeMarginMode method to ExchangeAdapter and Standx classes
- Introduced `changeMarginMode` method in `ExchangeAdapter` interface to allow margin mode adjustments. - Implemented the `changeMarginMode` method in `StandxExchangeAdapter` to interact with the gateway for changing margin modes. - Added corresponding `changeMarginMode` method in `StandxGateway` to handle API requests for margin mode changes. - Enhanced `MakerPointsEngine` to ensure isolated margin mode before order placement, with appropriate logging and defense mode activation if the change fails. - Created tests for margin mode functionality to validate behavior under different scenarios.
This commit is contained in:
@@ -161,6 +161,11 @@ export class StandxExchangeAdapter implements ExchangeAdapter {
|
||||
return this.gateway.queryAccountSnapshot();
|
||||
}
|
||||
|
||||
async changeMarginMode(params: { symbol: string; marginMode: "isolated" | "cross" }): Promise<void> {
|
||||
await this.ensureInitialized("changeMarginMode");
|
||||
await this.gateway.changeMarginMode(params.symbol, params.marginMode);
|
||||
}
|
||||
|
||||
/**
|
||||
* 强制取消所有挂单
|
||||
* 会查询当前挂单然后取消,并验证取消成功
|
||||
|
||||
@@ -1462,6 +1462,30 @@ export class StandxGateway {
|
||||
return await this.refreshAccountSnapshot();
|
||||
}
|
||||
|
||||
async changeMarginMode(symbol: string, marginMode: "isolated" | "cross"): Promise<void> {
|
||||
if (!this.signer.hasKey()) {
|
||||
throw new Error("StandX change_margin_mode requires STANDX_REQUEST_PRIVATE_KEY for signed requests");
|
||||
}
|
||||
const normalized = normalizeSymbol(symbol);
|
||||
const response = await this.requestJson<{ code?: number; message?: string; request_id?: string }>(
|
||||
"/api/change_margin_mode",
|
||||
{
|
||||
method: "POST",
|
||||
body: {
|
||||
symbol: normalized,
|
||||
margin_mode: marginMode,
|
||||
},
|
||||
signed: true,
|
||||
extraHeaders: {
|
||||
"x-session-id": this.sessionId,
|
||||
},
|
||||
}
|
||||
);
|
||||
if (response && typeof response.code === "number" && response.code !== 0) {
|
||||
throw new Error(response.message ?? "StandX change margin mode rejected");
|
||||
}
|
||||
}
|
||||
|
||||
private async refreshOpenOrders(symbol: string): Promise<void> {
|
||||
try {
|
||||
const ordersPayload = await this.requestJson<unknown>("/api/query_open_orders", {
|
||||
|
||||
Reference in New Issue
Block a user