Skip to content

datastream

sequenceDiagram
participant App as Datastream App
participant BS as Block Scholes WS
participant Store as Exchange Store
participant Redis as Redis Store
participant Broker as Redis Broker

    App->>BS: Connect
    BS-->>App: Connection Established

    App->>BS: Authenticate(api_key)
    BS-->>App: Authentication Response

    Note over App: Get active pairs/instruments

    App->>BS: Subscribe(pairs, instruments)
    BS-->>App: Subscription Confirmed

    loop Message Processing
        BS->>App: Send Data Update

        alt is Value Message (index/rate/perpetual)
            App->>Store: Update Value
            Store->>Redis: Store TimeObservable[value]
            Store->>Redis: Update universe:pair keys
            App->>Broker: Publish to index_price stream

            Note over Store: Calculate funding rate<br/>if perpetual price updated

        else is Model Message (SVI)
            App->>Store: Update SVI Parameters
            Store->>Redis: Store TimeObservable[SVI]
            Store->>Redis: Update expiry market data

            Note over Store: Recalculate IVs<br/>for affected options
        end

        alt Order Book Update
            Store->>Redis: Update orders:chain_id:instrument:side
            Note over Store: Group orders by price level
        end

        App->>App: Check for subscription updates
    end

    Note over App: Handle SIGTERM
    App->>BS: Disconnect