Closed thanhnguyennguyen closed 3 years ago
It's simply because there's no trades in that time, in order to keep connection alive you need to send periodic websocket pings to the server as otherwise it may close idle connections.
i don't think there's no trades in that time I put all pairs there. Once it stops, i ping again and get a lot of trades, then continue idle
It like a http api, give me trade once we ping to and then nothing until we ping again
Received: all types "recent_trades", no realtime trades
can you please provide standalone code sample that reproduces your issue? do you run serum-vial on your own or use demo server? do you set up your own Solana RPC node or use default one?
using demo server
const WebSocket = require('ws')
const ws = new WebSocket('wss://serum-vial.tardis.dev/v1/ws')
ws.onmessage = (message) => {
console.log(message.data)
}
ws.onopen = () => {
const subscribe = {
op: 'subscribe',
channel: 'trades',
types: 'recent_trades',
markets: ['RAY/USDT', 'BTC/USDC', 'SRM/USDT', 'SRM/USDC', 'SUSHI/USDC']
}
ws.send(JSON.stringify(subscribe))
}
I think you need to send periodic pings to the server (https://github.com/websockets/ws#how-to-detect-and-close-broken-connections), on serum for most pairs currently no trade periods can last multiple minutes and then connection is idle and by default would be closed without pings.
yes, we did it
Look like it always response last 100 trades. It looks like a http api rather than websocket connection with realtime trades
It's not old trades, but recent_trades
so after WS connection is established you receive last 100 trades snapshot (type:'recent_trades') and now since connection is open anytime trade happens (and those aren't very frequent most of the time) then you receive trade
message.
const WebSocket = require('ws')
// const ws = new WebSocket('ws://localhost:8000/v1/ws')
const ws = new WebSocket('wss://serum-vial.tardis.dev/v1/ws')
ws.onmessage = (message) => {
let data = JSON.parse(message.data)
if (data.type == 'trades' && Array.isArray(data.trades)) {
data.trades.forEach((value) => {
console.log("has data", data )
})
}
}
ws.onopen = () => {
const subscribe = {
op: 'subscribe',
channel: 'trades',
types: 'recent_trades',
markets: ['RAY/USDT', 'BTC/USDC', 'SRM/USDT', 'SRM/USDC', 'SUSHI/USDC']
}
ws.send(JSON.stringify(subscribe))
}
Filter by type 'trades' for new trades and set this code running in a service to always restart (establish new connection) once the current one is timeout And we don't get any log "has data" in the last 3 days
I've released one improvement, that hopefully should help in our case. Please let me know if now you get the trade data
alternatively please try subscribing via separate ws messages and provide one market in array for each subscription message, I'm looking into the issue that you see - can't reproduce it locally just yet.
did you update to demo server ?
Hi, I think I found the issue, it was due to underlying WebSocket library having issues with SSL, I turned it off for origin demo server and SSL/TLS is now handled by Cloudflare only, but that required different domain (as couldn't pull it off on existing one). Here's new url for demo server wss://api.serum-vial.dev/v1/ws
- I've tested it and seems to behave stable even when subscribing to 40 symbols at once.
yes. it works now Thank you so much
One additional question: how can we see proof of trade on Solana explorer ? (Any txhash, signature relating to the trade) I check trades from log and look at on explorer https://solanabeach.io/ , doesn't match any trade amount , so weird
Great, thanks for confirming. I was looking into tx info to match, but as far as I know it's not possible to know that, at least I wasn't able to get it from RPC node.
so nothing to prove that the trade happen
We receive tradeId, how can we use that trade ID to track the trade ?
Trade id can't be used as it's generated based on match order data (order id, size, timestamp etc), but you can use trade slot
field and look for orders that happened for given slot/block on https://solanabeach.io/address/9wFFyRfZBsuAha4YcuxcXLKwMxJR43S7fPfQLusDBzvT/recent-orders for example but since each block can have thousands of transactions it's not that straightforward to find, but possible. There's no other way as far as I know.
we may look into to see if we can get signature (txhash) of trade transaction