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

dynamic watch ticker solution? #10686

Closed
ghost opened this issue Nov 23, 2021 · 5 comments
Closed

dynamic watch ticker solution? #10686

ghost opened this issue Nov 23, 2021 · 5 comments
Assignees
Labels
question ws Websockets (a.k.a. PRO)

Comments

@ghost
Copy link

ghost commented Nov 23, 2021

Hello,

I was thinking to create little bit more complex solution to watch ticks, where I would be able to create something like a dynamic tick watcher. With dynamic I mean to define which exchange symbol I want to watch while the loop is already running.

I created script where I am watching ticks from multiple exchanges and symbols based on this example
https://github.com/ccxt/ccxt/blob/master/examples/ccxt.pro/py/many-exchanges-many-different-streams.py

But I would like to have an option to add or remove tick watchers for different symbols in different exchanges while the loop is already running. I would really appreciate any idea of a solution but my main focus is to have this solution in python.

Thank you for answer

@kroitor kroitor self-assigned this Nov 23, 2021
@ghost
Copy link
Author

ghost commented Dec 2, 2021

Hello @kroitor , I know you have a lot on your mind but did you came with any idea?

@ttodua ttodua added the ws Websockets (a.k.a. PRO) label Dec 28, 2021
@ttodua
Copy link
Member

ttodua commented Dec 28, 2021

The abortion of already running loop is not yet documented. (however, this is related and might get implemented in foreseeable future: #10786 )

@kroitor
Copy link
Member

kroitor commented Dec 28, 2021

@mvazny pardon for the long wait, I'll post an example on how to add watchTicker loops in runtime here.

@avmarko
Copy link

avmarko commented May 3, 2023

Are there any updates ?
I am looking for an example on how to dynamically add/remove watchTicker loops during runtime.
Even an "exchange-specific" solution (for binance only) would help me a lot :-)

@ttodua
Copy link
Member

ttodua commented Aug 27, 2024

late reply here, but for context, after that period in ccxt we added watchTickers for many exchanges, so you can use that method.
some notes when using watchTickers:

  • some exchanges might be able to watch all tickers, so you can just skip the symbol which you don't want
  • if exchange requires list of symbols, then you can easily amend the symbols during runtime, smth like this example:
const ex = new ccxt.pro.binance();
let mySymbols = ['BTC/USDT', 'ETH/USDT'];

async function myWatch () {
    while(true) {
        const result = await ex.watchTickers (mySymbols);
        console.log(result);
    }
}
   
function modifyFunc () {
  mySymbols = ['SOL/USDT']; // etc... modified in another place during runtime
} 

async main() {
    myWatch ();
    await ex.sleep(5000);
    modifyFunc ();
}

main();

@ttodua ttodua closed this as completed Aug 27, 2024
@ttodua ttodua self-assigned this Aug 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question ws Websockets (a.k.a. PRO)
Projects
None yet
Development

No branches or pull requests

3 participants