import { toUnixTimestamp } from '../utils/format' ; import { APIClient } from './APIClient' ; export class LiveClient { public constructor ( private api ) { } public async getAll ( status ? , start = new Date ( 0 ) , end = new Date ( ) ) { const parameters = { start : toUnixTimestamp ( start ) , end : toUnixTimestamp ( end ) , } ; if ( status !== undefined ) { parameters . status = status ; } const data = await this . api . get ( 'live/read' , parameters ) ; return data . live ; } public async start ( projectId , compileId , nodeId , brokerageSettings , priceDataHandler , tiingoToken ? ) { const parameters = { projectId , compileId , nodeId , brokerage : brokerageSettings , dataHandler : priceDataHandler , versionId : '-1' , } ; if ( tiingoToken !== undefined ) { parameters . addOnDataFeed = { TiingoNews : { token : tiingoToken , } , } ; } return this . api . post ( 'live/create' , parameters ) ; } public async stop ( projectId ) { await this . api . post ( 'live/update/stop' , { projectId } ) ; } public async liquidateAndStop ( projectId ) { await this . api . post ( 'live/update/liquidate' , { projectId } ) ; } public async getLogs ( projectId , deploymentId , start = new Date ( 0 ) , end = new Date ( ) ) { const { data } = await this . api . axios . post ( 'live/read/log' , { projectId , algorithmId : deploymentId , start : toUnixTimestamp ( start ) , end : toUnixTimestamp ( end ) , } ) ; return data ; } }