Programming Concepts
Here we will cover programming concepts that are not specifically related to the cTrader OpenAPI, but are useful in our intercation with it (or any other similar server). For example, concepts like infinite loop, timing, error handling, async vs sync, throttling, tracking, state management, and etc.
Infinite Loop
In this way, the program runs endlessly giving us the opportunity to check program state at specific intervals (e.g. every 2 seconds).
- JavaScript - Node.js
- Python
const CHECK_INTERVAL_SECS = 2;
(async () => {
while (true) {
await sleep(0); // neccessary in "async infinite loops"
console.log('checking things...');
await sleep(CHECK_INTERVAL_SECS);
}
})();
import asyncio as aio
CHECK_INTERVAL_SECS = 2
async def main():
while True:
await aio.sleep(0) # neccessary in "async infinite loops"
print('checking things...')
await aio.sleep(CHECK_INTERVAL_SECS)
aio.run(main())