import { IDtoConverter } from "../interfaces" ; import { IHistoricalOrderBookDto , IHistoricalOrderBookItemDto } from "../dtos" ; import { IHistoricalOrderBook , IHistoricalOrderBookItem } from "../models" ; import { DecimalDtoConverter } from "./decimal-dto-converter" ; import { DateDtoConverter } from "./date-dto-converter" ; export class HistoricalOrderBookItemDtoConverter implements IDtoConverter < IHistoricalOrderBookItemDto , IHistoricalOrderBookItem > { private _decimalDtoConverter = new DecimalDtoConverter ( ) ; public convertFromDto ( dto ) { return { price : this . _decimalDtoConverter . convertFromDto ( dto . price ) , size : this . _decimalDtoConverter . convertFromDto ( dto . size ) } ; } public convertToDto ( model ) { return { price : this . _decimalDtoConverter . convertToDto ( model . price ) , size : this . _decimalDtoConverter . convertToDto ( model . size ) } ; } } export class HistoricalOrderBooksDtoConverter implements IDtoConverter < IHistoricalOrderBookDto [ ] , IHistoricalOrderBook [ ] > { private _dateDtoConverter = new DateDtoConverter ( ) ; private _historicalOrderBookItemDtoConverter = new HistoricalOrderBookItemDtoConverter ( ) ; public convertFromDto ( dto ) { return dto . map ( ( historicalDepthDto ) => { const historicalDepth = { time : this . _dateDtoConverter . convertFromDto ( historicalDepthDto . time ) , bids : historicalDepthDto . bids . map ( ( depthItemDto ) => { return this . _historicalOrderBookItemDtoConverter . convertFromDto ( depthItemDto ) ; } ) , asks : historicalDepthDto . asks . map ( ( depthItemDto ) => { return this . _historicalOrderBookItemDtoConverter . convertFromDto ( depthItemDto ) ; } ) } ; return historicalDepth ; } ) ; } public convertToDto ( model ) { return model . map ( ( historicalDepth ) => { const historicalDepthDto = { time : this . _dateDtoConverter . convertToDto ( historicalDepth . time ) , bids : historicalDepth . bids . map ( ( depthItem ) => { return this . _historicalOrderBookItemDtoConverter . convertToDto ( depthItem ) ; } ) , asks : historicalDepth . asks . map ( ( depthItem ) => { return this . _historicalOrderBookItemDtoConverter . convertToDto ( depthItem ) ; } ) } ; return historicalDepthDto ; } ) ; } }