export const createMapping = (server: IServer, mapping: Partial<IMapping>) => ajax.post( buildApiUrl(server, '/mappings'), mapping, { 'Content-Type': 'application/json' } )
export function getDepth(direction: Direction) { const directionalCompare = (a: OrderType, b: OrderType) => direction === Direction.buy ? b.price > a.price : a.price > b.price return ajax.getJSON<OrderType[]>(`${URL}/depth/${direction}`).pipe( map((orders) => orders.sort((a, b) => directionalCompare(a, b) ? 1 : -1).slice(0, 3)), ) }
(selectedView: IView | null) => selectedView == null ? EMPTY : merge( // initial fetch ajax.getJSON<IViewData>(`api/viewdata/${selectedView.id}`).pipe(catchError(() => EMPTY)), // keep polling observableOf(null) .pipe(delay(3000)) .pipe(mergeMap(() => ajax.getJSON<IViewData>(`api/viewdata/${selectedView.id}`).pipe(catchError(() => EMPTY)))) .pipe(repeat<IViewData | null>()) )
.pipe(switchMap<View | null, IView[]>(() => ajax.getJSON<IView[]>("api/views")))
.pipe(mergeMap(() => ajax.getJSON<IViewData>(`api/viewdata/${selectedView.id}`).pipe(catchError(() => EMPTY))))
export const allViews: Observable<IView[] | null> = observableDefer(() => ajax.getJSON<IView[]>("api/views"));
export const getMappings = (server: IServer) => ajax.getJSON(buildApiUrl(server, '/mappings'))
export const deleteMapping = (server: IServer, mappingId: string) => ajax.delete(buildApiUrl(server, `/mappings/${mappingId}`))
export const updateMapping = (server: IServer, mapping: IMapping) => ajax.put( buildApiUrl(server, `/mappings/${mapping.id}`), mapping, { 'Content-Type': 'application/json' } )
export const getMapping = (server: IServer, mappingId: string) => ajax.getJSON(buildApiUrl(server, `/mappings/${mappingId}`))