From 620cad2a0a164fcc058ea21feaa3a5e12b6b31d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tarc=C3=ADsio=20Zotelli=20Ferraz?= Date: Tue, 2 Aug 2022 16:09:58 -0300 Subject: [PATCH] refactor PnL (#29) --- index.js | 10 +++++++--- package.json | 4 ++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 16d5467..db0c494 100644 --- a/index.js +++ b/index.js @@ -10,9 +10,10 @@ const PromiseThrottle = require('promise-throttle') const debug = require('debug')('bfx:hf:strategy-exec') const { onSeedCandle, onCandle, onTrade, closeOpenPositions, - getPosition, positionPl + getPosition } = require('bfx-hf-strategy') const _generateStrategyResults = require('bfx-hf-strategy/lib/util/generate_strategy_results') +const { calcRealizedPositionPnl, calcUnrealizedPositionPnl } = require('bfx-hf-strategy/lib/pnl') const EventEmitter = require('events') @@ -303,8 +304,11 @@ class LiveStrategyExecution extends EventEmitter { const openPosition = getPosition(this.strategyState, symbol) if (openPosition && price) { - openPosition.pl = positionPl(this.strategyState, symbol, price) - this.emit('opened_position_data', openPosition) + this.emit('opened_position_data', { + ...openPosition, + realizedPnl: calcRealizedPositionPnl(openPosition), + unrealizedPnl: calcUnrealizedPositionPnl(openPosition, price) + }) } this.emit('rt_execution_results', this.generateResults(openPosition)) diff --git a/package.json b/package.json index 3390b02..5e4ff97 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bfx-hf-strategy-exec", - "version": "2.1.0", + "version": "2.2.0", "description": "Execution logic for bfx-hf-strategy", "main": "./index.js", "directories": { @@ -36,7 +36,7 @@ ], "dependencies": { "bfx-api-node-core": "git+https://github.com/bitfinexcom/bfx-api-node-core.git#v1.6.1", - "bfx-hf-strategy": "git+https://github.com/bitfinexcom/bfx-hf-strategy.git#v1.5.5", + "bfx-hf-strategy": "git+https://github.com/bitfinexcom/bfx-hf-strategy.git#v2.0.0", "bfx-hf-util": "git+https://github.com/bitfinexcom/bfx-hf-util.git#v1.0.12", "debug": "^4.3.3", "lodash": "^4.17.10",