import * as zerorpc from 'zerorpc' ; import { IndicativePriceApiParams , IndicativePriceApiResult , PriceApiParams , PriceApiResult , NotifyOrderResult , Quoter , } from './types' ; import { DealOrder , ExceptionOrder } from '../../types' ; const promisify = ( client , apiName , req ? ) : Promise < any > => { return new Promise ( ( resolve , reject ) => { client . invoke ( apiName , req , ( err , res ) => { if ( err ) { reject ( err ) ; } else { resolve ( res ) ; } } ) ; } ) ; } ; export class ZeroRPCQuoter implements Quoter { client : zerorpc . Client ; constructor ( endpoint ) { this . client = new zerorpc . Client ( ) ; this . client . connect ( endpoint ) ; } async getPairs ( ) { const res = await promisify ( this . client , 'pairs' ) ; return res . pairs ; } async getIndicativePrice ( data ) { return promisify ( this . client , 'indicativePrice' , data ) ; } async getPrice ( data ) { return promisify ( this . client , 'price' , data ) ; } async dealOrder ( data ) { return promisify ( this . client , 'deal' , data ) ; } async exceptionOrder ( data ) { return promisify ( this . client , 'exception' , data ) ; } }