diff --git a/src/bingx-client/services/trade.service.ts b/src/bingx-client/services/trade.service.ts index a87ee7f..ff8bdac 100644 --- a/src/bingx-client/services/trade.service.ts +++ b/src/bingx-client/services/trade.service.ts @@ -4,6 +4,10 @@ import { AccountInterface } from '@app/bingx/account/account.interface'; import { BingxTradeOrderEndpoint } from '@app/bingx/endpoints/bingx-trade-order-endpoint'; import { BingxCloseAllPositionsEndpoint } from '@app/bingx/endpoints/bingx-close-all-positions-endpoint'; import { BingxCancelAllOrdersEndpoint } from '@app/bingx/endpoints/bingx-cancel-all-orders-endpoint'; +import { + BingxSwitchMarginModeEndpoint, + MarginType, +} from '@app/bingx/endpoints/bingx-switch-margin-mode-endpoint'; export class TradeService { constructor(private readonly requestExecutor: RequestExecutorInterface) {} @@ -28,4 +32,14 @@ export class TradeService { new BingxCancelAllOrdersEndpoint(symbol, account), ); } + + public switchMarginMode( + symbol: string, + marginType: MarginType, + account: AccountInterface, + ) { + return this.requestExecutor.execute( + new BingxSwitchMarginModeEndpoint(symbol, marginType, account), + ); + } } diff --git a/src/bingx/endpoints/bingx-switch-margin-mode-endpoint.ts b/src/bingx/endpoints/bingx-switch-margin-mode-endpoint.ts new file mode 100644 index 0000000..98de4ce --- /dev/null +++ b/src/bingx/endpoints/bingx-switch-margin-mode-endpoint.ts @@ -0,0 +1,44 @@ +import { + AccountInterface, + DefaultSignatureParameters, + Endpoint, + EndpointInterface, + SignatureParametersInterface, +} from '@app/bingx'; + +export interface SwitchMarginModeResponse { + code: number; + msg: string; +} + +export type MarginType = 'ISOLATED' | 'CROSSED'; + +export class BingxSwitchMarginModeEndpoint + extends Endpoint + implements EndpointInterface +{ + public constructor( + private readonly symbol: string, + private readonly marginType: MarginType, + account: AccountInterface, + ) { + super(account); + } + + method(): 'get' | 'post' | 'put' | 'patch' | 'delete' { + return 'post'; + } + + parameters(): SignatureParametersInterface { + return new DefaultSignatureParameters({ + symbol: this.symbol, + marginType: this.marginType, + }); + } + + path(): string { + return '/openApi/swap/v2/trade/marginType'; + } + + readonly t!: SwitchMarginModeResponse; +}