Skip to content

Commit

Permalink
Merge pull request #460 from JJ-Cro/Update031024
Browse files Browse the repository at this point in the history
feat(): updated Margin endpoints
  • Loading branch information
tiagosiebler authored Oct 3, 2024
2 parents af55482 + 0086e8c commit f8a8842
Show file tree
Hide file tree
Showing 4 changed files with 251 additions and 4 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "binance",
"version": "2.13.4",
"version": "2.13.5",
"description": "Node.js & JavaScript SDK for Binance REST APIs & WebSockets, with TypeScript & end-to-end tests.",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down
78 changes: 77 additions & 1 deletion src/main-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,6 @@ import {
TradingDayTickerParams,
RollingWindowTickerParams,
NewOrderListOTOParams,
NewOrderListOTOResponse,
NewOrderListOTOCOParams,
NewOrderListOTOCOResponse,
PreventedMatchesParams,
Expand Down Expand Up @@ -512,6 +511,14 @@ import {
SubAccountDeposit,
SubaccountBrokerSpotAsset,
SubAccountBrokerMarginAsset,
SubmitMarginOTOOrderParams,
MarginOTOOrder,
MarginOTOCOOrder,
SubmitMarginOTOCOOrderParams,
NewOrderListOTOResponse,
CreateSpecialLowLatencyKeyParams,
SpecialLowLatencyKeyResponse,
SpecialLowLatencyKeyInfo,
} from './types/spot';

import {
Expand Down Expand Up @@ -1041,6 +1048,75 @@ export class MainClient extends BaseRestClient {
return this.postPrivate('sapi/v1/margin/manual-liquidation', params);
}

/**
* Post a new OTO order for margin account
*/
submitMarginOTOOrder(
params: SubmitMarginOTOOrderParams,
): Promise<MarginOTOOrder> {
this.validateOrderId(params, 'listClientOrderId');
this.validateOrderId(params, 'workingClientOrderId');
this.validateOrderId(params, 'pendingClientOrderId');
return this.postPrivate('sapi/v1/margin/order/oto', params);
}

/**
* Submit a new OTOCO order for margin account
*/
submitMarginOTOCOOrder(
params: SubmitMarginOTOCOOrderParams,
): Promise<MarginOTOCOOrder> {
this.validateOrderId(params, 'listClientOrderId');
this.validateOrderId(params, 'workingClientOrderId');
this.validateOrderId(params, 'pendingAboveClientOrderId');
this.validateOrderId(params, 'pendingBelowClientOrderId');
return this.postPrivate('sapi/v1/margin/order/otoco', params);
}

/**
* Create a special key for low-latency trading (VIP 4+ only)
*/
createMarginSpecialLowLatencyKey(
params: CreateSpecialLowLatencyKeyParams,
): Promise<SpecialLowLatencyKeyResponse> {
return this.postPrivate('sapi/v1/margin/apiKey', params);
}

deleteMarginSpecialLowLatencyKey(params?: {
apiKey?: string;
apiName?: string;
symbol?: string;
}): Promise<any> {
return this.deletePrivate('sapi/v1/margin/apiKey', params);
}

updateMarginIPForSpecialLowLatencyKey(params: {
apiKey: string;
symbol?: string;
ip: string;
}): Promise<{}> {
return this.putPrivate('sapi/v1/margin/apiKey/ip', params);
}

/**
* Query the list of special keys for low-latency trading
*/
getMarginSpecialLowLatencyKeys(params: {
symbol?: string;
}): Promise<SpecialLowLatencyKeyInfo[]> {
return this.getPrivate('sapi/v1/margin/api-key-list', params);
}

/**
* Query information for a specific special key used in low-latency trading
*/
getMarginSpecialLowLatencyKey(params: {
apiKey: string;
symbol?: string;
}): Promise<SpecialLowLatencyKeyInfo> {
return this.getPrivate('sapi/v1/margin/apiKey', params);
}

/**
*
* MARGIN TRADING Endpoints - Transfer endpoints
Expand Down
171 changes: 171 additions & 0 deletions src/types/spot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5119,3 +5119,174 @@ export interface QueryBrokerFuturesCommissionRebateParams {
recvWindow?: number;
timestamp: number;
}

export interface SubmitMarginOTOOrderParams {
symbol: string;
isIsolated?: 'TRUE' | 'FALSE';
listClientOrderId?: string;
newOrderRespType?: 'ACK' | 'RESULT' | 'FULL';
sideEffectType?: 'NO_SIDE_EFFECT' | 'MARGIN_BUY';
selfTradePreventionMode?:
| 'EXPIRE_TAKER'
| 'EXPIRE_MAKER'
| 'EXPIRE_BOTH'
| 'NONE';
autoRepayAtCancel?: boolean;
workingType: 'LIMIT' | 'LIMIT_MAKER';
workingSide: 'BUY' | 'SELL';
workingClientOrderId?: string;
workingPrice: number;
workingQuantity: number;
workingIcebergQty?: number;
workingTimeInForce?: 'GTC' | 'IOC' | 'FOK';
pendingType: OrderType;
pendingSide: 'BUY' | 'SELL';
pendingClientOrderId?: string;
pendingPrice?: number;
pendingStopPrice?: number;
pendingTrailingDelta?: number;
pendingQuantity: number;
pendingIcebergQty?: number;
pendingTimeInForce?: 'GTC' | 'IOC' | 'FOK';
}

export interface MarginOTOOrder {
orderListId: number;
contingencyType: string;
listStatusType: string;
listOrderStatus: string;
listClientOrderId: string;
transactionTime: number;
symbol: string;
isIsolated: boolean;
orders: {
symbol: string;
orderId: number;
clientOrderId: string;
}[];
orderReports: {
symbol: string;
orderId: number;
orderListId: number;
clientOrderId: string;
transactTime: number;
price: string;
origQty: string;
executedQty: string;
cummulativeQuoteQty: string;
status: string;
timeInForce: string;
type: string;
side: string;
selfTradePreventionMode: string;
}[];
}

export interface SubmitMarginOTOCOOrderParams {
symbol: string;
isIsolated?: 'TRUE' | 'FALSE';
sideEffectType?: 'NO_SIDE_EFFECT' | 'MARGIN_BUY';
autoRepayAtCancel?: boolean;
listClientOrderId?: string;
newOrderRespType?: 'ACK' | 'RESULT' | 'FULL';
selfTradePreventionMode?:
| 'EXPIRE_TAKER'
| 'EXPIRE_MAKER'
| 'EXPIRE_BOTH'
| 'NONE';
workingType: 'LIMIT' | 'LIMIT_MAKER';
workingSide: 'BUY' | 'SELL';
workingClientOrderId?: string;
workingPrice: string;
workingQuantity: string;
workingIcebergQty?: string;
workingTimeInForce?: 'GTC' | 'IOC' | 'FOK';
pendingSide: 'BUY' | 'SELL';
pendingQuantity: string;
pendingAboveType: 'LIMIT_MAKER' | 'STOP_LOSS' | 'STOP_LOSS_LIMIT';
pendingAboveClientOrderId?: string;
pendingAbovePrice?: string;
pendingAboveStopPrice?: string;
pendingAboveTrailingDelta?: string;
pendingAboveIcebergQty?: string;
pendingAboveTimeInForce?: 'GTC' | 'IOC' | 'FOK';
pendingBelowType: 'LIMIT_MAKER' | 'STOP_LOSS' | 'STOP_LOSS_LIMIT';
pendingBelowClientOrderId?: string;
pendingBelowPrice?: string;
pendingBelowStopPrice?: string;
pendingBelowTrailingDelta?: string;
pendingBelowIcebergQty?: string;
pendingBelowTimeInForce?: 'GTC' | 'IOC' | 'FOK';
}

export interface MarginOTOCOOrder {
orderListId: number;
contingencyType: 'OTO';
listStatusType: 'EXEC_STARTED';
listOrderStatus: 'EXECUTING';
listClientOrderId: string;
transactionTime: number;
symbol: string;
isIsolated: boolean;
orders: {
symbol: string;
orderId: number;
clientOrderId: string;
}[];
orderReports: {
symbol: string;
orderId: number;
orderListId: number;
clientOrderId: string;
transactTime: number;
price: string;
origQty: string;
executedQty: string;
cummulativeQuoteQty: string;
status:
| 'NEW'
| 'PARTIALLY_FILLED'
| 'FILLED'
| 'CANCELED'
| 'PENDING_CANCEL'
| 'REJECTED'
| 'EXPIRED'
| 'PENDING_NEW';
timeInForce: 'GTC' | 'IOC' | 'FOK';
type:
| 'LIMIT'
| 'MARKET'
| 'STOP_LOSS'
| 'STOP_LOSS_LIMIT'
| 'TAKE_PROFIT'
| 'TAKE_PROFIT_LIMIT'
| 'LIMIT_MAKER';
side: 'BUY' | 'SELL';
stopPrice?: string;
selfTradePreventionMode:
| 'EXPIRE_TAKER'
| 'EXPIRE_MAKER'
| 'EXPIRE_BOTH'
| 'NONE';
}[];
}

export interface CreateSpecialLowLatencyKeyParams {
apiName: string;
symbol?: string;
ip?: string;
publicKey?: string;
}

export interface SpecialLowLatencyKeyResponse {
apiKey: string;
secretKey: string | null;
type: 'HMAC_SHA256' | 'RSA' | 'Ed25519';
}

export interface SpecialLowLatencyKeyInfo {
apiName: string;
apiKey: string;
ip: string;
type: 'HMAC_SHA256' | 'RSA' | 'Ed25519';
}

0 comments on commit f8a8842

Please sign in to comment.