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

Anyway to have this code run only once? #47

Open
stuald opened this issue Jul 12, 2024 · 4 comments
Open

Anyway to have this code run only once? #47

stuald opened this issue Jul 12, 2024 · 4 comments

Comments

@stuald
Copy link

stuald commented Jul 12, 2024

Hi guys,

is there a way to adjust the base python code to run only once.. rather than the continual and constant live update?
right now I am running the code, and leaving open for 3 minutes before a "close" exit function.

id like to be able to run... and then it just finishes once all the tasks are complete if possible.

thanks
Stuart

@elvinex
Copy link
Collaborator

elvinex commented Jul 12, 2024

Hi Stuart,

If you use the provided example, which has

while processor.dwx.ACTIVE:
    sleep(1)

at the end of the file, you could just set self.dwx.ACTIVE = false at the point you want to exit.

@stuald
Copy link
Author

stuald commented Jul 12, 2024

thanks Elvinex,
firstly I should say - great piece of code. I'm loving it. thank you ever so much.

I don't use the base code as a live type interaction method. I use it as a run once only.
I currently modify your sleep to 180 - so it has time to process everything within my function. (but 180 isn't guaranteed enough of course depending on what is going on)
I run my specific buy/sell/modify and math code lines within the get history function. (I've emptied the other functions, so no live ticker pricing etc. all it does it get history and then execute my lines.)
Sometimes, it takes a long time to modify a larger number of trades.
180 of course is not guaranteed, hence looking for a way to exit after my code is done, rather than maxing 180 seconds.

So I added sys.exit() after the sleep 180.

instead, should i keep the sleep(1) and...
Should I therefore add your line of code(self.dwx.ACTIVE = false) at the end of the get history function? so that it exits once all this modification is finished? or place this after the sleep(1), or place within the CLASS itself after the #get_history function -as the method to exit.
I want the full function to still run of course? :)

thanks for your help
Stuart

@elvinex
Copy link
Collaborator

elvinex commented Jul 13, 2024

Lol, if 180s is not enough, it must be a quite a number of tasks.

Normally, I would place the self.dwx.ACTIVE = False after confirmation that all of the tasks have been done. But it depends on what the tasks actually are.
For example, if the task was just to send one order, you could wait until on_order_event will trigger with that order event. If you have multiple orders, you could count how many etc.

Or if you don't care about the feedback that everything was actually done, I would put the sleep(180) and exit() after the last command. This way you at least know that the code before has been executed.

@stuald
Copy link
Author

stuald commented Jul 16, 2024

thanks elvinex, I will have a play with this and update the thread before closing.

thanks
Stuart

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

No branches or pull requests

2 participants