Skip to main content

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).

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);
}
})();

Timing Things

Error Handling

Async vs. Sync

Throttling

Tracking

State Management