Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement switch margin mode #39 #41

Merged
merged 1 commit into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/bingx-client/services/trade.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
Expand All @@ -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),
);
}
}
44 changes: 44 additions & 0 deletions src/bingx/endpoints/bingx-switch-margin-mode-endpoint.ts
Original file line number Diff line number Diff line change
@@ -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<SwitchMarginModeResponse>
{
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;
}
Loading