Skip to content

Add azure blob storage state serializer and deserializer for stateless run with statefull support #274

@MDUYN

Description

@MDUYN

Azure Storage provides a simple, scalable, and cost-effective way to save state and could be used to allow users to run their algorithm stateless in an Azure function but still store their state in between runs in a azure blob container.

Initialisation should look like this:

from investing_algorithm_framework import AzureBlobStorageStateHandler
from azure.storage.blob import BlobServiceClient

connection_string = "<your_connection_string>"
container_name = "my-container"

state_handler = AzureBlobStorageStateHandler(connection_string, container_name=container_name)
app = create_app(config=config, state_handler=state_handler)

... Do all you algorithm initialization

Implementation of the state handler should look something like below:

from azure.storage.blob import BlobServiceClient

connection_string = "<your_connection_string>"
blob_service_client = BlobServiceClient.from_connection_string(connection_string)
container_name = "my-container"
blob_name = "my-state.json"

# Write state
blob_client = blob_service_client.get_blob_client(container=container_name, blob=blob_name)
blob_client.upload_blob("My serialized state", overwrite=True)

# Read state
download_stream = blob_client.download_blob()
state = download_stream.readall()

Class AzureBlobStorageStateHandler(StateHandler):

.....
      def store(algorithm):

      def load_portfolio() -> Portfolio
      def load_orders() -> List[Order]
      def load_trades() -> List[Trade]
      def load_position() -> List[Position]

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions