Skip to content

Commit

Permalink
reconnect only when in the same mode (#202)
Browse files Browse the repository at this point in the history
* handle close of other mode

* move notification

* improve test

* update version

Co-authored-by: Tarcisio Ferraz <[email protected]>
  • Loading branch information
tarcisiozf and tferraz-bitfinex authored Sep 21, 2022
1 parent b09438b commit 9d37e79
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
17 changes: 8 additions & 9 deletions lib/ws_servers/api/handlers/on_save_api_credentials.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,14 @@ module.exports = async (server, ws, msg) => {

d('issuing API & Algo reconnect due to credentials change')

ws.authenticateSession({
apiKey,
apiSecret,
mode,
dmsScope
})
await ws.closeMode(formSent)

notifySuccess(ws, 'Reconnecting with new credentials...', ['reconnectingWithNewCredentials'])
if (formSent === mode) {
notifySuccess(ws, 'Reconnecting with new credentials...', ['reconnectingWithNewCredentials'])

await ws.closeMode(mode)
await connManager.start(server, ws)
ws.authenticateSession({ mode, dmsScope, apiKey, apiSecret })
await connManager.start(server, ws)
} else {
ws.setCredentialsForMode(formSent, apiKey, apiSecret)
}
}
4 changes: 4 additions & 0 deletions lib/ws_servers/api/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ class Session {
this.mode = mode
this.dmsScope = dmsScope
this.isPaper = mode === 'paper'
this.setCredentialsForMode(mode, apiKey, apiSecret)
}

setCredentialsForMode (mode, apiKey, apiSecret) {
this.credentials[mode] = { apiKey, apiSecret }
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bfx-hf-server",
"version": "7.9.3",
"version": "7.9.4",
"description": "HF server bundle",
"author": "Bitfinex",
"license": "Apache-2.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ describe('on save api credentials', () => {
authPassword: 'secret',
authControl: 'auth control',
closeMode: sandbox.stub(),
authenticateSession: sandbox.stub()
authenticateSession: sandbox.stub(),
setCredentialsForMode: sandbox.stub()
}
const authToken = 'authToken'
const apiKey = 'apiKey'
Expand Down Expand Up @@ -150,7 +151,9 @@ describe('on save api credentials', () => {
['encryptedApiCredentialsSavedFor', { target: 'Bitfinex' }]
)
assert.calledWithExactly(stubWsSend, ws, ['data.api_credentials.configured', 'bitfinex'])
assert.notCalled(server.reconnectAlgoHost)
assert.calledWithExactly(ws.setCredentialsForMode, formSent, apiKey, apiSecret)
assert.notCalled(ws.authenticateSession)
assert.notCalled(stubStartConnections)
})

it('should start algo worker', async () => {
Expand Down

0 comments on commit 9d37e79

Please sign in to comment.