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

v1.4.13 feat(): added new endpoints, updated request/response types #85

Merged
merged 2 commits into from
Dec 11, 2024
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
693 changes: 351 additions & 342 deletions docs/endpointFunctionList.md

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions examples/apidoc/RestClient/adjustCollateral.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const { RestClient } = require('okx-api');

// This example shows how to call this OKX API endpoint with either node.js, javascript (js) or typescript (ts) with the npm module "okx-api" for OKX exchange
// This OKX API SDK is available on npm via "npm install okx-api"
// ENDPOINT: /api/v5/finance/flexible-loan/adjust-collateral
// METHOD: POST
// PUBLIC: NO

const client = new RestClient({
apiKey: 'apiKeyHere',
apiSecret: 'apiSecretHere',
apiPass: 'apiPassHere',
});

client.adjustCollateral(params)
.then((response) => {
console.log(response);
})
.catch((error) => {
console.error(error);
});
2 changes: 1 addition & 1 deletion examples/apidoc/RestClient/amendLendingOrder.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const { RestClient } = require('okx-api');

// This example shows how to call this OKX API endpoint with either node.js, javascript (js) or typescript (ts) with the npm module "okx-api" for OKX exchange
// This OKX API SDK is available on npm via "npm install okx-api"
// ENDPOINT: /api/v5/finance/fixed-loan/lending-order
// ENDPOINT: /api/v5/finance/fixed-loan/amend-lending-order
// METHOD: POST
// PUBLIC: NO

Expand Down
21 changes: 21 additions & 0 deletions examples/apidoc/RestClient/getAccountSwitchPrecheck.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const { RestClient } = require('okx-api');

// This example shows how to call this OKX API endpoint with either node.js, javascript (js) or typescript (ts) with the npm module "okx-api" for OKX exchange
// This OKX API SDK is available on npm via "npm install okx-api"
// ENDPOINT: /api/v5/account/set-account-switch-precheck
// METHOD: GET
// PUBLIC: NO

const client = new RestClient({
apiKey: 'apiKeyHere',
apiSecret: 'apiSecretHere',
apiPass: 'apiPassHere',
});

client.getAccountSwitchPrecheck(params)
.then((response) => {
console.log(response);
})
.catch((error) => {
console.error(error);
});
21 changes: 21 additions & 0 deletions examples/apidoc/RestClient/getAccruedInterest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const { RestClient } = require('okx-api');

// This example shows how to call this OKX API endpoint with either node.js, javascript (js) or typescript (ts) with the npm module "okx-api" for OKX exchange
// This OKX API SDK is available on npm via "npm install okx-api"
// ENDPOINT: /api/v5/finance/flexible-loan/interest-accrued
// METHOD: GET
// PUBLIC: NO

const client = new RestClient({
apiKey: 'apiKeyHere',
apiSecret: 'apiSecretHere',
apiPass: 'apiPassHere',
});

client.getAccruedInterest(params)
.then((response) => {
console.log(response);
})
.catch((error) => {
console.error(error);
});
21 changes: 21 additions & 0 deletions examples/apidoc/RestClient/getBorrowableCurrencies.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const { RestClient } = require('okx-api');

// This example shows how to call this OKX API endpoint with either node.js, javascript (js) or typescript (ts) with the npm module "okx-api" for OKX exchange
// This OKX API SDK is available on npm via "npm install okx-api"
// ENDPOINT: /api/v5/finance/flexible-loan/borrow-currencies
// METHOD: GET
// PUBLIC: YES

const client = new RestClient({
apiKey: 'apiKeyHere',
apiSecret: 'apiSecretHere',
apiPass: 'apiPassHere',
});

client.getBorrowableCurrencies(params)
.then((response) => {
console.log(response);
})
.catch((error) => {
console.error(error);
});
21 changes: 21 additions & 0 deletions examples/apidoc/RestClient/getCollateralAssets.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const { RestClient } = require('okx-api');

// This example shows how to call this OKX API endpoint with either node.js, javascript (js) or typescript (ts) with the npm module "okx-api" for OKX exchange
// This OKX API SDK is available on npm via "npm install okx-api"
// ENDPOINT: /api/v5/finance/flexible-loan/collateral-assets
// METHOD: GET
// PUBLIC: YES

const client = new RestClient({
apiKey: 'apiKeyHere',
apiSecret: 'apiSecretHere',
apiPass: 'apiPassHere',
});

client.getCollateralAssets(params)
.then((response) => {
console.log(response);
})
.catch((error) => {
console.error(error);
});
21 changes: 21 additions & 0 deletions examples/apidoc/RestClient/getLoanHistory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const { RestClient } = require('okx-api');

// This example shows how to call this OKX API endpoint with either node.js, javascript (js) or typescript (ts) with the npm module "okx-api" for OKX exchange
// This OKX API SDK is available on npm via "npm install okx-api"
// ENDPOINT: /api/v5/finance/flexible-loan/loan-history
// METHOD: GET
// PUBLIC: NO

const client = new RestClient({
apiKey: 'apiKeyHere',
apiSecret: 'apiSecretHere',
apiPass: 'apiPassHere',
});

client.getLoanHistory(params)
.then((response) => {
console.log(response);
})
.catch((error) => {
console.error(error);
});
21 changes: 21 additions & 0 deletions examples/apidoc/RestClient/getLoanInfo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const { RestClient } = require('okx-api');

// This example shows how to call this OKX API endpoint with either node.js, javascript (js) or typescript (ts) with the npm module "okx-api" for OKX exchange
// This OKX API SDK is available on npm via "npm install okx-api"
// ENDPOINT: /api/v5/finance/flexible-loan/loan-info
// METHOD: GET
// PUBLIC: NO

const client = new RestClient({
apiKey: 'apiKeyHere',
apiSecret: 'apiSecretHere',
apiPass: 'apiPassHere',
});

client.getLoanInfo(params)
.then((response) => {
console.log(response);
})
.catch((error) => {
console.error(error);
});
21 changes: 21 additions & 0 deletions examples/apidoc/RestClient/getMaxLoanAmount.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const { RestClient } = require('okx-api');

// This example shows how to call this OKX API endpoint with either node.js, javascript (js) or typescript (ts) with the npm module "okx-api" for OKX exchange
// This OKX API SDK is available on npm via "npm install okx-api"
// ENDPOINT: /api/v5/finance/flexible-loan/max-loan
// METHOD: POST
// PUBLIC: NO

const client = new RestClient({
apiKey: 'apiKeyHere',
apiSecret: 'apiSecretHere',
apiPass: 'apiPassHere',
});

client.getMaxLoanAmount(params)
.then((response) => {
console.log(response);
})
.catch((error) => {
console.error(error);
});
21 changes: 21 additions & 0 deletions examples/apidoc/RestClient/presetAccountLevelSwitch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const { RestClient } = require('okx-api');

// This example shows how to call this OKX API endpoint with either node.js, javascript (js) or typescript (ts) with the npm module "okx-api" for OKX exchange
// This OKX API SDK is available on npm via "npm install okx-api"
// ENDPOINT: /api/v5/account/account-level-switch-preset
// METHOD: POST
// PUBLIC: NO

const client = new RestClient({
apiKey: 'apiKeyHere',
apiSecret: 'apiSecretHere',
apiPass: 'apiPassHere',
});

client.presetAccountLevelSwitch(params)
.then((response) => {
console.log(response);
})
.catch((error) => {
console.error(error);
});
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": "okx-api",
"version": "1.4.12",
"version": "1.4.13",
"description": "Complete & robust Node.js SDK for OKX's REST APIs and WebSockets, with TypeScript & end-to-end tests",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down
90 changes: 88 additions & 2 deletions src/rest-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,17 @@ import {
Announcement,
} from './types';
import { ASSET_BILL_TYPE } from './constants';
import {
AccruedInterestItem,
AccruedInterestRequest,
AdjustCollateralRequest,
CollateralAssetsResponse,
LoanHistoryItem,
LoanHistoryRequest,
LoanInfo,
MaxLoanRequest,
MaxLoanResponse,
} from './types/rest/response/private-flexible-loan';

export class RestClient extends BaseRestClient {
/**
Expand Down Expand Up @@ -498,12 +509,14 @@ export class RestClient extends BaseRestClient {
getMaxLoan(
instId: string,
mgnMode: MarginMode,
mgnCcy?: string
mgnCcy?: string,
ccy?: string
JJ-Cro marked this conversation as resolved.
Show resolved Hide resolved
): Promise<AccountMaxLoan[]> {
return this.getPrivate('/api/v5/account/max-loan', {
instId,
mgnMode,
mgnCcy,
ccy,
});
}

Expand Down Expand Up @@ -814,6 +827,26 @@ export class RestClient extends BaseRestClient {
return this.postPrivate('/api/v5/account/set-auto-loan', params);
}

presetAccountLevelSwitch(params: {
acctLv: '2' | '3' | '4';
lever?: string;
riskOffsetType?: '1' | '2' | '3' | '4';
}): Promise<any[]> {
return this.postPrivate(
'/api/v5/account/account-level-switch-preset',
params
);
}

getAccountSwitchPrecheck(params: {
acctLv: '1' | '2' | '3' | '4';
}): Promise<any[]> {
return this.getPrivate(
'/api/v5/account/set-account-switch-precheck',
params
);
}

setAccountMode(params: {
acctLv: AccountLevel;
}): Promise<AccountModeResult[]> {
Expand Down Expand Up @@ -2869,7 +2902,10 @@ export class RestClient extends BaseRestClient {
}

amendLendingOrder(params: LendingOrder): Promise<any[]> {
return this.postPrivate('/api/v5/finance/fixed-loan/lending-order', params);
return this.postPrivate(
'/api/v5/finance/fixed-loan/amend-lending-order',
params
);
}

getLendingOrders(params: GetLendingOrderListRequest): Promise<any[]> {
Expand All @@ -2886,6 +2922,56 @@ export class RestClient extends BaseRestClient {
);
}

/**
*
* Financial product - Flexible loan endpoints
*
*/

getBorrowableCurrencies(): Promise<
{
borrowCcy: string;
}[]
> {
return this.get('/api/v5/finance/flexible-loan/borrow-currencies');
}

getCollateralAssets(params?: {
ccy?: string;
}): Promise<CollateralAssetsResponse[]> {
JJ-Cro marked this conversation as resolved.
Show resolved Hide resolved
return this.get('/api/v5/finance/flexible-loan/collateral-assets', params);
}

getMaxLoanAmount(params: MaxLoanRequest): Promise<MaxLoanResponse[]> {
return this.postPrivate('/api/v5/finance/flexible-loan/max-loan', params);
}

adjustCollateral(params: AdjustCollateralRequest): Promise<[]> {
return this.postPrivate(
'/api/v5/finance/flexible-loan/adjust-collateral',
params
);
}

getLoanInfo(): Promise<LoanInfo[]> {
return this.getPrivate('/api/v5/finance/flexible-loan/loan-info');
}
getLoanHistory(params?: LoanHistoryRequest): Promise<LoanHistoryItem[]> {
return this.getPrivate(
'/api/v5/finance/flexible-loan/loan-history',
params
);
}

getAccruedInterest(
params?: AccruedInterestRequest
): Promise<AccruedInterestItem[]> {
return this.getPrivate(
'/api/v5/finance/flexible-loan/interest-accrued',
params
);
}

/**
*
* Affiliate endpoints
Expand Down
2 changes: 1 addition & 1 deletion src/types/rest/request/simple-earn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export interface GetLendingOrderListRequest {
export interface LendingOrder {
ccy: string;
amt: string;
rate: string;
rate?: string;
term: '30D';
autoRenewal?: boolean;
}
Expand Down
Loading
Loading