Skip to content
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
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@ const res = await privateApi.getAssets();
assert.equal(res.success, 1);
```

##### getMarginPositions
```typescript
const res = await privateApi.getMarginPositions();
assert.equal(res.success, 1);
```

##### getOrder
```typescript
const params: GetOrderRequest = {
Expand All @@ -167,6 +173,7 @@ const params: OrderRequest = {
side: 'buy', // required
type: 'market', // required
post_only: false, // optional. Except for circuit_break_info.mode is NONE, this parm is ignored.
position_side: 'long', // optional
};
const res = await privateApi.postOrder(params);
```
Expand Down
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.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-bitbankcc",
"version": "4.0.0",
"version": "4.1.0",
"description": "node-bitbankcc",
"repository": {
"type": "git",
Expand All @@ -21,7 +21,9 @@
"tslint": "tslint --project ./tsconfig.json",
"test": "NODE_ENV=test mocha src/**/*.test.ts --require ts-node/register --timeout 10000 --require intelli-espower-loader",
"test:prod": "NODE_ENV=production mocha src/**/*.test.ts --require ts-node/register --timeout 10000 --require intelli-espower-loader",
"prepare": "npm run build"
"prepare": "npm run build",
"prepublish:sandbox": "rm -fr node_modules && npm ci && npm run build && jq \".version += \\\"-$(git rev-parse HEAD)\\\" | .name |= \\\"@bitbank-sandbox/\\\" + .\" package.json > dist/package.json && cp -rf .npmignore dist",
"publish:sandbox": "cd dist && npm publish --registry https://gitlab.p0fuy9f4prap28og.bitbank.cc/api/v4/projects/578/packages/npm/"
},
"ciNode": "8",
"devDependencies": {
Expand Down
7 changes: 7 additions & 0 deletions src/lib/private-api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ const getAssetsTest = async () => {
assert.equal(res.success, 1);
};

const getMarginPositionsTest = async () => {
const privateApi = new PrivateApi(config.privateApi);
const res = await privateApi.getMarginPositions();
assert.equal(res.success, 1);
};

const getOrderTest = async () => {
const privateApi = new PrivateApi(config.privateApi);
const params: GetOrderRequest = {
Expand Down Expand Up @@ -245,6 +251,7 @@ describe('PrivateAPI Test', () => {
it('switch auth method at header', authMethodTest);
it('nonce should increment', nonceIncrementTest);
it('GET /user/assets', getAssetsTest);
it('GET /user/margin/positions', getMarginPositionsTest);
it('GET /user/spot/order', getOrderTest);
it('GET /user/spot/active_orders', getActiveOrdersTest);
it('POST /user/spot/orders_info', getOrdersInfoTest);
Expand Down
6 changes: 6 additions & 0 deletions src/lib/private-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
CancelOrderResponse,
CancelOrdersResponse,
DepositHistoryResponse,
MarginPositionsResponse,
OrderResponse,
OrdersResponse,
Response,
Expand Down Expand Up @@ -64,6 +65,11 @@ export class PrivateApi extends Api {
return this.get(path, {});
}

public getMarginPositions(): Promise<Response<MarginPositionsResponse>> {
const path = '/user/margin/positions';
return this.get(path, {});
}

public getOrder(params: GetOrderRequest): Promise<Response<OrderResponse | CancelOrderResponse>> {
const path = '/user/spot/order';
return this.get(path, params);
Expand Down
1 change: 1 addition & 0 deletions src/lib/requestType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export interface OrderRequest {
side: string;
type: string;
post_only?: boolean;
position_side?: string;
trigger_price?: number | string;
}

Expand Down
38 changes: 38 additions & 0 deletions src/lib/responseType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export interface DepthResponse {
bids_under: string;
asks_under: string;
bids_over: string;
ask_market: string;
bid_market: string;
timestamp: number;
sequenceId: string;
}
Expand Down Expand Up @@ -62,7 +64,9 @@ export interface AssetResponse {
amount_precision: number;
onhand_amount: string;
locked_amount: string;
withdrawing_amount: string;
free_amount: string;
collateral_ratio: string;
stop_deposit: boolean;
stop_withdrawal: boolean;
withdrawal_fee:
Expand All @@ -86,17 +90,47 @@ export interface AssetResponse {
}[];
}

// MarginPositions
export interface MarginPositionsResponse {
notice: {
what: string | null;
occurred_at: number | null;
amount: string | null;
dueDateAt: number | null;
};
payables: {
amount: string;
};
positions: MarginPositionResponse[];
losscut_threshold: {
company: string;
indivisual: string;
};
}

export interface MarginPositionResponse {
pair: string;
position_side: string;
open_amount: string;
product: string;
average_price: string;
unrealized_fee_amount: string;
unrealized_interest_amount: string;
}

// Order
export interface OrderResponse {
order_id: number;
pair: string;
position_side?: string;
side: string;
type: string;
start_amount: string;
remaining_amount: string;
executed_amount: string;
price?: string;
post_only?: boolean;
user_cancelable: boolean;
average_price: string;
ordered_at: number;
expire_at: number;
Expand Down Expand Up @@ -136,8 +170,12 @@ export interface TradeResponse {
amount: string;
price: string;
maker_taker: string;
position_side?: string;
fee_amount_base: string;
fee_amount_quote: string;
fee_occurred_amount_quote?: string;
interest?: string;
profit_loss?: string;
executed_at: number;
}

Expand Down
Loading