Thanks for the reply.
I am using the sample subscribequote code from tradovate:
const syncSocket = new TradovateSocket({debugLabel: ‘sync data’})
and
TradovateSocket.prototype.subscribe = async function({url, body, subscription}) {
const self = this
let removeListener = noop
let cancelUrl = ''
let cancelBody = {}
let contractId
console.log('url='+url)
let response = await this.send({url, body})
if(response.d['p-ticket']) {
await waitForMs(response.d['p-time']*1000)
let nextResponse = await self.send({url, body: {...body, 'p-ticket': response.d['p-ticket']}})
console.log('p-ticket')
response = nextResponse
}
const realtimeId = response?.d?.realtimeId || response?.d?.subscriptionId
if(body?.symbol && !body.symbol.startsWith('@')) {
const contractRes = await tvGet('/contract/find', { name: body.symbol })
contractId = contractRes?.id || null
if(!contractId) {
contractId = await tvGet('/contract/suggest', {name: body.symbol })[0].id
}
}
if(!realtimeId && response.d && response.d.users) { //for user sync request's initial response
subscription(response.d)
}
return new Promise((res, rej) => {
//console.log('swtich='+url)
switch(url.toLowerCase()) {
case 'md/getchart': {
cancelUrl = 'md/cancelChart'
cancelBody = { subscriptionId: realtimeId }
if(this.listeningURL !== MD_URL) rej('Cannot subscribe to Chart Data without using the Market Data URL.')
removeListener = self.addListener(data => {
if(data.d.charts) {
data.d.charts.forEach(chart => chart.id === realtimeId ? subscription(chart) : noop())
}
})
break
}
case 'md/subscribedom': {
cancelUrl = 'md/unsubscribedom'
cancelBody = { symbol: body.symbol }
if(this.listeningURL !== MD_URL) rej('Cannot subscribe to DOM Data without using the Market Data URL.')
removeListener = self.addListener(data => {
if(data.d.doms) {
data.d.doms.forEach(dom => dom.contractId === contractId ? subscription(dom) : noop())
}
})
break
}
case 'md/subscribequote': {
console.log('tvsocket/md/subquote reached')
cancelUrl = 'md/unsubscribequote'
cancelBody = { symbol: body.symbol }
if(this.listeningURL !== MD_URL) rej('Cannot subscribe to Quote Data without using the Market Data URL.')
removeListener = self.addListener(data => {
if(data.d.quotes) {
data.d.quotes.forEach(quote => quote.contractId === contractId ? subscription(quote) : noop())
}
})
break
}
case 'md/subscribehistogram': {
cancelUrl = 'md/unsubscribehistogram'
cancelBody = { symbol: body.symbol }
if(this.listeningURL !== MD_URL) rej('Cannot subscribe to Histogram Data without using the Market Data URL.')
removeListener = self.addListener(data => {
if(data.d.histograms) {
data.d.histograms.forEach(histogram => histogram.contractId === contractId ? subscription(histogram) : noop())
}
})
break
}
case 'user/syncrequest': {
console.log('tvsocket/user/sync reached')
if(this.listeningURL !== WS_DEMO_URL && url !== WS_LIVE_URL) rej('Cannot subscribe to User Data without using one of the Demo or Live URLs.')
removeListener = self.addListener(data => {
if(data?.d?.users || data?.e === 'props') {
subscription(data.d)
}
})
break
}
default:
rej('Incorrect URL parameters provided to subscribe.')
break
}
res(async () => {
removeListener()
if(cancelUrl && cancelUrl !== '') {
await self.send({ url: cancelUrl, body: cancelBody })
}
})
})
}
and
TradovateSocket.prototype.send = async function({url, query, body, onResponse, onReject}) {
const self = this
return new Promise((res, rej) => {
const id = this.increment()
self.ws.addEventListener('message', function onEvent(msg) {
const [_, data] = prepareMessage(msg.data)
data.forEach(item => {
if(item.s === 200 && item.i === id) {
if(onResponse) {
onResponse(item)
}
self.ws.removeEventListener('message', onEvent)
res(item)
} else if(item.s && item.s !== 200 && item.i && item.i === id) {
//console.log(item)
self.ws.removeEventListener('message', onEvent)
if(onReject) onReject()
rej(`\nFAILED:\n\toperation '${url}'\n\tquery ${query ? JSON.stringify(query, null, 2) : ''}\n\tbody ${body ? JSON.stringify(body, null, 2) : ''}\n\treason '${JSON.stringify(item?.d, null, 2) || 'unknown'}'`)
}
})
})
console.log(`${url}\n${id}\n${query || ''}\n${JSON.stringify(body)}`)
this.ws.send(`${url}\n${id}\n${query || ''}\n${JSON.stringify(body)}`)
})
}
====
It seems the error occurred right after this step:
under TradovateSocket.prototype.send
console.log(${url}\n${id}\n${query || ''}\n${JSON.stringify(body)}
)
this.ws.send(${url}\n${id}\n${query || ''}\n${JSON.stringify(body)}
)
The console shows:
md/subscribequote
3
{“symbol”:[“MESM2”]}
index.js:9 Uncaught (in promise)
FAILED:
operation ‘md/subscribequote’
query
body {
“symbol”: [
“MESM2”
]
}
reason ‘" \ “Not found: md/subscribequote”"’