import { Action } from 'redux' ; import { WEBSOCKET_BROKEN , WEBSOCKET_CLOSED , WEBSOCKET_CONNECT , WEBSOCKET_MESSAGE , WEBSOCKET_OPEN , WEBSOCKET_SEND , WEBSOCKET_ERROR , } from '@giantmachines/redux-websocket' ; import { Instrument , Order } from '../../api/bitmex/types' ; type CreateNoPayloadAction < T > = Action < T > ; interface CreateAction < T , P > extends CreateNoPayloadAction < T > { payload : P ; } export const FETCH_ORDERS = 'websocket/FETCH_ORDERS' ; const WEBSOCKET_PREFIX = 'REDUX_WEBSOCKET' ; export const REDUX_WEBSOCKET_BROKEN = `${ WEBSOCKET_PREFIX }::${ WEBSOCKET_BROKEN }` ; export const REDUX_WEBSOCKET_OPEN = `${ WEBSOCKET_PREFIX }::${ WEBSOCKET_OPEN }` ; export const REDUX_WEBSOCKET_CLOSED = `${ WEBSOCKET_PREFIX }::${ WEBSOCKET_CLOSED }` ; export const REDUX_WEBSOCKET_MESSAGE = `${ WEBSOCKET_PREFIX }::${ WEBSOCKET_MESSAGE }` ; export const REDUX_WEBSOCKET_CONNECT = `${ WEBSOCKET_PREFIX }::${ WEBSOCKET_CONNECT }` ; export const REDUX_WEBSOCKET_SEND = `${ WEBSOCKET_PREFIX }::${ WEBSOCKET_SEND }` ; export const REDUX_WEBSOCKET_ERROR = `${ WEBSOCKET_PREFIX }::${ WEBSOCKET_ERROR }` ; export type WebsocketActions = CreateAction < typeof FETCH_ORDERS , any > ; export type ReduxWebsocketMessage = CreateAction < typeof REDUX_WEBSOCKET_MESSAGE , any > ; export interface WebsocketState extends Tables { __keys : Keys ; connected : boolean ; wsLoading : boolean ; message ? : string ; error : string ; } export enum RESPONSE_ACTIONS { PARTIAL = 'partial' , UPDATE = 'update' , INSERT = 'insert' , DELETE = 'delete' } export interface Tables { instrument : Instrument [ ] ; order : Order [ ] ; } export type TableData = Instrument | Order ; type Keys = { [ key in keyof Tables ] ? : ( keyof Tables ) [ ] ; } ; interface WebsocketResponseData { table : keyof Tables ; action : RESPONSE_ACTIONS ; data : Record < string , keyof Tables > [ ] ; keys ? : string [ ] ; foreignKeys ? : iterobject ; types ? : iterobject ; filter ? : { account ? : number ; symbol ? : string ; } ; attributes ? : iterobject ; } interface WebsocketResponseSuccess { subscribe : keyof Tables ; unsubscribe : keyof Tables ; status : unknown ; success : boolean ; } interface WebsocketResponseError { error : string ; } export type WebsocketResponse = WebsocketResponseData & Partial < WebsocketResponseSuccess > & Partial < WebsocketResponseError > ;