Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor PnL #29

Merged
merged 7 commits into from
Aug 2, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/tarcisiozf/bfx-hf-strategy.git#refactor-pnl",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wait for merge

"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