import OrderImpl from './OrderImpl' ; import * as _ from 'lodash' ; import { findBrokerConfig } from './configUtil' ; import { OrderSide , ConfigRoot } from './types' ; export function calcCommission ( price , volume , commissionPercent ) { return commissionPercent !== undefined ? price * volume * ( commissionPercent / 100 ) : 0 ; } export function calcProfit ( orders , config ) { const commission = _ ( orders ) . sumBy ( o => { const brokerConfig = findBrokerConfig ( config , o . broker ) ; return calcCommission ( o . averageFilledPrice , o . filledSize , brokerConfig . commissionPercent ) ; } ) ; const profit = _ ( orders ) . sumBy ( o => ( o . side === OrderSide . Sell ? 1 : - 1 ) * o . filledNotional ) - commission ; return { profit , commission } ; }