# State 008: Pricing Awareness as a Functional Track

> For the complete documentation index, see [llms.txt](https://deploy-preview-472--lucky-concha-f3599f.netlify.app/llms.txt).

State `008-pricing-awareness-market-data` extends `007-observability-lgtm-compose` and marks the first major functional expansion after the NATS messaging upgrade.

This state adds pricing awareness to trade execution, persistence, and portfolio presentation, while preserving the existing end-to-end trading flow.

## Why This State

The system previously handled quantities and securities but had no execution pricing context in persisted trades or aggregated positions.  
State `008` introduces that missing functional layer and keeps it realtime via NATS topics.

## What Changed

*   Added a new `price-publisher` component that emits random-walk quotes per ticker on `pricing.<TICKER>`.
*   Stamped execution price on trade submission in `trade-service`.
*   Persisted price on trades and volume-weighted average cost basis on positions in `trade-processor`.
*   Extended schema to include `TRADES.Price` and `POSITIONS.AverageCostBasis`.
*   Updated Angular blotters to show trade price, relative execution time, position value, cost basis, and net P&L totals.

## Verification and Regression Coverage

*   State-specific smoke suite: `./scripts/test-state-008-pricing-awareness-market-data.sh`
*   Realtime checks validated:
    *   account trade stream
    *   account position stream
    *   pricing stream (`pricing.IBM`)
*   Persistence checks validated:
    *   `trade.price` is populated
    *   `position.averageCostBasis` is populated
*   Baseline overlay smoke tests also pass under the state runtime to ensure no regressions in prior behavior.

## Spec + Code Links

*   State spec pack: [/specs/pricing-awareness-market-data](https://deploy-preview-472--lucky-concha-f3599f.netlify.app/specs/pricing-awareness-market-data.md)
*   Learning guide: [/docs/learning/state-008-pricing-awareness-market-data](https://deploy-preview-472--lucky-concha-f3599f.netlify.app/docs/learning/state-008-pricing-awareness-market-data.md)
*   Generated code branch: [code/generated-state-008-pricing-awareness-market-data](https://github.com/finos/traderX/tree/code/generated-state-008-pricing-awareness-market-data)
*   Compare vs parent (`007`): [code/generated-state-007-observability-lgtm-compose...code/generated-state-008-pricing-awareness-market-data](https://github.com/finos/traderX/compare/code%2Fgenerated-state-007-observability-lgtm-compose...code%2Fgenerated-state-008-pricing-awareness-market-data)
