Closed wmbutler closed 6 years ago
Now you need to use a timer. But in the next version I'll try to add an event to create a new block. Subscription for the account is also in the plans, but it turned out to be more complicated than I expected. I need time to test everything.
From btsdex v0.3.1 has three types of events:
connected
- works once after connecting to the blockchain;block
- it works when a new block is created in the blockchain;account
- occurs when the specified account is changed (balance change).For example:
const BitShares = require("btsdex");
BitShares.init("wss://bitshares.openledger.info/ws");
BitShares.subscribe('connected', startAfterConnected);
BitShares.subscribe('block', callEachBlock);
BitShares.subscribe('account', changeAccount, 'trade-bot');
async function startAfterConnected() {/* is called once after connecting to the blockchain */}
async function callEachBlock(obj) {/* is called with each block created */}
async function changeAccount(array) {/* is called when you change the 'trade-bot' account */}
This is awesome. Thanks!
Thanks for providing enhancements and adding to your instructions. It's much appreciated.
I am currently using the subscribe method to run a function once
'connected'
. I have a few questions about how to handle monitoring activity to perform subsequent operations. Ideally, I'd like to receive events from the particular market(s) my bot is operating on and check to see if my orders need to be updated whenever the market changes.If that is not possible, I expect I will run a timer that will loop through my
startAfterConnected
function at a regular interval. I'm hoping you can provide more guidance on observable events.