Skip to content

Commit

Permalink
Feat/circuit break info (#50)
Browse files Browse the repository at this point in the history
* feat: circuit break info
  • Loading branch information
koiibb authored Dec 13, 2023
1 parent 3ec92d5 commit facb7d9
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 5 deletions.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ const params: GetCandleStickRequest = {
const res = await publicApi.getCandlestick(params);
```

##### getCircuitBreakInfo
```typescript
const params: GetCircuitBreakInfoRequest = {
pair: 'btc_jpy', // required
};
const res = await publicApi.getCircuitBreakInfo(params);
```

### PrivateAPI
PrivateAPIの初期化にはPrivateApiConfigが必要になります。

Expand Down Expand Up @@ -145,7 +153,7 @@ const params: OrderRequest = {
price: 1000, // optional
side: 'buy', // required
type: 'market', // required
post_only: false, // optional
post_only: false, // optional. Except for circuit_break_info.mode is NONE, this parm is ignored.
};
const res = await privateApi.postOrder(params);
```
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-bitbankcc",
"version": "3.1.0",
"version": "3.2.0",
"description": "node-bitbankcc",
"repository": {
"type": "git",
Expand Down
18 changes: 17 additions & 1 deletion src/lib/public-api.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import * as assert from 'power-assert';
import { PublicApi } from './public-api';
import { GetCandleStickRequest, GetDepthRequest, GetTickerRequest, GetTransactionsRequest } from './requestType';
import {
GetCandleStickRequest,
GetCircuitBreakInfoRequest,
GetDepthRequest,
GetTickerRequest,
GetTransactionsRequest,
} from './requestType';

function getYesterdayYYYYMMDD(): string {
const date = new Date();
Expand Down Expand Up @@ -60,10 +66,20 @@ const getCandlestickTest = async () => {
assert.equal(res.success, 1);
};

const getCircuitBreakInfoTest = async () => {
const publicApi = new PublicApi(config.publicApi);
const params: GetCircuitBreakInfoRequest = {
pair: 'btc_jpy',
};
const res = await publicApi.getCircuitBreakInfo(params);
assert.equal(res.success, 1);
};

describe('PublicAPI Test', () => {
it('GET /{pair}/ticker', getTickerTest);
it('GET /{pair}/depth', getDepthTest);
it('GET /{pair}/transactions', getTransactionsTest);
it('GET /{pair}/transactions/{YYYYMMDD}', getDailyTransactionsTest);
it('GET /{pair}/candlestick/{candle-type}/{YYYYMMDD}', getCandlestickTest);
it('GET /{pair}/circuit_break_info', getCircuitBreakInfoTest);
});
22 changes: 20 additions & 2 deletions src/lib/public-api.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
import { Api } from './api';
import { GetCandleStickRequest, GetDepthRequest, GetTickerRequest, GetTransactionsRequest } from './requestType';
import { CandlestickResponse, DepthResponse, Response, TickerResponse, TransactionsResponse } from './responseType';
import {
GetCandleStickRequest,
GetCircuitBreakInfoRequest,
GetDepthRequest,
GetTickerRequest,
GetTransactionsRequest,
} from './requestType';
import {
CandlestickResponse,
CircuitBreakInfoResponse,
DepthResponse,
Response,
TickerResponse,
TransactionsResponse,
} from './responseType';

export class PublicApi extends Api {
public getTicker(params: GetTickerRequest): Promise<Response<TickerResponse>> {
Expand All @@ -25,4 +38,9 @@ export class PublicApi extends Api {
const path: string = '/'.concat(params.pair, '/candlestick/', params.candleType, '/', params.yyyymmdd);
return this.get(path);
}

public getCircuitBreakInfo(params: GetCircuitBreakInfoRequest): Promise<Response<CircuitBreakInfoResponse>> {
const path: string = '/'.concat(params.pair, '/circuit_break_info');
return this.get(path);
}
}
5 changes: 5 additions & 0 deletions src/lib/requestType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,8 @@ export interface WithdrawalRequest {
otp_token?: string;
sms_token?: string;
}

// Circuit Break Info
export interface GetCircuitBreakInfoRequest {
pair: string;
}
19 changes: 19 additions & 0 deletions src/lib/responseType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ export interface TickerResponse {
export interface DepthResponse {
asks: [string, string][];
bids: [string, string][];
asks_over: string;
bids_under: string;
asks_under: string;
bids_over: string;
timestamp: number;
sequenceId: string;
}

// Transactions
Expand Down Expand Up @@ -190,3 +196,16 @@ export interface WithdrawalResponse {
export interface WithdrawalHistoryResponse {
withdrawals: WithdrawalResponse[];
}

// Circuit Break Info
export interface CircuitBreakInfoResponse {
mode: 'NONE' | 'CIRCUIT_BREAK' | 'FULL_RANGE_CIRCUIT_BREAK' | 'RESUMPTION' | 'LISTING';
upper_trigger_price: string | null;
lower_trigger_price: string | null;
fee_type: 'NORMAL' | 'SELL_MAKER' | 'BUY_MAKER' | 'DYNAMIC';
estimated_itayose_price: string | null;
itayose_upper_price: string | null;
itayose_lower_price: string | null;
reopen_timestamp: number | null;
timestamp: number;
}

0 comments on commit facb7d9

Please sign in to comment.