|
1 | 1 | # Implementation Plan |
2 | 2 |
|
3 | | -- [ ] 1. Set up core infrastructure and state management |
| 3 | +- [x] 1. Set up core infrastructure and state management |
| 4 | + |
4 | 5 | - Create state management system for tracking spread creation sessions |
5 | 6 | - Implement session storage with automatic cleanup |
6 | 7 | - Add basic command handler structure for `/addspread` |
7 | 8 | - _Requirements: 1.1, 1.2_ |
8 | 9 |
|
9 | | -- [ ] 1.1 Create spread state management module |
| 10 | +- [x] 1.1 Create spread state management module |
| 11 | + |
10 | 12 | - Write tests for SpreadCreationState class and state management functions |
11 | 13 | - Write `bot/spread_state.py` with SpreadCreationState class |
12 | 14 | - Implement in-memory state storage with user_id as key |
13 | 15 | - Add state persistence methods: save_state, get_state, clear_state, update_state |
14 | 16 | - _Requirements: 1.1, 1.2_ |
15 | 17 |
|
16 | | -- [ ] 1.2 Create basic command handler for addspread |
| 18 | +- [x] 1.2 Create basic command handler for addspread |
| 19 | + |
17 | 20 | - Write tests for command parsing and initial validation logic |
18 | 21 | - Add `/addspread` command to ROUTINES in `bot/commands.py` |
19 | 22 | - Create `bot/spread_creator.py` with handle_addspread_command function |
20 | 23 | - Implement ticker parsing and validation from command arguments |
21 | 24 | - _Requirements: 1.1, 1.4_ |
22 | 25 |
|
23 | 26 | - [ ] 2. Implement ticker validation and API integration |
| 27 | + |
24 | 28 | - Create API integration module for ticker validation |
25 | 29 | - Add price fetching functionality using existing Tinkoff integration |
26 | 30 | - Implement duplicate spread detection |
27 | 31 | - _Requirements: 1.2, 1.3, 7.5_ |
28 | 32 |
|
29 | 33 | - [ ] 2.1 Create API integration module for spread creation |
| 34 | + |
30 | 35 | - Write tests for ticker validation and price fetching functions |
31 | 36 | - Write `bot/spread_api.py` with ticker validation functions |
32 | 37 | - Implement validate_ticker function using existing ticker endpoint |
33 | 38 | - Add get_current_prices function using existing price fetching logic |
34 | 39 | - _Requirements: 1.2, 1.3_ |
35 | 40 |
|
36 | 41 | - [ ] 2.2 Add spread creation API endpoint integration |
| 42 | + |
37 | 43 | - Write tests for spread creation and duplicate detection functions |
38 | 44 | - Implement create_spread function to POST to Django spreads endpoint |
39 | 45 | - Add check_duplicate_spread function to detect existing spreads |
40 | 46 | - Handle API errors and connection issues gracefully |
41 | 47 | - _Requirements: 6.1, 6.2, 7.4_ |
42 | 48 |
|
43 | 49 | - [ ] 3. Implement market-neutral price calculation logic |
| 50 | + |
44 | 51 | - Create price calculator module with ratio calculation |
45 | 52 | - Implement spread price calculations for different asset type combinations |
46 | 53 | - Add market-neutral explanation generation |
47 | 54 | - _Requirements: 2.1, 2.2, 2.3_ |
48 | 55 |
|
49 | 56 | - [ ] 3.1 Create spread pricing calculation module |
| 57 | + |
50 | 58 | - Write tests for spread price calculations and ratio calculations for different asset combinations |
51 | 59 | - Write `bot/spread_pricing.py` with calculate_spread_price function |
52 | 60 | - Implement calculate_ratio function for stock-future and future-future pairs |
53 | 61 | - Add get_market_neutral_explanation function for user display |
54 | 62 | - _Requirements: 2.1, 2.2, 2.3_ |
55 | 63 |
|
56 | 64 | - [ ] 3.2 Integrate price calculations with existing Tinkoff API |
| 65 | + |
57 | 66 | - Write tests for price integration and error handling scenarios |
58 | 67 | - Use existing get_current_prices_by_uid function for market data |
59 | 68 | - Implement bid/ask price fetching for spread calculations |
60 | 69 | - Add price unavailable handling and fallback logic |
61 | 70 | - _Requirements: 2.5, 2.6_ |
62 | 71 |
|
63 | 72 | - [ ] 4. Create interactive menu system with inline keyboards |
| 73 | + |
64 | 74 | - Implement inline keyboard generators for each step |
65 | 75 | - Create callback query handlers for menu interactions |
66 | 76 | - Add menu navigation and state transitions |
67 | 77 | - _Requirements: 2.4, 3.1, 4.1, 5.1_ |
68 | 78 |
|
69 | 79 | - [ ] 4.1 Create inline keyboard menu generators |
| 80 | + |
| 81 | + - Write tests for menu generation functions and keyboard layouts |
70 | 82 | - Write `bot/spread_menu.py` with menu generation functions |
71 | 83 | - Implement generate_direction_menu for buy/sell selection |
72 | 84 | - Add generate_price_menu and generate_amount_menu functions |
73 | 85 | - Create generate_confirmation_menu for final review |
74 | 86 | - _Requirements: 2.4, 3.1, 4.1, 5.1_ |
75 | 87 |
|
76 | 88 | - [ ] 4.2 Implement callback query handlers |
| 89 | + |
| 90 | + - Write tests for callback handling and state transitions |
77 | 91 | - Add callback query handler to `bot/spread_creator.py` |
78 | 92 | - Implement state transitions based on user selections |
79 | 93 | - Add input validation for custom price and amount entries |
80 | 94 | - Handle menu navigation (back, cancel) functionality |
81 | 95 | - _Requirements: 3.2, 3.4, 4.2, 4.4, 5.4_ |
82 | 96 |
|
83 | 97 | - [ ] 5. Add comprehensive input validation and error handling |
| 98 | + |
84 | 99 | - Implement validation for all user inputs (price, amount, tickers) |
85 | 100 | - Add error message generation and user feedback |
86 | 101 | - Create session timeout and cleanup mechanisms |
87 | 102 | - _Requirements: 3.4, 4.4, 7.1, 7.3_ |
88 | 103 |
|
89 | 104 | - [ ] 5.1 Implement input validation functions |
| 105 | + |
| 106 | + - Write tests for all validation functions with edge cases and error scenarios |
90 | 107 | - Add price validation (valid integer, reasonable range) |
91 | 108 | - Implement amount validation (positive integer, minimum lot requirements) |
92 | 109 | - Create ticker format validation and existence checking |
93 | 110 | - _Requirements: 3.2, 3.4, 4.2, 4.4_ |
94 | 111 |
|
95 | 112 | - [ ] 5.2 Add comprehensive error handling and user feedback |
| 113 | + |
| 114 | + - Write tests for error handling scenarios and message generation |
96 | 115 | - Implement error message generation for all validation failures |
97 | 116 | - Add graceful handling of API connection errors |
98 | 117 | - Create user-friendly error messages with suggested corrections |
99 | 118 | - _Requirements: 7.1, 7.3, 7.4_ |
100 | 119 |
|
101 | 120 | - [ ] 6. Integrate spread creation with Django backend |
| 121 | + |
102 | 122 | - Connect menu system to Django API for spread persistence |
103 | 123 | - Implement SpreadStats creation and association |
104 | 124 | - Add success confirmation and spread activation |
105 | 125 | - _Requirements: 5.5, 6.1, 6.2, 6.3_ |
106 | 126 |
|
107 | 127 | - [ ] 6.1 Implement Django API integration for spread creation |
| 128 | + |
| 129 | + - Write tests for spread creation payload generation and API integration |
108 | 130 | - Create spread creation payload from menu state |
109 | 131 | - POST spread data to Django spreads endpoint |
110 | 132 | - Handle SpreadStats creation automatically in Django |
111 | 133 | - _Requirements: 5.5, 6.1, 6.2_ |
112 | 134 |
|
113 | 135 | - [ ] 6.2 Add spread activation and confirmation |
| 136 | + |
| 137 | + - Write tests for spread activation and confirmation flow |
114 | 138 | - Set active=True by default for new spreads |
115 | 139 | - Return spread ID and confirmation to user |
116 | 140 | - Clear session state after successful creation |
117 | 141 | - _Requirements: 6.3, 6.4, 5.6_ |
118 | 142 |
|
119 | 143 | - [ ] 7. Add logging, monitoring and session cleanup |
| 144 | + |
120 | 145 | - Implement comprehensive logging for all operations |
121 | 146 | - Add session timeout and automatic cleanup |
122 | 147 | - Create monitoring for spread creation activity |
123 | 148 | - _Requirements: 7.1, 7.2, 7.3_ |
124 | 149 |
|
125 | 150 | - [ ] 7.1 Add comprehensive logging system |
| 151 | + |
| 152 | + - Write tests for logging functionality and log message formats |
126 | 153 | - Log all spread creation attempts with user and parameters |
127 | 154 | - Add error logging with full context for troubleshooting |
128 | 155 | - Implement success logging with spread details |
129 | 156 | - _Requirements: 7.1, 7.2, 7.3_ |
130 | 157 |
|
131 | | -- [ ]* 7.2 Create session cleanup and monitoring |
| 158 | +- [ ] 7.2 Create session cleanup and monitoring |
| 159 | + |
| 160 | + - Write tests for session timeout and cleanup functionality |
132 | 161 | - Implement automatic session timeout (30 minutes) |
133 | 162 | - Add periodic cleanup of stale sessions |
134 | 163 | - Create monitoring dashboard for spread creation metrics |
135 | 164 | - _Requirements: 7.1, 7.3_ |
136 | 165 |
|
137 | 166 | - [ ] 8. Integration testing and final wiring |
| 167 | + |
138 | 168 | - Connect all modules and test complete user flow |
139 | 169 | - Add the addspread command to bot command routing |
140 | 170 | - Verify integration with existing spreads trading functionality |
141 | 171 | - _Requirements: 6.5_ |
142 | 172 |
|
143 | 173 | - [ ] 8.1 Wire up complete spread creation flow |
| 174 | + |
| 175 | + - Write integration tests for complete user journey from command to spread creation |
144 | 176 | - Register addspread command handler in bot dispatcher |
145 | 177 | - Connect all modules: state management, API integration, menus, pricing |
146 | 178 | - Test complete user journey from command to spread creation |
147 | 179 | - _Requirements: 6.5_ |
148 | 180 |
|
149 | 181 | - [ ] 8.2 Verify integration with existing spread trading system |
| 182 | + - Write integration tests for spread trading system compatibility |
150 | 183 | - Ensure newly created spreads appear in spreads command |
151 | 184 | - Test that created spreads are properly formatted for trading logic |
152 | 185 | - Verify SpreadStats integration works with existing patch operations |
153 | | - - _Requirements: 6.4, 6.5_ |
| 186 | + - _Requirements: 6.4, 6.5_ |
0 commit comments