Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
tferraz-bitfinex committed Sep 15, 2022
2 parents 0fe5619 + b8b92bc commit ee597b7
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 13 deletions.
8 changes: 6 additions & 2 deletions lib/ws_servers/api/factories/create_strategy_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,25 @@ const send = require('../../../util/ws/send')

/**
* @param {APIWSServer} server
* @param {Session} session
* @param {FilteredWebSocket} ws
* @param {string} scope
* @param {function} sendDataToMetricsServer
* @returns {StrategyManager}
*/
module.exports = (server, ws, scope, sendDataToMetricsServer) => {
module.exports = (server, session, ws, scope, sendDataToMetricsServer) => {
const { wsURL, restURL, strategyExecutionDB } = server
const { apiKey, apiSecret } = session.getCredentials()
const bcast = send.bind(null, ws)

return new StrategyManager(
{
dms: false,
wsURL,
restURL,
scope
scope,
apiKey,
apiSecret
},
bcast,
strategyExecutionDB,
Expand Down
19 changes: 16 additions & 3 deletions lib/ws_servers/api/handlers/strategy/strategy_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,14 @@ const EXECUTION_RESULTS_OMIT_FIELDS = ['candles', 'trades']

class StrategyManager {
constructor (settings, bcast, strategyExecutionDB, sendDataToMetricsServer) {
const { wsURL, restURL, scope, closeConnectionsDelay = CLOSE_CONNECTIONS_DELAY } = settings
const {
wsURL,
restURL,
scope,
closeConnectionsDelay = CLOSE_CONNECTIONS_DELAY,
apiKey,
apiSecret
} = settings

this.wsURL = wsURL
this.restURL = restURL
Expand All @@ -43,7 +50,12 @@ class StrategyManager {
this.closeConnectionsTimeout = null
this.connectionLost = false

this.rest = new RESTv2({ url: restURL, transform: true })
this.rest = new RESTv2({
url: restURL,
transform: true,
apiKey,
apiSecret
})

this.strategyExecutionDB = strategyExecutionDB
this.sendDataToMetricsServer = sendDataToMetricsServer
Expand Down Expand Up @@ -265,7 +277,8 @@ class StrategyManager {
scope,
ws,
priceFeed,
perfManager
perfManager,
rest
}

this.performanceWatchers = startPerformanceWatchers(
Expand Down
2 changes: 1 addition & 1 deletion lib/ws_servers/api/start_connections.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ class ConnectionManager {

const { dmsScope: scope = 'app', sendDataToMetricsServer } = session

strategyManager = createStrategyManager(server, ws, scope, sendDataToMetricsServer)
strategyManager = createStrategyManager(server, session, ws, scope, sendDataToMetricsServer)
session.setStrategyManager(strategyManager)

return { strategyManager: true }
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bfx-hf-server",
"version": "7.8.1",
"version": "7.9.1",
"description": "HF server bundle",
"author": "Bitfinex",
"license": "Apache-2.0",
Expand All @@ -27,8 +27,8 @@
"bfx-hf-indicators": "git+https://github.com/bitfinexcom/bfx-hf-indicators.git#v2.1.1",
"bfx-hf-models": "git+https://github.com/bitfinexcom/bfx-hf-models.git#v4.0.0",
"bfx-hf-models-adapter-lowdb": "git+https://github.com/bitfinexcom/bfx-hf-models-adapter-lowdb.git#v1.0.5",
"bfx-hf-strategy": "git+https://github.com/bitfinexcom/bfx-hf-strategy.git#v2.0.2",
"bfx-hf-strategy-exec": "git+https://github.com/bitfinexcom/bfx-hf-strategy-exec.git#v2.3.0",
"bfx-hf-strategy": "git+https://github.com/bitfinexcom/bfx-hf-strategy.git#v2.1.0",
"bfx-hf-strategy-exec": "git+https://github.com/bitfinexcom/bfx-hf-strategy-exec.git#v2.3.1",
"bfx-hf-strategy-perf": "git+https://github.com/bitfinexcom/bfx-hf-strategy-perf.git#v3.0.1",
"bfx-hf-ui-config": "git+https://github.com/bitfinexcom/bfx-hf-ui-config#v1.6.0",
"bfx-hf-util": "git+https://github.com/bitfinexcom/bfx-hf-util.git#v1.0.12",
Expand Down
2 changes: 1 addition & 1 deletion test/unit/lib/ws_servers/api/start_connections.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ describe('ConnectionManager', () => {
assert.calledWithExactly(startWorkerStub, { apiKey, apiSecret, userId: 'HF_User' })

assert.calledWithExactly(session.getStrategyManager)
assert.calledWithExactly(createStrategyManager, server, filteredWs, dmsScope, session.sendDataToMetricsServer)
assert.calledWithExactly(createStrategyManager, server, session, filteredWs, dmsScope, session.sendDataToMetricsServer)
assert.calledWithExactly(session.setStrategyManager, strategyManager)

assert.calledWithExactly(session.getMetricsClient)
Expand Down
21 changes: 18 additions & 3 deletions test/unit/lib/ws_servers/api/strategy/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,15 @@ describe('Strategy Manager', () => {
const apiKey = 'api key'
const apiSecret = 'api secret'
const authToken = 'auth token'
const settings = { wsURL, scope: 'app', restURL, dms, closeConnectionsDelay: 500 }
const settings = {
wsURL,
scope: 'app',
restURL,
dms,
closeConnectionsDelay: 500,
apiKey,
apiSecret
}
const bcast = WsStub

const ws = { conn: 'connection details' }
Expand Down Expand Up @@ -128,7 +136,9 @@ describe('Strategy Manager', () => {

assert.calledWithExactly(restV2Stub, {
url: restURL,
transform: true
transform: true,
apiKey,
apiSecret
})
})
})
Expand Down Expand Up @@ -189,7 +199,12 @@ describe('Strategy Manager', () => {
await manager.execute(parsedStrategy, strategyOptions)

assert.calledWithExactly(StrategyExecutionConstructor, {
strategy: { ws, scope: 'app', ...parsedStrategy },
strategy: {
ws,
scope: 'app',
rest: manager.rest,
...parsedStrategy
},
ws2Manager: manager.ws2Manager,
rest: manager.rest,
strategyOptions,
Expand Down

0 comments on commit ee597b7

Please sign in to comment.