I'm recently trying to monitor transactions of a contract address on BSC chain for my dex limit order and I finally found a stable solution to monitor the log event -- 'using web sockect connection'.
bsc = "wss://ws-nd-112-055-480.p2pify.com/xxxxxxxxxxxxxxxxxxx"
web3 = Web3(Web3.WebsocketProvider(bsc))
poolAdd = '0x0eD7e52944161450477ee417DE9Cd3a859b14fD0'
block_filter = web3.eth.filter({'fromBlock': 'latest', 'address': poolAdd, 'topics': [sha128Dic['swap']]})
while 1:
log_new(block_filter)
time.sleep(1)
However, I tried to change some websokect endpoint provider among below list, there's still some huge time delay of the swap event log. Some of those happens nearly one hour ago.
wss://bsc-ws-node.nariox.org:443
Moralis: https://moralis.io/speedy-nodes/
ANKR: https://app.ankr.com/api
Chainstack: https://chainstack.com/build-better-with-binance-smart-chain/
When I switch back to http provider like: Web3.HTTPProvider('https://bsc-dataseed.binance.org/'). the event log is nearly in time but some 'filter not found exception will be found during the time elapse'.
Here's the note written on BSC websocket introduction: 'You can make eth_getLogs requests with up to a 5K block range. If you need to pull logs frequently, we recommend using WebSockets to push new logs to you when they are available.'
Can anyone help out to find a better way to get a timely websocket endpoint?
to optimize the latency you need to run your own node which needs a very powerfull dedicated server or you can get a private node from fastlynode