import { Injectable } from '@nestjs/common' ; import { Map } from 'immutable' ; import { TradeService } from './trade.service' ; import { AccountAssetDTO , AccountBalanceAssetService , AccountBalanceService } from '../account-balance' ; @ Injectable ( ) export class TradeAccountingService < TProduct , TProductFilter > extends AccountBalanceAssetService { constructor ( private readonly tradeService , accountBalanceService ) { super ( ) ; accountBalanceService . registerAssetSource ( this ) ; } public async lockedAssets ( ownerId ) { return Map < string , AccountAssetDTO > ( ) ; } public async availableAssets ( ownerId ) { const trades = await this . tradeService . getAllByUser ( ownerId , false ) ; return this . sumByAsset ( trades , ( trade ) => trade . ask . asset , ( trade ) => { const sign = trade . ask . userId === ownerId ? - 1 : 1 ; return trade . volume . muln ( sign ) ; } ) . filter ( ( value ) => ! value . amount . isZero ( ) ) ; } }