Scheduler

The scheduler class is used to run functions with a low-overhead CPU cost, as well as pass cached arguments & data. This allows single functions to double as asynchronous logic that can be used across exchanges & currencies.

Creation

A scheduler can be created by calling blankly.Scheduler:

Arguments

ArgDescriptionExamplesType
callbackFill with a function reference to be called in the scheduler thread.price_eventcallable
intervalTime interval for the given function to run.'2m' or '3h'str or int/float
initially_stoppedOptional boolean. If set to True, the scheduler will not start until .start() is run.Truebool
syncedAlign the scheduler with intervals in UTC. ex: if the interval is '1h' then with sync it will only run at *:00Truebool
**kwargsArguments to pass into the callback function. This can be used to distinguish what the logic in the callback should do.'asset_id='BTC-USDAny

Response

DescriptionExamplesType
A scheduler objectscheduler = blankly.Scheduler(price_event, '2m')Scheduler

Functions

start(force=False)

Start a scheduler. This only needs to be used if initially_stopped is set to True.

Arguments

ArgDescriptionExamplesType
forceOptional argument to override any duplicate thread protection.Truebool

get_interval()

Get the interval in seconds that the scheduler is running on.

Response

DescriptionExamplesType
The scheduler interval in seconds120, 3600, 86400str

get_kwargs()

Get the custom arguments that were passed during construction.

Response

DescriptionExamplesType
A dictionary containing all the key/value pairs that were added during construction.{'asset_id': 'BTC-USD'}dict

stop_scheduler()

Raise a stop flag that will be checked on the next scheduler run & stop the thread.

get_callback()

Get the callback function that the scheduler is attached to.

Response

DescriptionExamplesType
The callable object passed in during object construction.price_event callablecallable