Skip to main content

MesoLive Historical Data Hub

Use MesoLiveHistoricalDataHubClient for persisted account NAV and PnL/greek/price/IV time series.

Runnable examples

The mesolive-sdk-examples package includes historical_data_example:

python -m mesolive_sdk_examples.historical_data_example --help
python -m mesolive_sdk_examples.historical_data_example account-nav --broker-account-id ML1234 --broker-type MesoLive
python -m mesolive_sdk_examples.historical_data_example position-metrics --position-id 789 --include PnL,Greeks
python -m mesolive_sdk_examples.historical_data_example strategy-metrics --strategy-id 123 --underlying-contract-id 456
python -m mesolive_sdk_examples.historical_data_example underlying-metrics --underlying-contract-id 456
python -m mesolive_sdk_examples.historical_data_example leg-metrics --leg-id 456 --compression Zstd

Examples decode payloads by default and print JSON-safe output. Pass --raw-payload when you need the compressed envelope and pagination metadata only.

Add --plot-html <path> to write an interactive Plotly report for the returned page. Use --no-json-output when you only want the chart, --plot-open to open the generated report, and --plotlyjs embed when the report must be self-contained instead of loading Plotly from the CDN.

python -m mesolive_sdk_examples.historical_data_example account-nav --broker-account-id ML1234 --broker-type MesoLive --plot-html account-nav.html --no-json-output
python -m mesolive_sdk_examples.historical_data_example position-metrics --position-id 789 --include PnL,Greeks --plot-html position-metrics.html

Plotting preserves pagination semantics: it renders the page returned by the current query arguments. Use --limit and --continuation-token to choose which page to render.

Methods

Python SDKHub methodResult payload
get_account_navGetAccountNavHistoricalAccountNavPayload
get_position_metricsGetPositionMetricsHistoricalMetricPayload
get_strategy_metricsGetStrategyMetricsHistoricalMetricPayload
get_underlying_metricsGetUnderlyingMetricsHistoricalMetricPayload
get_leg_metricsGetLegMetricsHistoricalMetricPayload

Queries share paging, resolution, granularity, rollup value mode, time-window, and compression options. ContinuationToken values are opaque; pass the returned token into the next request unchanged.

Plotly output

Account NAV reports render NAV, cash, and maintenance margin series. Metric reports render PnL, Greek, price, and IV series when those values are present in the decoded payload. Rollup OHLC points use close values for the line and include translucent low/high bands when the payload contains them. Points are sorted by timestamp, raw before rollup, then raw/rollup id to match the automation views.

Payload decoding

Historical responses include a HistoricalDataPayload envelope. Decode account NAV and metric results with the helper matching the method family:

from mesolive_sdk import MesoLiveHistoricalDataHubClient, models
from mesolive_sdk.historical_data import decode_account_nav_payload, decode_metric_payload

historical = MesoLiveHistoricalDataHubClient(
mesolive_instance=instance,
mesolive_api_key=api_key,
)

result = await historical.get_position_metrics(
models.GetPositionMetricsArgs(
PositionId=789,
Include=models.HistoricalMetricInclude.PnL | models.HistoricalMetricInclude.Greeks,
Compression=models.HistoricalDataCompression.Gzip,
)
)
decoded = decode_metric_payload(result)
print(decoded.compression, decoded.compressed_size_bytes, decoded.uncompressed_size_bytes)
print(decoded.data.Series)

decode_account_nav_payload(result) validates HistoricalDataPayloadKind.AccountNav; decode_metric_payload(result) validates HistoricalDataPayloadKind.Metrics.

Resolution modes

  • Auto: bounded chart-history mode. The server stitches rollups with the recent raw tail where possible.
  • Raw: high-resolution samples only; this is the only tail-following mode.
  • Rollup: rollup buckets only, using the selected granularity.

For rollup points, use RollupValueMode to request Ohlc or close-only values.

Reconnect hooks

Historical Data clients support the same lifecycle hooks as other hub clients:

historical.on_reconnecting(lambda: print("historical data reconnecting"))
historical.on_reconnected(lambda: print("historical data reconnected"))