Skip to content

Commit

Permalink
show current exit cost #80
Browse files Browse the repository at this point in the history
  • Loading branch information
bitrinjani committed Jan 28, 2018
1 parent ee7fa9e commit 80cb354
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 15 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "r2",
"version": "2.3.0",
"version": "2.3.1",
"main": "index.js",
"license": "MIT",
"scripts": {
Expand Down
20 changes: 6 additions & 14 deletions src/OpportunitySearcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,14 @@ export default class OppotunitySearcher extends EventEmitter {
return { closable: false };
}
const activePairsMap = await this.activePairStore.getAll();
this.printActivePairs(activePairsMap.map(kv => kv.value));
if (activePairsMap.length > 0) {
this.log.info(t`OpenPairs`);
}
for (const { key, value: pair } of activePairsMap) {
try {
this.log.debug(`Analyzing pair: ${this.formatPair(pair)}...`);
const exitAnalysisResult = await this.spreadAnalyzer.analyze(quotes, this.positionService.positionMap, pair);
this.log.debug(`pair: ${pair}, result: ${JSON.stringify(exitAnalysisResult)}.`);
this.log.info(this.formatPairInfo(pair, exitAnalysisResult));
const limitResult = this.limitCheckerFactory.create(exitAnalysisResult, pair).check();
if (limitResult.success) {
return { closable: true, key, exitAnalysisResult };
Expand All @@ -86,20 +88,10 @@ export default class OppotunitySearcher extends EventEmitter {
return { closable: false };
}

private printActivePairs(activePairs: OrderPair[]): void {
if (activePairs.length === 0) {
return;
}
this.log.info(t`OpenPairs`);
activePairs.forEach(pair => {
this.log.info(this.formatPair(pair));
});
}

private formatPair(pair: OrderPair) {
private formatPairInfo(pair: OrderPair, exitAnalysisResult: SpreadAnalysisResult) {
return `[${pair[0].toShortString()}, ${pair[1].toShortString()}, Entry PL: ${_.round(
calcProfit(pair, this.configStore.config).profit
)} JPY]`;
)} JPY, Current exit cost: ${_.round(-exitAnalysisResult.targetProfit)} JPY]`;
}

private printSpreadAnalysisResult(result: SpreadAnalysisResult) {
Expand Down

0 comments on commit 80cb354

Please sign in to comment.