Skip to content

jimbokl/FinStreamKit

Repository files navigation

FinStreamKit

FinStreamKit is a deliberately small, dependency-free Swift package that demonstrates production-oriented patterns for a real-time financial iOS feature:

  • strict Swift 6 concurrency;
  • actor-owned market state;
  • AsyncStream quote subscriptions with cancellation cleanup;
  • sequence-aware ingestion that rejects stale updates;
  • deterministic order-risk decisions using integer price units;
  • idempotency-aware order requests;
  • atomic local snapshots;
  • XCTest coverage and GitHub Actions CI.

It is a portfolio sample, not a trading product and not financial advice.

Why this sample exists

The interesting part of a trading screen is not drawing a green or red number. It is preserving explicit state and safety under duplicated events, out-of-order updates, reconnects, cancellation and stale prices.

FinStreamKit keeps those concerns outside the UI:

transport events
    -> QuoteBook actor
    -> sequence/freshness rules
    -> immutable MarketQuote snapshots
    -> OrderRiskPolicy
    -> explicit approved/rejected decision
    -> @MainActor presentation model

Build and test

xcrun swift-format lint --recursive --configuration .swift-format Sources Tests Package.swift
xcrun swift test --parallel
xcrun swift build -c release

The package supports iOS 17+ and macOS 14+, has no third-party dependencies and currently contains 13 XCTest cases.

Core types

QuoteBook

An actor that owns the latest quote per symbol. It rejects out-of-order sequence numbers and exposes cancellation-aware AsyncStream subscriptions buffered to the newest value.

OrderRiskPolicy

A pure, deterministic validator. It checks quote freshness, spread, quantity, notional limits and optional limit-price deviation. Prices use scaled integers rather than floating point.

SnapshotStore

An actor that encodes Codable & Sendable values and writes them atomically to a caller-provided directory.

TradingDashboardModel

A @MainActor observable model showing how an iOS screen can consume the quote stream while cancellation remains tied to view-model lifecycle.

Design choices

  • No global singleton: dependencies are explicit.
  • No floating-point money: ScaledPrice stores integer micros.
  • No fake transaction result: this package validates requests but never infers execution success from connectivity.
  • No unstructured background work: subscriptions use structured tasks and cooperative cancellation.
  • No hidden persistence location: the caller supplies the snapshot directory.

See docs/architecture.md for failure modes and extension points. See VERIFICATION.md for the latest local QA record.

Public-repository checklist

Before publishing:

  1. Create a new public repository named FinStreamKit.
  2. Push this directory as its root.
  3. Enable branch protection and require the swift-test check.
  4. Add the repository to LinkedIn Featured after CI is green.

Exact repository metadata and the safe publication sequence are in PUBLISHING.md.

About

Production-oriented Swift 6 concurrency and risk-control patterns for a real-time financial iOS feature.

Topics

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages