Skip to content

Commit

Permalink
fix: improve SubscribeAccountEvents interface
Browse files Browse the repository at this point in the history
  • Loading branch information
hadnet committed May 16, 2021
1 parent 77394e9 commit 4cbb0bd
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 27 deletions.
19 changes: 9 additions & 10 deletions src/foxbit-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ import type {
CancelReplaceOrderRejectEvent,
CancelOrderRejectEvent,
CancelAllOrdersRejectEvent,
SubscribeAccountEvent,
SubscribeAccountEvents,
SubscribeTradesResponse,
} from './message-result';
Expand Down Expand Up @@ -737,46 +736,46 @@ export class FoxBit {
*/
subscribeAccountEvents(AccountId: number, OMSId: number): Observable<SubscribeAccountEvents> {
const endpoint = 'SubscribeAccountEvents';
const isAccountPositionEvent = (obj: SubscribeAccountEvent): obj is AccountPositionEvent => {
const isAccountPositionEvent = (obj: SubscribeAccountEvents): obj is AccountPositionEvent => {
if ('Hold' in obj) return true;
return false;
};
const isSubscribeAccountEventsResponse = (
obj: SubscribeAccountEvent,
obj: SubscribeAccountEvents,
): obj is SubscribeAccountEventsResponse => {
if ('Subscribed' in obj) return true;
return false;
};
const isOrderTradeEvent = (obj: SubscribeAccountEvent): obj is OrderTradeEvent => {
const isOrderTradeEvent = (obj: SubscribeAccountEvents): obj is OrderTradeEvent => {
if ('NotionalValue' in obj) return true;
return false;
};
const isOrderStateEvent = (obj: SubscribeAccountEvent): obj is OrderStateEvent => {
const isOrderStateEvent = (obj: SubscribeAccountEvents): obj is OrderStateEvent => {
if ('ChangeReason' in obj) return true;
return false;
};
const isMarketStateUpdate = (obj: SubscribeAccountEvent): obj is MarketStateUpdate => {
const isMarketStateUpdate = (obj: SubscribeAccountEvents): obj is MarketStateUpdate => {
if ('Action' in obj) return true;
return false;
};
const isPendingDepositUpdate = (obj: SubscribeAccountEvent): obj is PendingDepositUpdate => {
const isPendingDepositUpdate = (obj: SubscribeAccountEvents): obj is PendingDepositUpdate => {
if ('AssetId' in obj) return true;
return false;
};
const isCancelReplaceOrderRejectEvent = (
obj: SubscribeAccountEvent,
obj: SubscribeAccountEvents,
): obj is CancelReplaceOrderRejectEvent => {
if ('ReferencePrice' in obj) return true;
return false;
};
const isCancelOrderRejectEvent = (
obj: SubscribeAccountEvent,
obj: SubscribeAccountEvents,
): obj is CancelOrderRejectEvent => {
if ('OrderRevision' in obj) return true;
return false;
};
const isCancelAllOrdersRejectEvent = (
obj: SubscribeAccountEvent,
obj: SubscribeAccountEvents,
): obj is CancelAllOrdersRejectEvent => {
if ('RejectReason' in obj && 'InstrumentId' in obj) return true;
return false;
Expand Down
78 changes: 61 additions & 17 deletions src/message-result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,12 @@ export interface AccountPositionResult {
}

export interface SubscribeAccountEventsResponse {
/**
* The update event name.
* @type {string}
* @memberof SubscribeAccountEventsResponse
*/
kind: 'SubscribeAccountEventsResponse';
/**
* Cross Product Amount on Hold from open orders
* @type {boolean}
Expand All @@ -605,6 +611,12 @@ export interface SubscribeAccountEventsResponse {
Subscribed: boolean;
}
export interface AccountPositionEvent extends Omit<AccountPositionResult, 'TotalMonthWithdraws'> {
/**
* The update event name.
* @type {string}
* @memberof AccountPositionEvent
*/
kind: 'AccountPositionEvent';
/**
* Cross Product Amount on Hold from open orders
* @type {number}
Expand Down Expand Up @@ -644,6 +656,12 @@ export interface AccountPositionEvent extends Omit<AccountPositionResult, 'Total
}

export interface CancelOrderRejectEvent {
/**
* The update event name.
* @type {string}
* @memberof CancelOrderRejectEvent
*/
kind: 'CancelOrderRejectEvent';
/**
* OMS Id
* @type {number}
Expand Down Expand Up @@ -698,6 +716,12 @@ export interface CancelOrderRejectEvent {
}

export interface CancelReplaceOrderRejectEvent {
/**
* The update event name.
* @type {string}
* @memberof CancelReplaceOrderRejectEvent
*/
kind: 'CancelReplaceOrderRejectEvent';
/**
* ID of the OMS
* @type {number}
Expand Down Expand Up @@ -803,6 +827,12 @@ export interface CancelReplaceOrderRejectEvent {
}

export interface MarketStateUpdate {
/**
* The update event name.
* @type {string}
* @memberof MarketStateUpdate
*/
kind: 'MarketStateUpdate';
/**
* Exchange Id
* @type {number}
Expand Down Expand Up @@ -849,6 +879,12 @@ export interface MarketStateUpdate {
}

export interface NewOrderRejectEvent {
/**
* The update event name.
* @type {string}
* @memberof NewOrderRejectEvent
*/
kind: 'NewOrderRejectEvent';
/**
* OMS Id
* @type {number}
Expand Down Expand Up @@ -882,6 +918,12 @@ export interface NewOrderRejectEvent {
}

export interface CancelAllOrdersRejectEvent {
/**
* The update event name.
* @type {string}
* @memberof CancelAllOrdersRejectEvent
*/
kind: 'CancelAllOrdersRejectEvent';
/**
* OMS ID
* @type {number}
Expand Down Expand Up @@ -915,6 +957,12 @@ export interface CancelAllOrdersRejectEvent {
}

export interface OrderStateEvent {
/**
* The update event name.
* @type {string}
* @memberof OrderStateEvent
*/
kind: 'OrderStateEvent';
/**
* The side of your order.
* @type {Side}
Expand Down Expand Up @@ -1003,6 +1051,12 @@ export interface OrderStateEvent {
}

export interface OrderTradeEvent {
/**
* The update event name.
* @type {string}
* @memberof OrderTradeEvent
*/
kind: 'OrderTradeEvent';
/**
* OMS Id
* @type {number}
Expand Down Expand Up @@ -1116,6 +1170,12 @@ export interface OrderTradeEvent {
}

export interface PendingDepositUpdate {
/**
* The update event name.
* @type {string}
* @memberof PendingDepositUpdate
*/
kind: 'PendingDepositUpdate';
/**
* Your account id number.
* @type {number}
Expand Down Expand Up @@ -1157,7 +1217,7 @@ export interface PendingDepositUpdate {
/**
* Describe all possible events for SubscribeAccountEvents
*/
export type SubscribeAccountEvent =
export type SubscribeAccountEvents =
| SubscribeAccountEventsResponse
| AccountPositionEvent
| OrderTradeEvent
Expand All @@ -1169,22 +1229,6 @@ export type SubscribeAccountEvent =
| NewOrderRejectEvent
| CancelAllOrdersRejectEvent;

/**
* Describe all possible object response events
* for subscribeAccountEvents function
*/
export type SubscribeAccountEvents =
| (SubscribeAccountEventsResponse & {kind: string})
| (AccountPositionEvent & {kind: string})
| (OrderTradeEvent & {kind: string})
| (OrderStateEvent & {kind: string})
| (MarketStateUpdate & {kind: string})
| (PendingDepositUpdate & {kind: string})
| (CancelReplaceOrderRejectEvent & {kind: string})
| (CancelOrderRejectEvent & {kind: string})
| (NewOrderRejectEvent & {kind: string})
| (CancelAllOrdersRejectEvent & {kind: string});

export interface AccountTradesResult {
/**
* The date and time stamp of the trade in Microsoft tick format and UTC time zone
Expand Down

0 comments on commit 4cbb0bd

Please sign in to comment.