Skip to content

Commit

Permalink
refactor PnL (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
tarcisiozf authored Aug 2, 2022
1 parent 42657c0 commit 620cad2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
10 changes: 7 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down Expand Up @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 620cad2

Please sign in to comment.