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

continue running ao orders if dms is disabled #252

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
12 changes: 11 additions & 1 deletion lib/ws_servers/api/algos/algo_worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class AlgoWorker {
apiKey,
apiSecret,
authToken,
dms: dms ? DMS_ENABLED : 0,
dms: 0, // always set dms 0 for AOHost. dms order cancelation will be handled by dms_remote_control
withHeartbeat: true,
affiliateCode,
wsURL,
Expand All @@ -80,6 +80,7 @@ class AlgoWorker {

this.host = host
this.registerEvents()
this.updateDms(dms)

const { caps } = await host.connect()
if (!hasRequiredPermissions(caps)) {
Expand Down Expand Up @@ -212,6 +213,15 @@ class AlgoWorker {
adapter.updateAuthArgs(args)
}

/**
* @public
* @param {number?} dms
*/
updateDms (dms) {
// if dms is disabled, skip meta:reload on disconnection
if (this.host) this.host.shouldSkipMetaReload = !dms
}

/**
* @public
* @param {number?} dms
Expand Down
4 changes: 4 additions & 0 deletions lib/ws_servers/api/dms_remote_control.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class DmsRemoteControl {
this.restURL = restURL
this.ws = null
this.isOpen = false
this.lastAlive = 0
}

async open ({ apiKey, apiSecret, dmsScope }) {
Expand Down Expand Up @@ -118,6 +119,9 @@ class DmsRemoteControl {
this._schedulePing()
onSuccess()
}

// track last connection time
this.lastAlive = Date.now()
}

_onClose () {
Expand Down
2 changes: 1 addition & 1 deletion lib/ws_servers/api/factories/create_algo_worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module.exports = (server, session, ws, settings) => {

return new AlgoWorker(
{
dms: false,
dms: settings.dms || 0,
affiliateCode,
wsURL,
restURL,
Expand Down
3 changes: 3 additions & 0 deletions lib/ws_servers/api/start_connections.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ class ConnectionManager {
* @returns {Promise<*>}
*/
async updateDms (server, session, dms, dmsScope) {
// update dms setting for algo worker
session.getAlgoWorker()?.updateDms(dms)

if (!dmsScope) {
return { dmsControl: false }
}
Expand Down