Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kraken client downloading orders again in fetchOrder? #22210

Open
Nomad-Soul opened this issue Apr 19, 2024 · 3 comments
Open

Kraken client downloading orders again in fetchOrder? #22210

Nomad-Soul opened this issue Apr 19, 2024 · 3 comments
Assignees
Labels

Comments

@Nomad-Soul
Copy link

Operating System

Windows 11

Programming Languages

JavaScript

CCXT Version

4.3.1

Description

I have made a simple test, using the kraken client. I just wanted to see how long ccxt took to download an order because it seemed to me that it was taking too long. So I measured the time it takes to fetch an order after a call to both loadMarkets and fetchClosedOrders and ccxt takes 3 seconds to execute fetchOrder (not counting the other seconds to execute those two prior calls to loadMarkets and fetchClosedOrders).

But if I'm understanding correctly how ccxt works, the orders should already have been downloaded from the fetchClosedOrders call. Indeed if I swap the fetchOrder call in the code below with an array search, it takes 1 ms instead of 3000 ms because the order I am looking for is indeed already in the array but it looks like it is being downloaded again.

Or is the fetchOrder call intended to download it again, even if it is a closed order that is not going to change anymore?
Even so, comparing it to my own implementation which takes less than 100 ms, three seconds seem way too much.

Am I doing something wrong or is there an underlying issue? Thanks in advance.

Code

    this.#ccxtClient = new ccxt[accountSettings.type]({
      apiKey: accountSettings.publicKey,
      secret: accountSettings.privateKey,
    });

    // [...]
    var orderId = 'xxxxx-...';
    await this.#ccxtClient.loadMarkets();
    var orders = await this.#ccxtClient.fetchClosedOrders(undefined, undefined, 100);

    var now = Date.now();
    var order = await this.#ccxtClient.fetchOrder(orderId);
    // if I replace the above line with this next one, the code outputs "1 ms" because the order is already in that array.
    //var order = orders.find((o) => o.id === orderId);
    console.log(order.id);
    var elapsed = Date.now() - now;
    App.warning(`Took: ${elapsed} ms`);

    now = Date.now();
    // #krakenClient is my own implementation
    order = await this.#krakenClient.queryOrder(orderId);
    elapsed = Date.now() - now;
    console.log(order.txid);
    App.warning(`Took: ${elapsed} ms`);  

Output:

xxxxx-...
  Took: 3109 ms
xxxxx-...
  Took: 65 ms
@sc0Vu sc0Vu self-assigned this Apr 19, 2024
@sc0Vu
Copy link
Contributor

sc0Vu commented Apr 19, 2024

@Nomad-Soul there's no cache mechanism in fetchOrder api. The request would be sent to exchange directly. You may implement cache in code.

@sc0Vu sc0Vu added the question label Apr 19, 2024
@Nomad-Soul
Copy link
Author

So it must be downloading all orders again, otherwise how come my own implementation is just 60 ms?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants
@sc0Vu @Nomad-Soul and others