Giter Club home page Giter Club logo

Comments (4)

nardew avatar nardew commented on September 18, 2024

Hi @bastienjalbert ,
you are probably after a construct like this:

async def main_loop():
    while True:
        toto()
        tada()
        await asyncio.sleep(1) # sleep asynchronously for 1 sec

async def run():
    client = CryptoXLib.create_aax_client(api_key, sec_key)
    client.compose_subscriptions(...)

        await asyncio.gather(*[
            client.start_websockets(),
            main_loop()
        ])

    await client.close()

if __name__ == "__main__":
    async_run(run())

Have a look at examples/ws_subscriptions.py.

from cryptoxlib-aio.

bastienjalbert avatar bastienjalbert commented on September 18, 2024

Thank you @nardew, appreciate that !

Is there any way to prevent main_loop() to be executed (like waitFor) until the client.start_websockets() has been "launched" ?
Since toto() or tada() may push orders on the market, I would like to monitoring them through the compose_subscriptions callback, but the websockets subscription / start looks slower then my main_loop(). I cannot put a While True: in the main_loop because toto and tada need somehow synchronous. In reality it's only the last step of tada() who need to do some stuff asynchronously (like checking orders status).

I think I may need multi loop or multi threading to achieve that ...

from cryptoxlib-aio.

nardew avatar nardew commented on September 18, 2024

I am not quite sure what is the ultimate goal but if you need to make sure toto and tada are called only after the streams are initiated, then you can

i) add toto and tada directly into the websocket callback
ii) have a variable which is set in the websocket callback and then have a check for the variable in the main loop

from cryptoxlib-aio.

nardew avatar nardew commented on September 18, 2024

Since there was not follow up in the past month, I am closing the thread. Re-open if needed.

from cryptoxlib-aio.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.