MetaApi Cloud API TradeError: Request canceled by timeout

126 views Asked by At

I am getting TradeError: Request canceled by timeout too often when I try to hit the trade requests with MetaApi Cloud SDK. I have looked at their documentation and it is one of the errors that occur but so far I haven't found anything on the internet that specifically talks about this problem. I would like to know more about the problem and how can I tackle it.

This is the documentation for the responses from them, I am hitting the code:10012 TRADE_RETCODE_TIMEOUT error it seems. https://metaapi.cloud/docs/client/models/metatraderTradeResponse/

If anyone knows how to tackle it, I would really appreciate it. I know these are usually network errors but if there's anything we can do from coding side to improve user experience, I would like to do it.

I am using this sdk for development https://github.com/agiliumtrade-ai/metaapi-browser-javascript-sdk

I am just following the sdk and calling action by first initializing the connection and then calling the actions based on that connection.

This is how I am initializing connection

        const accounts = await metaApi.metatraderAccountApi.getAccounts();
        let account = accounts.find(a => a.login === user.login && a.type.startsWith('cloud'));

        // -> Deploy account
        await account.deploy();

        // -> Wait until connected
        await account.waitConnected();


        // -> Connect to MetaApi API
        const connection = account.getStreamingConnection();
        await connection.connect();
        await connection.waitSynchronized();

        this.account = account;
        this.connection = connection;

and this how I am calling an action based on connection

    // getting positions for example
    async getPositions() {
        return this.connection?.terminalState.positions;
    }

Please let me know how can I improve this so I can tackle the timeout errors because the metaAPI seems to hit them too often.

0

There are 0 answers