Skip to content

Commit

Permalink
chore(): type refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagosiebler committed Jun 11, 2024
1 parent df51c82 commit a5efe89
Show file tree
Hide file tree
Showing 11 changed files with 384 additions and 397 deletions.
102 changes: 50 additions & 52 deletions src/RestClient.ts

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/types/request/futures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* ==========================================================================================================================
*/

import { FuturesOrder, FuturesPriceTriggeredOrder } from '../shared';
import { FuturesOrder, FuturesPriceTriggeredOrder } from '../response/futures';

export interface GetFuturesOrderBookReq {
settle: 'btc' | 'usdt' | 'usd';
Expand Down Expand Up @@ -133,7 +133,7 @@ export interface GetFuturesOrdersByTimeRangeReq {
offset?: number;
}

export interface submitFuturesBatchOrdersReq extends FuturesOrder {
export interface SubmitFuturesBatchOrdersReq extends FuturesOrder {
settle: 'btc' | 'usdt' | 'usd';
}

Expand Down
13 changes: 13 additions & 0 deletions src/types/request/spot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,26 @@ export interface GetSpotOrdersReq {
side?: 'buy' | 'sell';
}

export interface CancelSpotBatchOrdersReq {
currency_pair: string;
id: string;
account?: 'cross_margin';
action_mode?: 'ACK' | 'RESULT' | 'FULL';
}

export interface DeleteSpotOrderReq {
order_id: string;
currency_pair: string;
account?: 'spot' | 'margin' | 'cross_margin' | 'unified';
action_mode?: 'ACK' | 'RESULT' | 'FULL';
}

export interface GetSpotOrderReq {
order_id: string;
currency_pair: string;
account?: 'spot' | 'margin' | 'cross_margin' | 'unified';
}

export interface GetSpotTradingHistoryReq {
currency_pair?: string;
limit?: number;
Expand Down
195 changes: 194 additions & 1 deletion src/types/response/futures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export interface GetFuturesAccountBookResp {
trade_id: string;
}

export interface ToggleFuturesDualModeResp {
export interface UpdateFuturesDualModeResp {
total: string;
unrealised_pnl: string;
position_margin: string;
Expand Down Expand Up @@ -171,6 +171,81 @@ export interface ToggleFuturesDualModeResp {
};
}

export interface FuturesOrder {
id?: number;
user?: number;
create_time?: number;
finish_time?: number;
finish_as?:
| 'filled'
| 'cancelled'
| 'liquidated'
| 'ioc'
| 'auto_deleveraged'
| 'reduce_only'
| 'position_closed'
| 'stp';
status?: 'open' | 'finished';
contract: string;
size: number;
iceberg?: number;
price?: string;
close?: boolean;
is_close?: boolean;
reduce_only?: boolean;
is_reduce_only?: boolean;
is_liq?: boolean;
tif?: 'gtc' | 'ioc' | 'poc' | 'fok';
left?: number;
fill_price?: string;
text?: string;
tkfr?: string;
mkfr?: string;
refu?: number;
auto_size?: 'close_long' | 'close_short';
stp_id?: number;
stp_act?: 'cn' | 'co' | 'cb' | '-';
amend_text?: string;
biz_info?: string;
}

export interface FuturesPosition {
user?: number;
contract?: string;
size?: number;
leverage?: string;
risk_limit?: string;
leverage_max?: string;
maintenance_rate?: string;
value?: string;
margin?: string;
entry_price?: string;
liq_price?: string;
mark_price?: string;
initial_margin?: string;
maintenance_margin?: string;
unrealised_pnl?: string;
realised_pnl?: string;
pnl_pnl?: string;
pnl_fund?: string;
pnl_fee?: string;
history_pnl?: string;
last_close_pnl?: string;
realised_point?: string;
history_point?: string;
adl_ranking?: number;
pending_orders?: number;
close_order?: {
id?: number;
price?: string;
is_liq?: boolean;
} | null;
mode?: 'single' | 'dual_long' | 'dual_short';
cross_leverage_limit?: string;
update_time?: number;
open_time?: number;
}

export interface GetFuturesTradingHistoryResp {
id: number;
create_time: number;
Expand Down Expand Up @@ -232,3 +307,121 @@ export interface DeleteFuturesBatchOrdersResp {
succeeded: boolean;
message: string;
}

export interface FuturesContract {
name?: string;
type?: 'inverse' | 'direct';
quanto_multiplier?: string;
leverage_min?: string;
leverage_max?: string;
maintenance_rate?: string;
mark_type?: 'internal' | 'index';
mark_price?: string;
index_price?: string;
last_price?: string;
maker_fee_rate?: string;
taker_fee_rate?: string;
order_price_round?: string;
mark_price_round?: string;
funding_rate?: string;
funding_interval?: number;
funding_next_apply?: number;
risk_limit_base?: string;
risk_limit_step?: string;
risk_limit_max?: string;
order_size_min?: number;
order_size_max?: number;
order_price_deviate?: string;
ref_discount_rate?: string;
ref_rebate_rate?: string;
orderbook_id?: number;
trade_id?: number;
trade_size?: number;
position_size?: number;
config_change_time?: number;
in_delisting?: boolean;
orders_limit?: number;
enable_bonus?: boolean;
enable_credit?: boolean;
create_time?: number;
funding_cap_ratio?: string;
}

export interface FuturesPriceTriggeredOrder {
initial: {
contract: string;
size?: number;
price?: string;
close?: boolean;
tif?: 'gtc' | 'ioc';
text?: string;
reduce_only?: boolean;
auto_size?: string;
is_reduce_only?: boolean;
is_close?: boolean;
};
trigger: {
strategy_type?: 0 | 1;
price_type?: 0 | 1 | 2;
price?: string;
rule?: 1 | 2;
expiration?: number;
};
id?: number;
user?: number;
create_time?: number;
finish_time?: number;
trade_id?: number;
status?: 'open' | 'finished' | 'inactive' | 'invalid';
finish_as?: 'cancelled' | 'succeeded' | 'failed' | 'expired';
reason?: string;
order_type?:
| 'close-long-order'
| 'close-short-order'
| 'close-long-position'
| 'close-short-position'
| 'plan-close-long-position'
| 'plan-close-short-position';
me_order_id?: number;
}

export interface FuturesDeliveryContract {
name?: string;
underlying?: string;
cycle?: 'WEEKLY' | 'BI-WEEKLY' | 'QUARTERLY' | 'BI-QUARTERLY';
type?: 'inverse' | 'direct';
quanto_multiplier?: string;
leverage_min?: string;
leverage_max?: string;
maintenance_rate?: string;
mark_type?: 'internal' | 'index';
mark_price?: string;
index_price?: string;
last_price?: string;
maker_fee_rate?: string;
taker_fee_rate?: string;
order_price_round?: string;
mark_price_round?: string;
basis_rate?: string;
basis_value?: string;
basis_impact_value?: string;
settle_price?: string;
settle_price_interval?: number;
settle_price_duration?: number;
expire_time?: number;
risk_limit_base?: string;
risk_limit_step?: string;
risk_limit_max?: string;
order_size_min?: number;
order_size_max?: number;
order_price_deviate?: string;
ref_discount_rate?: string;
ref_rebate_rate?: string;
orderbook_id?: number;
trade_id?: number;
trade_size?: number;
position_size?: number;
config_change_time?: number;
in_delisting?: boolean;
orders_limit?: number;
}
9 changes: 5 additions & 4 deletions src/types/response/shared.types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@




export interface APIResponse<TData = {}> {
success: boolean;
data: TData;
timestamp: number;
}
68 changes: 65 additions & 3 deletions src/types/response/spot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
* ==========================================================================================================================
*/

import { Order } from '../shared';

export interface GetSpotCurrenciesResp {
currency: string;
delisted: boolean;
Expand Down Expand Up @@ -158,10 +156,74 @@ export interface SubmitSpotBatchOrdersResp {
finish_as: 'open' | 'filled' | 'cancelled' | 'ioc' | 'stp';
}

export interface SpotOrder {
id?: string;
text?: string;
amend_text?: string;
create_time?: string;
update_time?: string;
create_time_ms?: number;
update_time_ms?: number;
status?: 'open' | 'closed' | 'cancelled';
currency_pair: string;
type?: 'limit' | 'market';
account?: 'spot' | 'margin' | 'cross_margin' | 'unified';
side: 'buy' | 'sell';
amount: string;
price?: string;
time_in_force?: 'gtc' | 'ioc' | 'poc' | 'fok';
iceberg?: string;
auto_borrow?: boolean;
auto_repay?: boolean;
left?: string;
filled_amount?: string;
fill_price?: string;
filled_total?: string;
avg_deal_price?: string;
fee?: string;
fee_currency?: string;
point_fee?: string;
gt_fee?: string;
gt_maker_fee?: string;
gt_taker_fee?: string;
gt_discount?: boolean;
rebated_fee?: string;
rebated_fee_currency?: string;
stp_id?: number;
stp_act?: 'cn' | 'co' | 'cb' | '-';
finish_as?: 'open' | 'filled' | 'cancelled' | 'ioc' | 'stp';
action_mode?: 'ACK' | 'RESULT' | 'FULL';
}

export interface SpotPriceTriggeredOrder {
trigger: {
price: string;
rule: '>=' | '<=';
expiration: number;
};
put: {
type?: 'limit' | 'market';
side: 'buy' | 'sell';
price: string;
amount: string;
account: 'normal' | 'margin' | 'cross_margin';
time_in_force?: 'gtc' | 'ioc';
text?: string;
};
id?: number;
user?: number;
market: string;
ctime?: number;
ftime?: number;
fired_order_id?: number;
status?: 'open' | 'cancelled' | 'finish' | 'failed' | 'expired';
reason?: string;
}

export interface GetSpotOpenOrdersResp {
currency_pair: string;
total: number;
orders: Order[];
orders: SpotOrder[];
}

export interface DeleteSpotBatchOrdersResp {
Expand Down
25 changes: 25 additions & 0 deletions src/types/response/subaccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,28 @@ export interface CreateSubAccountApiKeyResp {
updated_at: number;
last_access: number;
}

export interface SubAccountKey {
user_id?: string;
mode?: number;
name?: string;
perms?: {
name?:
| 'wallet'
| 'spot'
| 'futures'
| 'delivery'
| 'earn'
| 'options'
| 'account'
| 'unified'
| 'loan';
read_only?: boolean;
}[];
ip_whitelist?: string[];
key?: string;
state?: number;
created_at?: number;
updated_at?: number;
last_access?: number;
}
6 changes: 0 additions & 6 deletions src/types/response/wallet.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
export interface APIResponse<TData = {}> {
success: boolean;
data: TData;
timestamp: number;
}

export interface GetCurrencyChainsResp {
chain: string;
name_cn: string;
Expand Down
Loading

0 comments on commit a5efe89

Please sign in to comment.