Trader Bot: Implement API abstraction layer to make bot independent of Tinkoff API#264
Open
konard wants to merge 3 commits into
Open
Trader Bot: Implement API abstraction layer to make bot independent of Tinkoff API#264konard wants to merge 3 commits into
konard wants to merge 3 commits into
Conversation
Adding CLAUDE.md with task information for AI processing. This file will be removed when the task is complete. Issue: #230
This implementation introduces a comprehensive abstraction layer that decouples the trading bot from the Tinkoff API, addressing the issue of API instability. Key Changes: - Created ITradingApiProvider interface to abstract all trading operations - Implemented TinkoffApiProvider as a wrapper around Tinkoff InvestApi - Added MockApiProvider for testing without real API calls - Introduced configuration-based provider selection - Created interfaces for all trading data structures (IAccount, IInstrument, IOrder, etc.) - Used custom enums to avoid namespace conflicts with provider APIs - Refactored TradingService to use the abstraction layer Benefits: - Reduced dependency risk - no longer tied to single API provider - Easy testing with mock provider - Provider flexibility via configuration - Future-proof architecture for adding new trading APIs - API instability isolation to specific provider implementations Files added: - Interfaces/ - Complete abstraction layer interfaces - Providers/TinkoffApiProvider.cs - Tinkoff implementation - Providers/Tinkoff/ - Tinkoff-specific wrapper classes - Providers/MockApiProvider.cs - Mock implementation for testing - AbstractTradingService.cs - Refactored service using abstraction - Configuration files and examples 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🎯 Objective
Implements a comprehensive API abstraction layer to make the Trader Bot independent of the Tinkoff API, addressing the issue of API instability mentioned in #230.
🔧 Solution Overview
This implementation introduces a complete abstraction layer that decouples the trading bot from any specific API provider, making it resilient to API instability and easily extensible to support multiple trading platforms.
Key Components
1. API Abstraction Layer
ITradingApiProvider: Main interface abstracting all trading operationsIAccount,IInstrument,IOrder,IOrderBook,ITrades, etc.TradingOrderDirection,TradingInstrumentType, etc. to avoid namespace conflicts2. Provider Implementations
TinkoffApiProvider: Complete wrapper around Tinkoff InvestApiMockApiProvider: Mock implementation for testing without real API calls3. Configuration-Based Provider Selection
{ "ApiProviderSettings": { "Provider": "Tinkoff" // or "Mock" } }📁 Files Added
Core Abstraction
Interfaces/ITradingApiProvider.cs- Main provider interfaceInterfaces/IAccount.cs,IInstrument.cs,IOrder.cs, etc. - Data structure interfacesApiProviderSettings.cs- Provider configurationTinkoff Implementation
Providers/TinkoffApiProvider.cs- Main Tinkoff providerProviders/Tinkoff/TinkoffAccount.cs- Account wrapperProviders/Tinkoff/TinkoffOrder.cs- Order management wrapperProviders/Tinkoff/TinkoffOrderBook.cs- Market data wrapperProviders/Tinkoff/TinkoffTrades.cs- Trade execution wrapperProviders/Tinkoff/TinkoffPosition.cs- Portfolio management wrapperProviders/Tinkoff/TinkoffOperation.cs- Operations wrapperProviders/Tinkoff/TinkoffInstrument.cs- Instrument wrapperMock Implementation
Providers/MockApiProvider.cs- Complete mock implementationRefactored Service
AbstractTradingService.cs- Refactored service using abstraction layerProgram.cs- Updated dependency injection configurationConfiguration Examples
appsettings.example.json- Tinkoff provider configurationappsettings.mock.json- Mock provider configurationDocumentation
examples/README.md- Comprehensive usage documentation🚀 Benefits
📋 Usage Examples
Using Tinkoff Provider (Default)
{ "ApiProviderSettings": { "Provider": "Tinkoff" }, "InvestApiSettings": { "AccessToken": "your_tinkoff_token_here", "AppName": "LinksPlatformScalper" } }Using Mock Provider (Testing)
{ "ApiProviderSettings": { "Provider": "Mock" } }🔄 Adding New Providers
To add support for a new trading API:
ITradingApiProvider🎛️ Architecture
✅ Testing Status
🔧 Next Steps
This implementation successfully addresses issue #230 by making the bot truly independent of any single API provider, providing resilience against API instability while maintaining full functionality.
🤖 Generated with Claude Code
Resolves #230