Skip to content
This repository has been archived by the owner on Apr 2, 2024. It is now read-only.

Commit

Permalink
refactor: Prefer interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
bennycode committed Dec 4, 2020
1 parent 5aa9993 commit 04d14c5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
22 changes: 11 additions & 11 deletions src/client/WebSocketClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export enum WebSocketResponseType {
TICKER = 'ticker',
}

export type WebSocketResponse = {type: WebSocketResponseType} & WebSocketMessage;
export type WebSocketResponse = WebSocketMessage & {type: WebSocketResponseType};

// Not exported because it will become "WebSocketResponse" once complete
type WebSocketMessage =
Expand All @@ -130,13 +130,13 @@ type WebSocketMessage =
| WebSocketMatchMessage
| WebSocketErrorMessage;

export type WebSocketErrorMessage = {
export interface WebSocketErrorMessage {
message: string;
reason: string;
type: WebSocketResponseType.ERROR;
};
}

export type WebSocketMatchMessage = {
export interface WebSocketMatchMessage {
maker_order_id: UUID_V4;
price: string;
product_id: string;
Expand All @@ -147,9 +147,9 @@ export type WebSocketMatchMessage = {
time: ISO_8601_MS_UTC;
trade_id: number;
type: WebSocketResponseType.FULL_MATCH;
};
}

export type WebSocketStatusMessage = {
export interface WebSocketStatusMessage {
currencies: {
convertible_to: string[];
details: CurrencyDetail;
Expand All @@ -163,9 +163,9 @@ export type WebSocketStatusMessage = {
}[];
products: (Product & {type: 'spot'})[];
type: WebSocketResponseType.STATUS;
};
}

export type WebSocketTickerMessage = {
export interface WebSocketTickerMessage {
best_ask: string;
best_bid: string;
high_24h: string;
Expand All @@ -181,14 +181,14 @@ export type WebSocketTickerMessage = {
type: WebSocketResponseType.TICKER;
volume_24h: string;
volume_30d: string;
};
}

export type WebSocketLastMatchMessage = Omit<WebSocketMatchMessage, 'type'> & {type: WebSocketResponseType.LAST_MATCH};

export type WebSocketSubscription = {
export interface WebSocketSubscription {
channels: WebSocketChannel[];
type: WebSocketResponseType.SUBSCRIPTIONS;
};
}

export enum WebSocketEvent {
ON_CLOSE = 'WebSocketEvent.ON_CLOSE',
Expand Down
20 changes: 10 additions & 10 deletions src/order/OrderAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,23 +55,23 @@ type BasePlacedOrder = {

export type NewOrder = LimitOrder | AutoCancelLimitOrder | PostOnlyLimitOrder | MarketOrder;

export type AutoCancelLimitOrder = LimitOrder & {
export interface AutoCancelLimitOrder extends LimitOrder {
cancel_after: CancelOrderPeriod;
time_in_force: TimeInForce.GOOD_TILL_TIME;
};
}

export type PostOnlyLimitOrder = LimitOrder & {
export interface PostOnlyLimitOrder extends LimitOrder {
post_only: boolean;
time_in_force: TimeInForce.GOOD_TILL_CANCELED | TimeInForce.GOOD_TILL_TIME;
};
}

export type LimitOrder = BaseOrder & {
export interface LimitOrder extends BaseOrder {
price: string;
size: string;
/** Default is 'GTC'. */
time_in_force?: TimeInForce;
type: OrderType.LIMIT;
};
}

export type MarketOrder = BaseOrder & {type: OrderType.MARKET} & ({size: string} | {funds: string});

Expand All @@ -82,17 +82,17 @@ export enum OrderStatus {
PENDING = 'pending',
}

export type PendingOrder = BasePlacedOrder & {
export interface PendingOrder extends BasePlacedOrder {
status: OrderStatus.PENDING;
stp: SelfTradePrevention;
};
}

export type FilledOrder = BasePlacedOrder & {
export interface FilledOrder extends BasePlacedOrder {
done_at: ISO_8601_MS_UTC;
done_reason: 'filled';
profile_id: string;
status: OrderStatus.DONE;
};
}

export type Order = PendingOrder | FilledOrder;

Expand Down
4 changes: 2 additions & 2 deletions src/payload/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export interface Pagination {
limit?: number;
}

export type PaginatedData<PayloadType> = {
export interface PaginatedData<PayloadType> {
data: PayloadType[];
pagination: {after?: string; before?: string};
};
}

0 comments on commit 04d14c5

Please sign in to comment.