Skip to content

Commit

Permalink
Merge pull request #41 from singlesly/feat#39-implement-switch-margin…
Browse files Browse the repository at this point in the history
…-mode

feat: implement switch margin mode #39
  • Loading branch information
singlesly authored Oct 12, 2023
2 parents d1da148 + 6cb367e commit a4595f8
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
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;
}

0 comments on commit a4595f8

Please sign in to comment.