Skip to content

feat(options): add direction support for long/short positions and analytics - #59

Open
phbrgnomo wants to merge 31 commits into
MarkT1065:mainfrom
phbrgnomo:long_options
Open

phbrgnomo wants to merge 31 commits into
MarkT1065:mainfrom
phbrgnomo:long_options

Conversation

@phbrgnomo

@phbrgnomo phbrgnomo commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

OVERVIEW
Introduces a direction field for options to distinguish short and long positions across the data model, database, APIs, and UI.
Updates option creation, update, closing, and retrieval logic to validate and persist direction, defaulting to Short where unspecified for backward compatibility.
Adjusts analytics, metrics, charts, and summaries to treat short vs long options correctly for exposure, premiums, and profit calculations, including new summary fields for short/long counts and credits/debits.
Enhances templates and client-side scripts to display and edit option direction, refine performance metrics visibility, and improve tooltip and table summaries.
Extends migration tests and provider integration tests to cover the new direction column, index, defaults, and long option handling.

sequenceDiagram
actor User
participant Browser
participant Server
participant OptionService
participant Database

User->>Browser: submit createOption (symbol, type, direction)
Browser->>Server: POST /api/options (OptionRequest)
Server->>OptionService: CreateWithCommissionAndDirection(symbol, type, direction, opened, strike, expiration, premium, contracts, commission)
OptionService->>Database: INSERT INTO options(symbol, type, direction, ...)
Database-->>OptionService: created row with direction
OptionService-->>Server: Option (Direction)
Server-->>Browser: JSON response (includes direction)

erDiagram

options {
int id
string symbol
string type
string direction
float premium
}

OptionSummary {
string symbol
int total_positions
int short_positions
int long_positions
float total_premium
float short_credit
float long_debit
}

options ||--o{ OptionSummary : aggregated_by_symbol

Solves #22

phbr and others added 30 commits February 13, 2026 17:55
Introduces a provider abstraction layer to support multiple market data sources.

**Changes:**
- Created `internal/providers/` package with Provider interface
- Implemented PolygonProvider wrapping existing Polygon.io client
- Created providers.Service to manage provider lifecycle
- Updated Server to use providerService instead of polygonService
- Renamed polygonService to providerService throughout handlers

**Benefits:**
- Enables support for multiple data providers
- Maintains backward compatibility with existing Polygon.io integration
- Provides clear interface for adding new providers (e.g., Alpha Vantage)
- Standardizes error handling and response types

**Files Added:**
- internal/providers/provider.go (interface definition)
- internal/providers/polygon.go (Polygon.io implementation)
- internal/providers/service.go (provider service layer)
- internal/providers/provider_test.go (unit tests)
- internal/providers/README.md (documentation)

**Files Modified:**
- internal/web/server.go
- internal/web/polygon_handlers.go
- internal/web/symbol_handlers.go

No breaking changes - all existing functionality preserved.
…d improve error handling in API connection tests
… provider structure and enhance error handling
Refactor web utilities and enhance UI components
…o a criação do usuário não privilegiado.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant