Skip to content

Feature Proposal #52

@phbrgnomo

Description

@phbrgnomo

Hi, Brazilian Here.

First of all, great work on this project. Been looking for a tool to help me control my wheel strategy and found this one. Already started using it.

But i saw that the only integration to pull live prices is with Polygon.io, wich doesn't have information about Brazilian prices.

Here is my proposal:

Decouple the Polygon Integration to allow new price providers to be added in a modular way, allowing the use of different price providers.

First i am thinking about integrating Yahoo Finance API, so i could at least pull the stock prices (no options prices, but it is at least 50% of the manual work solved).

But the new architecture should make it easier to add more data providers over time.

I am not a professional dev, and my code knowledge is limited to python and MQL5, so here is some initial ideas i came up talking with Claude:

Phase 1 - Generic Refactor

Current state:

┌─────────────┐
│ Web Layer   │
│  (handlers) │
└──────┬──────┘
       │ directly depends on
       ▼
┌─────────────────┐
│ Polygon Service │
│ (polygon pkg)   │
└──────┬──────────┘
       │ directly depends on
       ▼
┌─────────────────┐
│ Polygon Client  │
│ (HTTP calls)    │
└─────────────────┘

Problem:

Web layer tightly coupled to Polygon.io
No abstraction for "price provider" concept
Adding new provider requires changing web layer code
Polygon-specific logic mixed with generic price-fetching logic

Proposed State:

Introduce abstraction layer that decouples providers from consumers

┌─────────────────────────────────────────┐
│          Web Layer (handlers)           │
└──────────────────┬──────────────────────┘
                   │ depends on
                   ▼
        ┌──────────────────────┐
        │  Price Service       │
        │  (Orchestrator)      │
        └──────────┬───────────┘
                   │ depends on
        ┌──────────┴───────────┐
        │ abstract interface   │
        │ (PriceProvider)      │
        │                      │
        ├──────┬──────┬────────┤
        │      │      │        │
        ▼      ▼      ▼        ▼
    [Polygon] [Yahoo] [IEX] [Others]

Key Conceptual Changes in Phase 1

  1. Provider Interface Abstraction
    Create generic contract that all price sources must follow
    Contract defines: GetQuote, GetQuotes, Name, IsHealthy
    Any implementation must provide these methods
    Enables treating different providers interchangeably
  2. Standardized Data Transfer
    Define universal data structure for "a price quote"
    Contains: symbol, price, previous close, change, timestamp, currency, exchange code
    Providers transform their native responses INTO this structure
    Web layer always receives same format regardless of source
  3. Service Layer Introduction
    Create orchestrator (PriceService) that manages multiple providers
    Service responsible for: provider registration, selection, fallback logic
    Service decouples "which provider to use" from "how to use it"
    Web layer talks to service, not individual providers
  4. Dependency Inversion
    Web layer depends on abstractions (interface), not concrete implementations
    Services depend on abstractions
    Concrete providers (Polygon) depend on abstractions
    Easy to swap implementations without changing layers above
  5. Single Responsibility Shift
    Polygon package: Remains focused on Polygon.io API protocol
    New Polygon adapter: Adapts Polygon to generic interface
    Price service: Responsible for multi-provider orchestration
    Each component has one reason to change

Layers:

  1. Data Transfer Layer (New)
  • Standardized types that flow through system
  • No business logic
  • Same contract everywhere
  1. Provider Interface Layer (New)
  • Defines contract all providers implement
  • Single method signatures
  • No implementation details
  1. Orchestration Layer (New)
  • PriceService manages multiple providers
  • Handles provider lifecycle
  • Implements fallback strategy
  • Health monitoring
  1. Adapter Layer (New)
  • Polygon adapter implements provider interface
  • Transforms Polygon-specific responses to standard types
  • Keeps Polygon package isolated
  1. Web Layer (Modified)
  • Depends on PriceService instead of polygon.Service
  • Handlers unaware of provider selection
  • Cleaner separation of concerns

Data Flow Changes

Before:

User Request 
  → Handler 
  → polygonService.UpdatePrice()
  → polygonClient.GetPreviousClose()
  → Polygon API
  → Parse Polygon response
  → Update DB

After:

User Request 
  → Handler 
  → priceService.UpdatePrice()
    → Get price from registered provider
    → Transform to QuoteData
    → Update DB
  → Same code works with Polygon, Yahoo, or any provider

If i get some free time i will try to implement this, but the idea is here if anyone want to work on it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions