Skip to content

Commit

Permalink
add entry PL ratio in open pair logging #100
Browse files Browse the repository at this point in the history
  • Loading branch information
bitrinjani committed Feb 3, 2018
1 parent ba38bdf commit d8f37f0
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/OpportunitySearcher.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getLogger } from '@bitr/logger';
import { injectable, inject } from 'inversify';
import * as _ from 'lodash';
import { ConfigStore, SpreadAnalysisResult, ActivePairStore, Quote, OrderPair } from './types';
import { ConfigStore, SpreadAnalysisResult, ActivePairStore, Quote, OrderPair, OrderSide } from './types';
import t from './intl';
import { padEnd } from './util';
import symbols from './symbols';
Expand All @@ -10,6 +10,8 @@ import SpreadAnalyzer from './SpreadAnalyzer';
import LimitCheckerFactory from './LimitCheckerFactory';
import { EventEmitter } from 'events';
import { calcProfit } from './pnl';
import OrderImpl from './OrderImpl';
import { LOT_MIN_DECIMAL_PLACE } from './constants';

@injectable()
export default class OppotunitySearcher extends EventEmitter {
Expand Down Expand Up @@ -91,14 +93,19 @@ export default class OppotunitySearcher extends EventEmitter {
}

private formatPairInfo(pair: OrderPair, exitAnalysisResult?: SpreadAnalysisResult) {
const entryProfit = calcProfit(pair, this.configStore.config).profit;
const buyLeg = pair.find(o => o.side === OrderSide.Buy) as OrderImpl;
const sellLeg = pair.find(o => o.side === OrderSide.Sell) as OrderImpl;
const midNotional = _.mean([buyLeg.averageFilledPrice, sellLeg.averageFilledPrice]) * buyLeg.filledSize;
const entryProfitRatio = _.round(entryProfit / midNotional * 100, LOT_MIN_DECIMAL_PLACE);
if (exitAnalysisResult) {
return `[${pair[0].toShortString()}, ${pair[1].toShortString()}, Entry PL: ${_.round(
calcProfit(pair, this.configStore.config).profit
)} JPY, Current exit cost: ${_.round(-exitAnalysisResult.targetProfit)} JPY]`;
entryProfit
)} JPY (${entryProfitRatio}%), Current exit cost: ${_.round(-exitAnalysisResult.targetProfit)} JPY]`;
}
return `[${pair[0].toShortString()}, ${pair[1].toShortString()}, Entry PL: ${_.round(
calcProfit(pair, this.configStore.config).profit
)} JPY]`;
entryProfit
)} JPY (${entryProfitRatio}%)]`;
}

private printSpreadAnalysisResult(result: SpreadAnalysisResult) {
Expand Down

0 comments on commit d8f37f0

Please sign in to comment.