PaperTrade-India 0.1.0.dev0__tar.gz → 0.1.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (197) hide show
  1. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/CHANGELOG.md +133 -0
  2. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/PKG-INFO +41 -7
  3. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/README.md +39 -5
  4. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/docs/ARCHITECTURE.md +23 -9
  5. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/docs/FEES.md +7 -1
  6. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/examples/01_basic_usage.py +10 -1
  7. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/examples/03_backtest_example.py +6 -0
  8. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/examples/07_backtest_replay.py +6 -0
  9. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/pyproject.toml +1 -1
  10. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/src/papertrade_india/__init__.py +7 -1
  11. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/src/papertrade_india/broker.py +53 -15
  12. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/src/papertrade_india/cli.py +6 -1
  13. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/src/papertrade_india/corporate_actions/bonus.py +17 -0
  14. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/src/papertrade_india/corporate_actions/dividends.py +5 -0
  15. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/src/papertrade_india/corporate_actions/rights.py +5 -0
  16. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/src/papertrade_india/corporate_actions/splits.py +20 -0
  17. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/src/papertrade_india/corporate_actions/store.py +28 -0
  18. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/src/papertrade_india/domain/exceptions.py +68 -1
  19. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/src/papertrade_india/domain/models.py +80 -5
  20. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/src/papertrade_india/domain/rules/risk.py +53 -10
  21. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/src/papertrade_india/execution/book.py +43 -5
  22. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/src/papertrade_india/execution/fees.py +27 -8
  23. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/src/papertrade_india/execution/settlement.py +44 -3
  24. papertrade_india-0.1.1/src/papertrade_india/infrastructure/idempotency.py +266 -0
  25. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/src/papertrade_india/infrastructure/market_hours.py +69 -5
  26. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/src/papertrade_india/infrastructure/migrations.py +341 -18
  27. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/src/papertrade_india/infrastructure/symbols.py +15 -1
  28. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/src/papertrade_india/orders/amo.py +33 -3
  29. papertrade_india-0.1.1/src/papertrade_india/orders/book_helpers.py +434 -0
  30. papertrade_india-0.1.1/src/papertrade_india/orders/bracket.py +199 -0
  31. papertrade_india-0.1.1/src/papertrade_india/orders/limit.py +477 -0
  32. papertrade_india-0.1.1/src/papertrade_india/orders/market.py +537 -0
  33. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/src/papertrade_india/orders/preopen.py +149 -25
  34. papertrade_india-0.1.1/src/papertrade_india/orders/state.py +1632 -0
  35. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/src/papertrade_india/orders/stop.py +70 -12
  36. papertrade_india-0.1.1/src/papertrade_india/orders/submit.py +520 -0
  37. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/src/papertrade_india/price_feed.py +76 -13
  38. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/src/papertrade_india/providers/alphavantage.py +12 -2
  39. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/src/papertrade_india/providers/base.py +15 -0
  40. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/src/papertrade_india/providers/cache.py +38 -13
  41. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/src/papertrade_india/providers/composite.py +99 -28
  42. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/src/papertrade_india/providers/dhan.py +42 -2
  43. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/src/papertrade_india/providers/finnhub.py +5 -2
  44. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/src/papertrade_india/providers/health.py +28 -8
  45. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/src/papertrade_india/providers/jugaad.py +6 -1
  46. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/src/papertrade_india/providers/kite.py +28 -1
  47. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/src/papertrade_india/providers/nse_bhavcopy.py +45 -6
  48. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/src/papertrade_india/providers/nsepython.py +4 -1
  49. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/src/papertrade_india/providers/stooq.py +17 -3
  50. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/src/papertrade_india/providers/twelvedata.py +8 -3
  51. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/src/papertrade_india/providers/upstox.py +43 -6
  52. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/src/papertrade_india/providers/upstox_instruments.py +90 -17
  53. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/src/papertrade_india/providers/yfinance.py +17 -4
  54. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/src/papertrade_india/reads/positions.py +12 -2
  55. papertrade_india-0.1.1/src/papertrade_india/workers/limit_orders.py +495 -0
  56. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/tests/integration/test_broker_invariants.py +14 -0
  57. papertrade_india-0.1.1/tests/integration/test_bse_routing.py +135 -0
  58. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/tests/integration/test_concurrent_access.py +81 -5
  59. papertrade_india-0.1.1/tests/integration/test_corporate_actions.py +532 -0
  60. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/tests/integration/test_events_and_observability.py +6 -1
  61. papertrade_india-0.1.1/tests/integration/test_idempotency.py +354 -0
  62. papertrade_india-0.1.1/tests/integration/test_migrations.py +924 -0
  63. papertrade_india-0.1.1/tests/integration/test_partial_fills_integration.py +296 -0
  64. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/tests/integration/test_quickstart_and_breakdown.py +2 -1
  65. papertrade_india-0.1.1/tests/integration/test_real_depth_fill.py +164 -0
  66. papertrade_india-0.1.1/tests/integration/test_realism_amo_gtt_preopen.py +782 -0
  67. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/tests/integration/test_realism_bonus_rights.py +32 -0
  68. papertrade_india-0.1.1/tests/integration/test_realism_microstructure.py +706 -0
  69. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/tests/integration/test_realism_misc.py +59 -3
  70. papertrade_india-0.1.1/tests/integration/test_realism_settlement.py +1220 -0
  71. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/tests/integration/test_realism_stops_and_brackets.py +146 -0
  72. papertrade_india-0.1.1/tests/integration/test_stale_price_reject.py +269 -0
  73. papertrade_india-0.1.1/tests/integration/test_symbol_lookup_normalization.py +129 -0
  74. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/tests/integration/test_symbols.py +60 -0
  75. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/tests/unit/test_fees.py +14 -0
  76. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/tests/unit/test_holidays.py +51 -0
  77. papertrade_india-0.1.1/tests/unit/test_price_feed.py +268 -0
  78. papertrade_india-0.1.1/tests/unit/test_provider_venue_and_history.py +145 -0
  79. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/tests/unit/test_providers_broker_feed.py +141 -0
  80. papertrade_india-0.1.1/tests/unit/test_providers_composite.py +275 -0
  81. papertrade_india-0.1.1/tests/unit/test_providers_health.py +238 -0
  82. papertrade_india-0.1.1/tests/unit/test_providers_rest.py +733 -0
  83. papertrade_india-0.1.1/tests/unit/test_risk.py +506 -0
  84. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/tests/unit/test_session_phase.py +35 -0
  85. papertrade_india-0.1.1/tests/unit/test_upstox_instruments.py +297 -0
  86. papertrade_india-0.1.0.dev0/src/papertrade_india/infrastructure/idempotency.py +0 -133
  87. papertrade_india-0.1.0.dev0/src/papertrade_india/orders/book_helpers.py +0 -111
  88. papertrade_india-0.1.0.dev0/src/papertrade_india/orders/bracket.py +0 -115
  89. papertrade_india-0.1.0.dev0/src/papertrade_india/orders/limit.py +0 -210
  90. papertrade_india-0.1.0.dev0/src/papertrade_india/orders/market.py +0 -264
  91. papertrade_india-0.1.0.dev0/src/papertrade_india/orders/state.py +0 -640
  92. papertrade_india-0.1.0.dev0/src/papertrade_india/orders/submit.py +0 -385
  93. papertrade_india-0.1.0.dev0/src/papertrade_india/workers/limit_orders.py +0 -390
  94. papertrade_india-0.1.0.dev0/tests/integration/test_corporate_actions.py +0 -158
  95. papertrade_india-0.1.0.dev0/tests/integration/test_idempotency.py +0 -141
  96. papertrade_india-0.1.0.dev0/tests/integration/test_migrations.py +0 -295
  97. papertrade_india-0.1.0.dev0/tests/integration/test_partial_fills_integration.py +0 -160
  98. papertrade_india-0.1.0.dev0/tests/integration/test_real_depth_fill.py +0 -79
  99. papertrade_india-0.1.0.dev0/tests/integration/test_realism_amo_gtt_preopen.py +0 -213
  100. papertrade_india-0.1.0.dev0/tests/integration/test_realism_microstructure.py +0 -160
  101. papertrade_india-0.1.0.dev0/tests/integration/test_realism_settlement.py +0 -150
  102. papertrade_india-0.1.0.dev0/tests/integration/test_stale_price_reject.py +0 -130
  103. papertrade_india-0.1.0.dev0/tests/unit/test_price_feed.py +0 -102
  104. papertrade_india-0.1.0.dev0/tests/unit/test_providers_composite.py +0 -149
  105. papertrade_india-0.1.0.dev0/tests/unit/test_providers_health.py +0 -126
  106. papertrade_india-0.1.0.dev0/tests/unit/test_providers_rest.py +0 -295
  107. papertrade_india-0.1.0.dev0/tests/unit/test_risk.py +0 -207
  108. papertrade_india-0.1.0.dev0/tests/unit/test_upstox_instruments.py +0 -95
  109. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/.gitignore +0 -0
  110. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/LICENSE +0 -0
  111. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/docs/COOKBOOK.md +0 -0
  112. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/examples/02_with_ai_agent.py +0 -0
  113. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/examples/04_multi_account.py +0 -0
  114. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/examples/05_mcp_server.py +0 -0
  115. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/examples/06_tier3_observability.py +0 -0
  116. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/examples/08_data_providers.py +0 -0
  117. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/examples/09_realism_features.py +0 -0
  118. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/src/papertrade_india/_context.py +0 -0
  119. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/src/papertrade_india/clock.py +0 -0
  120. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/src/papertrade_india/corporate_actions/__init__.py +0 -0
  121. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/src/papertrade_india/data/nse_holidays_2026.json +0 -0
  122. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/src/papertrade_india/data/nse_holidays_2027.json +0 -0
  123. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/src/papertrade_india/data/nse_universe_sample.csv +0 -0
  124. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/src/papertrade_india/domain/__init__.py +0 -0
  125. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/src/papertrade_india/domain/rules/__init__.py +0 -0
  126. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/src/papertrade_india/domain/rules/tick_lot_band.py +0 -0
  127. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/src/papertrade_india/events.py +0 -0
  128. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/src/papertrade_india/exceptions.py +0 -0
  129. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/src/papertrade_india/execution/__init__.py +0 -0
  130. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/src/papertrade_india/execution/simulation.py +0 -0
  131. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/src/papertrade_india/execution/slippage.py +0 -0
  132. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/src/papertrade_india/fees.py +0 -0
  133. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/src/papertrade_india/idempotency.py +0 -0
  134. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/src/papertrade_india/infrastructure/__init__.py +0 -0
  135. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/src/papertrade_india/infrastructure/clock.py +0 -0
  136. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/src/papertrade_india/infrastructure/events.py +0 -0
  137. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/src/papertrade_india/infrastructure/holidays.py +0 -0
  138. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/src/papertrade_india/infrastructure/ledger.py +0 -0
  139. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/src/papertrade_india/infrastructure/observability.py +0 -0
  140. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/src/papertrade_india/infrastructure/persistence.py +0 -0
  141. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/src/papertrade_india/infrastructure/watchlist.py +0 -0
  142. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/src/papertrade_india/interface.py +0 -0
  143. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/src/papertrade_india/ledger.py +0 -0
  144. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/src/papertrade_india/limit_orders.py +0 -0
  145. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/src/papertrade_india/market_hours.py +0 -0
  146. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/src/papertrade_india/microstructure.py +0 -0
  147. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/src/papertrade_india/migrations.py +0 -0
  148. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/src/papertrade_india/models.py +0 -0
  149. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/src/papertrade_india/observability.py +0 -0
  150. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/src/papertrade_india/orders/__init__.py +0 -0
  151. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/src/papertrade_india/orders/partial_fills.py +0 -0
  152. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/src/papertrade_india/partial_fills.py +0 -0
  153. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/src/papertrade_india/persistence.py +0 -0
  154. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/src/papertrade_india/preopen.py +0 -0
  155. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/src/papertrade_india/presets.py +0 -0
  156. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/src/papertrade_india/providers/__init__.py +0 -0
  157. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/src/papertrade_india/providers/registry.py +0 -0
  158. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/src/papertrade_india/quickstart.py +0 -0
  159. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/src/papertrade_india/reads/__init__.py +0 -0
  160. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/src/papertrade_india/reads/account.py +0 -0
  161. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/src/papertrade_india/reads/orders.py +0 -0
  162. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/src/papertrade_india/risk.py +0 -0
  163. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/src/papertrade_india/settlement.py +0 -0
  164. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/src/papertrade_india/simulation.py +0 -0
  165. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/src/papertrade_india/slippage.py +0 -0
  166. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/src/papertrade_india/symbols.py +0 -0
  167. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/src/papertrade_india/workers/__init__.py +0 -0
  168. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/tests/__init__.py +0 -0
  169. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/tests/conftest.py +0 -0
  170. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/tests/e2e/__init__.py +0 -0
  171. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/tests/e2e/test_real_yfinance.py +0 -0
  172. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/tests/integration/__init__.py +0 -0
  173. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/tests/integration/test_alpaca_contract.py +0 -0
  174. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/tests/integration/test_cli_tier3.py +0 -0
  175. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/tests/integration/test_full_lifecycle.py +0 -0
  176. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/tests/integration/test_ledger.py +0 -0
  177. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/tests/integration/test_replay_clock.py +0 -0
  178. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/tests/unit/__init__.py +0 -0
  179. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/tests/unit/test_book_real_depth.py +0 -0
  180. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/tests/unit/test_clock.py +0 -0
  181. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/tests/unit/test_fee_schedule.py +0 -0
  182. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/tests/unit/test_fees_properties.py +0 -0
  183. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/tests/unit/test_layering.py +0 -0
  184. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/tests/unit/test_market_hours.py +0 -0
  185. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/tests/unit/test_microstructure.py +0 -0
  186. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/tests/unit/test_partial_fills.py +0 -0
  187. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/tests/unit/test_preopen.py +0 -0
  188. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/tests/unit/test_presets.py +0 -0
  189. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/tests/unit/test_price_feed_new_provider_compat.py +0 -0
  190. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/tests/unit/test_providers_base.py +0 -0
  191. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/tests/unit/test_providers_registry.py +0 -0
  192. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/tests/unit/test_reads_positions.py +0 -0
  193. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/tests/unit/test_resilient_feed.py +0 -0
  194. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/tests/unit/test_settlement.py +0 -0
  195. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/tests/unit/test_simulation.py +0 -0
  196. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/tests/unit/test_slippage.py +0 -0
  197. {papertrade_india-0.1.0.dev0 → papertrade_india-0.1.1}/tests/unit/test_watchlist_store.py +0 -0
@@ -7,6 +7,139 @@ project follows [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
  Pre-1.0 releases may include breaking changes in MINOR bumps; each one will
8
8
  be called out here.
9
9
 
10
+ ## [0.1.1] - 2026-11-28
11
+
12
+ A correctness release with no new features. It adds one data migration
13
+ (schema version 5) that normalizes stored symbols. Back up your SQLite
14
+ database before upgrading: migrations run when the broker opens it.
15
+
16
+ ### Fixed
17
+
18
+ - **Upgrade data loss.** Upgrading a database created by the first schema
19
+ version removed its trades and idempotency keys. The migration runner
20
+ now turns foreign-key enforcement off for the run, checks for
21
+ violations before each commit and restores the setting afterwards. Rows
22
+ already lost by an earlier upgrade cannot be restored.
23
+ - **Idempotent submission.** The key is claimed in the same transaction
24
+ that writes the order. Concurrent requests with one key produce one
25
+ order. The request fingerprint now covers product type, stop price,
26
+ target price and exchange.
27
+ - **Partial fills.** A limit fill reads the order inside its write
28
+ transaction, so overlapping fills no longer lose shares.
29
+ - **Checks at fill time.** Position caps, cash and sellable shares are
30
+ checked again when a queued order fills. An intraday sell cannot use
31
+ unsettled delivery shares, and bracket legs follow the same rule as a
32
+ direct sell.
33
+ - **Market-entry brackets** follow the same session rules as market
34
+ orders.
35
+ - **Price bands and book depth.** The final execution price is checked
36
+ against the daily band on every path. A market order is declined when
37
+ the other side of the book is empty or cannot supply the full quantity.
38
+ - **DAY expiry and cancellation.** A DAY order expires after the close of
39
+ the session it belongs to. Expiry and `cancel_all_orders()` also stop
40
+ the remainder of a partially filled order and keep its fills.
41
+ - **Intraday square-off.** Intraday buys are refused between the cutoff
42
+ and the close. Open intraday exposure is computed from trades, so a
43
+ failed or interrupted square-off is retried and earlier days are
44
+ covered.
45
+ - **Quote checks.** One quote snapshot triggers, prices and sizes a fill,
46
+ and that snapshot is the one checked for freshness and real-time
47
+ status.
48
+ - **Fees.** The DP charge, flat brokerage and the brokerage cap are
49
+ charged once per order, not once per partial fill. Intraday sells pay
50
+ no DP charge.
51
+ - **BSE routing.** A BSE broker uses BSE prices, venue-scoped cache
52
+ entries and a BSE calendar. Upstox no longer accepts an NSE result for
53
+ a BSE request.
54
+ - **Invalid prices.** `NaN`, infinite and non-positive prices fall
55
+ through to the next provider. A seeded close no longer passes
56
+ `enforce_real_time`.
57
+ - **History.** A one-day Yahoo request returns that day's bar. The
58
+ composite provider delegates history to a child that supports it.
59
+ - **Depth.** Kite and Dhan quotes carry the full bid and ask ladder.
60
+ - **Circuit breaker.** A half-open probe with an empty answer closes the
61
+ breaker. The bhavcopy provider raises on transport failures and treats
62
+ only a missing archive as no data.
63
+ - **Upstox instruments.** The in-memory index refreshes after its TTL and
64
+ keeps the last good index when a refresh fails.
65
+ - **Pre-open.** Matched volume counts each crossed share once.
66
+ - **Square-off safety.** Intraday square-off sells only shares bought
67
+ intraday. It recomputes the open balance inside the selling
68
+ transaction, cancels open intraday bracket exit legs, and a bracket
69
+ leg cannot sell more than the open intraday shares. Exposure left from
70
+ an earlier session is closed at the next open. Splits and bonuses are
71
+ applied to the open intraday balance.
72
+ - **Notional cap.** `max_order_notional` is checked at a buy's own stop
73
+ or limit price on submission and again at the fill price.
74
+ - **Locked markets.** Limit orders also wait on a locked side. A side is
75
+ locked when a depth ladder has an empty contra side, or there is no
76
+ ladder and the last price is at the band limit in the order's
77
+ direction. Book levels outside the daily band are never traded.
78
+ - **Synthetic book.** A synthetic book never declines a market order on
79
+ size; the excess is priced at the worst level.
80
+ - **Market-entry brackets** that cannot execute raise what a market
81
+ order would and write nothing.
82
+ - **Pre-open auction.** All legs of a match are written in one
83
+ transaction or none, at the equilibrium price with no slippage.
84
+ - **Corporate actions.** Splits and bonuses rescale unsettled T+1 buys,
85
+ and split events from before a `reset()` no longer affect later
86
+ trades.
87
+ - **Bracket exits.** After a partial manual sell, an exit leg closes the
88
+ shares that remain. It used to be rejected.
89
+ - **Auto square-off off.** With `auto_square_off_enabled=False` the
90
+ watcher never sells intraday shares on its own.
91
+ - **AMO expiry.** An AMO expires when the first session after it was
92
+ placed closes.
93
+ - **Slippage.** With the book simulator on and no bid or ask, a market
94
+ fill uses the configured slippage.
95
+ - **`reset()`** clears settlement rows, idempotency keys and the
96
+ in-memory book queue for the account.
97
+ - **Stored symbols.** Migration 5 rewrites symbols stored before
98
+ normalization and merges rows that collide. Read helpers and
99
+ corporate-action entry points normalize the symbol passed in.
100
+ - **Provider failures.** REST and broker providers raise `ProviderError`
101
+ on malformed or error responses and broken connections, and the
102
+ composite raises when every child failed. A bhavcopy body that is not
103
+ the expected CSV raises and is not cached. A bad Upstox instrument
104
+ download is never written to the disk cache.
105
+ - **Circuit breaker.** The failure-rate rule waits for `min_calls`
106
+ (default 10), so a fresh breaker no longer opens on its first failure.
107
+ - **Symbols.** Symbols are trimmed and upper-cased on submission and in
108
+ the symbol master.
109
+ - `papertrade-india migrate` on an unstamped legacy database no longer
110
+ fails with a nested-transaction error.
111
+
112
+ ### Added
113
+
114
+ - Exceptions `InsufficientLiquidityError`, `IntradayCutoffError` and
115
+ `OrderRejectedAtFill`.
116
+ - `PriceFeed(exchange=...)`, `NSECalendar(exchange=..., holidays=...)`,
117
+ `CompositeProvider.get_history`,
118
+ `UpstoxInstrumentMaster(clock=...)` and
119
+ `CircuitBreakerProvider(min_calls=...)`.
120
+ - A warning when an account has filled orders with no trade rows, which
121
+ is the mark of a database damaged by an earlier upgrade.
122
+
123
+ ### Changed
124
+
125
+ - A queued order that fails an account check at fill time ends as
126
+ `REJECTED`, or `CANCELLED` if part of it had filled. An order with
127
+ insufficient cash used to stay pending.
128
+ - A queued order refused for a stale quote, the price band, liquidity or
129
+ the intraday cutoff stays open and is retried.
130
+ - A market order is declined when real provider depth cannot supply it
131
+ and no synthetic levels are configured, or when its side is locked.
132
+ - Default brokers on a feed with no bid or ask now pay the configured
133
+ slippage (5 bps by default) where they used to fill at the last price.
134
+ - A market-entry bracket that cannot execute raises. It used to return a
135
+ rejected parent order.
136
+ - `CompositeProvider.get_quote` can raise `ProviderError`. `PriceFeed`
137
+ catches it and moves to the next provider.
138
+ - A delivery sell cannot use shares bought intraday on the same day.
139
+ - Without BSE holiday data, a BSE calendar uses the NSE dates.
140
+ - The session rules for DAY expiry and the intraday cutoff apply only
141
+ with `enforce_market_hours=True`.
142
+
10
143
  ## [Unreleased]
11
144
 
12
145
  ### Architecture refactor (internal, no public API changes)
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.4
1
+ Metadata-Version: 2.5
2
2
  Name: PaperTrade-India
3
- Version: 0.1.0.dev0
3
+ Version: 0.1.1
4
4
  Summary: Production-grade simulated broker for NSE/BSE paper trading
5
5
  Project-URL: Homepage, https://github.com/Mirzabaig313/papertrade-india
6
6
  Project-URL: Documentation, https://github.com/Mirzabaig313/papertrade-india#readme
@@ -201,11 +201,45 @@ Runnable scripts are in [`examples/`](examples/).
201
201
 
202
202
  ## Configuration
203
203
 
204
- Provide your own broker credentials and data-provider keys via a `.env`
205
- file — see [`.env.example`](.env.example). Everything is optional: with no
206
- keys set, the broker uses the free `yfinance → jugaad-data` fallback chain
207
- and works out of the box. API keys unlock live broker feeds and
208
- higher-rate data sources.
204
+ Most providers and live broker feeds need an API key or token. Everything
205
+ is optional — with no keys set, the broker uses the free
206
+ `yfinance → jugaad-data` fallback chain and works out of the box. There
207
+ are three ways to supply credentials:
208
+
209
+ **1. Pass them directly to the provider** (most explicit — no env needed):
210
+
211
+ ```python
212
+ from papertrade_india import IndiaPaperBroker, resilient_feed
213
+ from papertrade_india.providers import UpstoxProvider, UpstoxInstrumentMaster
214
+
215
+ feed = resilient_feed([
216
+ UpstoxProvider(access_token="your-token", resolve=UpstoxInstrumentMaster().resolve),
217
+ ])
218
+ broker = IndiaPaperBroker(price_feed=feed)
219
+ ```
220
+
221
+ Every provider accepts its key this way: `FinnhubProvider(api_key=...)`,
222
+ `DhanProvider(client_id=..., access_token=...)`,
223
+ `KiteProvider(api_key=..., access_token=...)`, and so on.
224
+
225
+ **2. Set an environment variable** — every provider falls back to it:
226
+
227
+ ```bash
228
+ export UPSTOX_ACCESS_TOKEN="your-token"
229
+ python your_script.py
230
+ ```
231
+
232
+ The variable names are listed in [`.env.example`](.env.example) (e.g.
233
+ `UPSTOX_ACCESS_TOKEN`, `FINNHUB_API_KEY`, `ALPHA_VANTAGE_API_KEY`,
234
+ `DHAN_CLIENT_ID` / `DHAN_ACCESS_TOKEN`).
235
+
236
+ **3. Use a `.env` file** — the library doesn't read `.env` automatically,
237
+ so load it yourself with [python-dotenv](https://pypi.org/project/python-dotenv/):
238
+
239
+ ```python
240
+ from dotenv import load_dotenv
241
+ load_dotenv() # copy .env.example to .env and fill in your keys
242
+ ```
209
243
 
210
244
  ## Fee model
211
245
 
@@ -132,11 +132,45 @@ Runnable scripts are in [`examples/`](examples/).
132
132
 
133
133
  ## Configuration
134
134
 
135
- Provide your own broker credentials and data-provider keys via a `.env`
136
- file — see [`.env.example`](.env.example). Everything is optional: with no
137
- keys set, the broker uses the free `yfinance → jugaad-data` fallback chain
138
- and works out of the box. API keys unlock live broker feeds and
139
- higher-rate data sources.
135
+ Most providers and live broker feeds need an API key or token. Everything
136
+ is optional — with no keys set, the broker uses the free
137
+ `yfinance → jugaad-data` fallback chain and works out of the box. There
138
+ are three ways to supply credentials:
139
+
140
+ **1. Pass them directly to the provider** (most explicit — no env needed):
141
+
142
+ ```python
143
+ from papertrade_india import IndiaPaperBroker, resilient_feed
144
+ from papertrade_india.providers import UpstoxProvider, UpstoxInstrumentMaster
145
+
146
+ feed = resilient_feed([
147
+ UpstoxProvider(access_token="your-token", resolve=UpstoxInstrumentMaster().resolve),
148
+ ])
149
+ broker = IndiaPaperBroker(price_feed=feed)
150
+ ```
151
+
152
+ Every provider accepts its key this way: `FinnhubProvider(api_key=...)`,
153
+ `DhanProvider(client_id=..., access_token=...)`,
154
+ `KiteProvider(api_key=..., access_token=...)`, and so on.
155
+
156
+ **2. Set an environment variable** — every provider falls back to it:
157
+
158
+ ```bash
159
+ export UPSTOX_ACCESS_TOKEN="your-token"
160
+ python your_script.py
161
+ ```
162
+
163
+ The variable names are listed in [`.env.example`](.env.example) (e.g.
164
+ `UPSTOX_ACCESS_TOKEN`, `FINNHUB_API_KEY`, `ALPHA_VANTAGE_API_KEY`,
165
+ `DHAN_CLIENT_ID` / `DHAN_ACCESS_TOKEN`).
166
+
167
+ **3. Use a `.env` file** — the library doesn't read `.env` automatically,
168
+ so load it yourself with [python-dotenv](https://pypi.org/project/python-dotenv/):
169
+
170
+ ```python
171
+ from dotenv import load_dotenv
172
+ load_dotenv() # copy .env.example to .env and fill in your keys
173
+ ```
140
174
 
141
175
  ## Fee model
142
176
 
@@ -155,20 +155,34 @@ sell()
155
155
 
156
156
  ```
157
157
  LimitOrderWatcher.tick()
158
- ├─ broker.get_orders(status=PENDING) # snapshot
159
- ├─ for each unique symbol: price_feed.get_price()
158
+ ├─ expire DAY orders whose own session has closed
159
+ ├─ broker.get_orders(open) # pointers only
160
+ ├─ for each unique symbol: one quote snapshot # price + freshness flags
160
161
  └─ for each crossing order:
161
- broker._execute_limit_fill(order, price):
162
- persistence.transaction():
163
- ├─ UPDATE orders SET status=FILLED # claim, race-safe
164
- │ WHERE status='pending' #
165
- ├─ if rowcount == 0: #
166
- │ raise OrderNoLongerPending # rolls back
162
+ broker._execute_limit_fill(order, snapshot):
163
+ check the snapshot (stale, real-time, price band) # before any write
164
+ persistence.transaction(): # BEGIN IMMEDIATE
165
+ ├─ SELECT the order row # current state, not the snapshot
166
+ ├─ if not pending / partially filled:
167
+ │ raise OrderNoLongerPending # rolls back
168
+ ├─ revalidate: position caps and cash (buys),
169
+ │ sellable shares for the product (sells)
170
+ │ └─ on failure: mark REJECTED / CANCELLED, commit,
171
+ │ then raise OrderRejectedAtFill
167
172
  ├─ _apply_buy / _apply_sell
168
- ├─ UPDATE realized_pl on order
173
+ ├─ UPDATE orders (filled qty, avg price, fees, realized P&L)
169
174
  └─ _record_trade
170
175
  ```
171
176
 
177
+ The order passed in is only a pointer. Remaining quantity, fees and status
178
+ come from the row read inside the write transaction, so two watchers that
179
+ picked the same order each add their own slice.
180
+
181
+ A refusal that depends on the market (stale or delayed quote, price band,
182
+ no liquidity, intraday cutoff) is raised before any write. The order stays
183
+ open and is retried on a later tick. A refusal that depends on the account
184
+ (cash, shares, position caps) ends the order.
185
+
172
186
  ## Cost-basis convention
173
187
 
174
188
  `Position.avg_cost` is the **per-share economic cost basis** including
@@ -12,7 +12,13 @@ How `IndianFeeEngine` computes fees on each order leg.
12
12
  | GST | 18% × (brokerage + exchange charge) | ✓ | ✓ | Not on STT/SEBI/stamp |
13
13
  | SEBI charges | 0.0001% (₹10 per crore) | ✓ | ✓ | |
14
14
  | Stamp duty | 0.015% of turnover | ✓ | | Buy only (delivery) |
15
- | DP charge | ₹13.5 flat | | ✓ | Per sell order in this simulator |
15
+ | DP charge | ₹13.5 flat | | ✓ | Once per delivery sell order; never on intraday sells |
16
+
17
+ Flat components are charged once per order, however many partial fills
18
+ the order has: the DP charge, a flat brokerage (`brokerage_flat`) and the
19
+ brokerage cap (`brokerage_max`). Each partial fill pays the order's fees
20
+ so far minus what earlier fills already paid. Turnover-based components
21
+ come out the same either way.
16
22
 
17
23
  Sources for the rates: paraphrased from public Indian discount-broker
18
24
  fee structures (Zerodha, Upstox, Groww, Angel One) published 2025–2026.
@@ -13,7 +13,12 @@ from __future__ import annotations
13
13
 
14
14
  import logging
15
15
 
16
- from papertrade_india import IndiaPaperBroker, OrderType
16
+ from papertrade_india import (
17
+ IndiaPaperBroker,
18
+ OrderType,
19
+ SettlementConfig,
20
+ SettlementMode,
21
+ )
17
22
 
18
23
 
19
24
  def main() -> None:
@@ -26,6 +31,10 @@ def main() -> None:
26
31
  initial_capital=1_000_000.0,
27
32
  db_path="examples/_local/basic.db",
28
33
  account_id="basic-demo",
34
+ # Same-day buy and sell of delivery shares needs T+0 settlement.
35
+ # The default is T+1, where shares bought today cannot be sold as
36
+ # delivery until the next trading day.
37
+ settlement_config=SettlementConfig(mode=SettlementMode.T_PLUS_0),
29
38
  # Set to True in real use; False here so the example runs anytime.
30
39
  enforce_market_hours=False,
31
40
  )
@@ -9,6 +9,8 @@ from __future__ import annotations
9
9
  from papertrade_india import (
10
10
  IndiaPaperBroker,
11
11
  PriceFeed,
12
+ SettlementConfig,
13
+ SettlementMode,
12
14
  )
13
15
 
14
16
 
@@ -34,6 +36,10 @@ def main() -> None:
34
36
  initial_capital=500_000,
35
37
  db_path="examples/_local/backtest.db",
36
38
  account_id="backtest",
39
+ # Same-day buy and sell of delivery shares needs T+0 settlement.
40
+ # The default is T+1, where shares bought today cannot be sold as
41
+ # delivery until the next trading day.
42
+ settlement_config=SettlementConfig(mode=SettlementMode.T_PLUS_0),
37
43
  price_feed=feed,
38
44
  enforce_market_hours=False,
39
45
  )
@@ -18,6 +18,8 @@ from papertrade_india import (
18
18
  IndiaPaperBroker,
19
19
  PriceFeed,
20
20
  ReplayClock,
21
+ SettlementConfig,
22
+ SettlementMode,
21
23
  SlippageConfig,
22
24
  )
23
25
 
@@ -49,6 +51,10 @@ def main() -> None:
49
51
  initial_capital=500_000,
50
52
  db_path="examples/_local/backtest_replay.db",
51
53
  account_id="bt-replay",
54
+ # Same-day buy and sell of delivery shares needs T+0 settlement.
55
+ # The default is T+1, where shares bought today cannot be sold as
56
+ # delivery until the next trading day.
57
+ settlement_config=SettlementConfig(mode=SettlementMode.T_PLUS_0),
52
58
  price_feed=feed,
53
59
  clock=clock,
54
60
  slippage_config=SlippageConfig(bps=5.0),
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "PaperTrade-India"
7
- version = "0.1.0.dev0"
7
+ version = "0.1.1"
8
8
  description = "Production-grade simulated broker for NSE/BSE paper trading"
9
9
  readme = "README.md"
10
10
  license = { file = "LICENSE" }
@@ -32,13 +32,16 @@ from .domain.exceptions import (
32
32
  IdempotencyConflict,
33
33
  IndiaPaperBrokerError,
34
34
  InsufficientFundsError,
35
+ InsufficientLiquidityError,
35
36
  InsufficientSharesError,
37
+ IntradayCutoffError,
36
38
  InvalidOrderError,
37
39
  KillSwitchActive,
38
40
  LotSizeViolation,
39
41
  MarginNotSupported,
40
42
  MarketClosedError,
41
43
  OrderNoLongerPending,
44
+ OrderRejectedAtFill,
42
45
  PriceBandViolation,
43
46
  PriceUnavailableError,
44
47
  RandomBrokerRejection,
@@ -245,6 +248,9 @@ __all__ = [
245
248
  "RandomBrokerRejection",
246
249
  "MarginNotSupported",
247
250
  "AMOWindowClosedError",
251
+ "InsufficientLiquidityError",
252
+ "IntradayCutoffError",
253
+ "OrderRejectedAtFill",
248
254
  ]
249
255
 
250
- __version__ = "0.1.0.dev0"
256
+ __version__ = "0.1.1"
@@ -34,6 +34,7 @@ from .domain.exceptions import AccountNotFoundError
34
34
  from .domain.models import (
35
35
  Account,
36
36
  Exchange,
37
+ FillQuote,
37
38
  Order,
38
39
  OrderSide,
39
40
  OrderStatus,
@@ -55,11 +56,12 @@ from .execution.simulation import (
55
56
  from .execution.slippage import SlippageConfig
56
57
  from .infrastructure import events as _events
57
58
  from .infrastructure import ledger as _ledger
59
+ from .infrastructure import migrations as _migrations
58
60
  from .infrastructure.clock import Clock, WallClock
59
61
  from .infrastructure.market_hours import NSECalendar, SessionPhase
60
62
  from .infrastructure.observability import BrokerEvent, EventBus
61
63
  from .infrastructure.persistence import PathLike, Persistence
62
- from .infrastructure.symbols import SymbolMaster
64
+ from .infrastructure.symbols import SymbolMaster, normalize_symbol
63
65
  from .infrastructure.watchlist import WatchlistStore
64
66
  from .interface import BrokerInterface
65
67
  from .orders import amo as _amo
@@ -139,8 +141,11 @@ class IndiaPaperBroker(BrokerInterface):
139
141
 
140
142
  self.persistence = Persistence(db_path)
141
143
  self._watchlist = WatchlistStore(self.persistence)
142
- self.price_feed = price_feed or PriceFeed()
143
- self.calendar = calendar or NSECalendar()
144
+ # Defaults follow the broker's venue (BSE → ``.BO`` quotes and the
145
+ # BSE holiday list). Injected feeds/calendars are used as given.
146
+ venue = str(getattr(exchange, "value", exchange)).upper()
147
+ self.price_feed = price_feed or PriceFeed(exchange=venue)
148
+ self.calendar = calendar or NSECalendar(exchange=venue)
144
149
 
145
150
  schedule: FeeSchedule
146
151
  if fee_config is None:
@@ -196,6 +201,10 @@ class IndiaPaperBroker(BrokerInterface):
196
201
  )
197
202
 
198
203
  self._ensure_account_exists(initial_capital, strict_open=strict_open)
204
+ # Read-only, never raises: warns if an old upgrade lost this
205
+ # account's trade history.
206
+ with self.persistence.read() as conn:
207
+ _migrations.warn_if_trade_history_missing(conn, self.account_id)
199
208
 
200
209
  # ── Clock / fee helpers (kept for backwards-compat callers) ───────
201
210
 
@@ -357,9 +366,14 @@ class IndiaPaperBroker(BrokerInterface):
357
366
  side: OrderSide,
358
367
  price: float,
359
368
  ) -> int | None:
360
- """Public accessor for queued shares-ahead at a price level."""
369
+ """Public accessor for queued shares-ahead at a price level.
370
+
371
+ ``symbol`` is normalized (stripped, upper-cased) first, the form
372
+ resting orders are queued under.
373
+ """
361
374
  if not self._book_sim.config.enabled:
362
375
  return None
376
+ symbol = normalize_symbol(symbol)
363
377
  from .orders.book_helpers import symbol_microstructure # noqa: PLC0415
364
378
  tick, _, _ = symbol_microstructure(self._ctx, symbol)
365
379
  return self._book_sim.queue_position(symbol, side, price, tick)
@@ -467,16 +481,37 @@ class IndiaPaperBroker(BrokerInterface):
467
481
  # ── Public API: account reset ─────────────────────────────────────
468
482
 
469
483
  def reset(self, initial_capital: float | None = None) -> None:
470
- """Reset account to initial state (paper-trading reset)."""
484
+ """Reset account to initial state (paper-trading reset).
485
+
486
+ Per-account tables, all for this account only:
487
+
488
+ - ``orders``, ``trades``, ``positions``: deleted.
489
+ - ``idempotency_keys``: deleted. Each key points at an order that
490
+ no longer exists, so a retry after the reset is a new order.
491
+ - ``pending_settlements``: deleted. They describe trades the reset
492
+ wipes; left behind, a T+1 delivery buy from before the reset
493
+ would keep reducing sellable shares after it.
494
+ - ``cash_movements``: deleted, then re-seeded with one
495
+ ``initial_capital`` row equal to the resulting cash, so the
496
+ cash invariant holds.
497
+ - ``events``: kept. It is the audit trail, and an
498
+ ``account_reset`` event is appended to it.
499
+
500
+ ``realized_pl_total`` returns to 0; cash becomes
501
+ ``initial_capital`` when given, otherwise is kept as-is. Global
502
+ tables (``symbols``, ``corporate_actions``, ``watchlist``) and
503
+ other accounts are untouched. The in-memory order-book queue is
504
+ emptied too: its entries belong to the orders just deleted.
505
+ """
471
506
  with self.persistence.transaction() as conn:
472
- conn.execute("DELETE FROM orders WHERE account_id = ?",
473
- (self.account_id,))
474
- conn.execute("DELETE FROM trades WHERE account_id = ?",
475
- (self.account_id,))
476
- conn.execute("DELETE FROM positions WHERE account_id = ?",
477
- (self.account_id,))
478
- conn.execute("DELETE FROM cash_movements WHERE account_id = ?",
479
- (self.account_id,))
507
+ # Children before ``orders``: explicit rather than relying on
508
+ # the foreign-key cascade, which only fires with FKs on.
509
+ for table in (
510
+ "trades", "idempotency_keys", "pending_settlements",
511
+ "orders", "positions", "cash_movements",
512
+ ):
513
+ conn.execute(f"DELETE FROM {table} WHERE account_id = ?",
514
+ (self.account_id,))
480
515
  now = self._now_iso()
481
516
  if initial_capital is not None:
482
517
  conn.execute(
@@ -503,6 +538,7 @@ class IndiaPaperBroker(BrokerInterface):
503
538
  notes="Account reset (cash preserved)")
504
539
  self._emit_event(conn, event_type="account_reset",
505
540
  payload={"initial_capital": initial_capital})
541
+ self._book_sim.clear_queue()
506
542
  self._drain_pending_events()
507
543
  logger.info("RESET account %s", self.account_id)
508
544
 
@@ -515,14 +551,16 @@ class IndiaPaperBroker(BrokerInterface):
515
551
  def _execute_limit_fill(
516
552
  self,
517
553
  order: Order,
518
- fill_price: float,
554
+ fill_price: float | FillQuote,
519
555
  fill_qty: float | None = None,
520
556
  ) -> None:
521
557
  """Shim: delegates to orders.limit.fill (used by LimitOrderWatcher)."""
522
558
  from .orders.limit import fill as _limit_fill # noqa: PLC0415
523
559
  _limit_fill(self._ctx, order, fill_price, fill_qty=fill_qty)
524
560
 
525
- def _trigger_stop_order(self, order: Order, last_price: float) -> None:
561
+ def _trigger_stop_order(
562
+ self, order: Order, last_price: float | FillQuote,
563
+ ) -> None:
526
564
  """Shim: delegates to orders.stop.trigger (used by LimitOrderWatcher)."""
527
565
  from .orders.stop import trigger as _stop_trigger # noqa: PLC0415
528
566
  _stop_trigger(self._ctx, order, last_price)
@@ -194,7 +194,12 @@ def expire_day_orders(
194
194
  db: str = typer.Option("data/india_paper.db", help="SQLite DB path"),
195
195
  account_id: str = typer.Option("default", "--account", help="Account ID"),
196
196
  ) -> None:
197
- """Expire all PENDING DAY-tif limit orders. Run at session close."""
197
+ """Expire open DAY orders, including partially filled remainders.
198
+
199
+ With market-hours enforcement on, only orders whose own session has
200
+ closed are expired; with it off, every open DAY order is. A partially
201
+ filled order keeps its fills and its remainder is cancelled.
202
+ """
198
203
  b = _broker(db, account_id)
199
204
  n = b.expire_stale_day_orders()
200
205
  console.print(f"[green]Expired {n} DAY order(s).[/green]")
@@ -11,6 +11,7 @@ import logging
11
11
  from fractions import Fraction
12
12
  from typing import TYPE_CHECKING
13
13
 
14
+ from ..infrastructure.symbols import normalize_symbol
14
15
  from . import store as _store
15
16
 
16
17
  if TYPE_CHECKING: # pragma: no cover
@@ -38,8 +39,17 @@ def apply(
38
39
  ``new_qty = old_qty * (num + den) / den``, with avg_cost adjusted to
39
40
  preserve total cost basis.
40
41
 
42
+ ``symbol`` is normalized (stripped, upper-cased) before use, so
43
+ it matches the position orders created.
44
+
45
+ As with a split, when the account holds the symbol the same
46
+ transaction scales its pending T+1 delivery buys by the
47
+ split-equivalent factor and records the account's highest trade
48
+ rowid (``last_trade_rowid``) in the ``corporate_action`` event.
49
+
41
50
  Returns the action id. Idempotency is *not* enforced.
42
51
  """
52
+ symbol = normalize_symbol(symbol)
43
53
  if ratio_num <= 0 or ratio_den <= 0:
44
54
  raise ValueError("ratio components must be positive integers")
45
55
  bonus_ratio = Fraction(ratio_num, ratio_den)
@@ -79,6 +89,10 @@ def apply(
79
89
  "WHERE account_id = ? AND symbol = ?",
80
90
  (new_qty, new_avg, ctx.account_id, symbol),
81
91
  )
92
+ ctx.settlement.rescale_pending_buys(
93
+ conn, account_id=ctx.account_id, symbol=symbol,
94
+ factor=float(split_equiv),
95
+ )
82
96
  ctx.emit(
83
97
  conn,
84
98
  event_type="corporate_action",
@@ -90,6 +104,9 @@ def apply(
90
104
  "ex_date": ex_date,
91
105
  "old_qty": old_qty,
92
106
  "new_qty": new_qty,
107
+ "last_trade_rowid": _store.last_trade_rowid(
108
+ conn, ctx.account_id,
109
+ ),
93
110
  },
94
111
  )
95
112
 
@@ -14,6 +14,7 @@ import logging
14
14
  from typing import TYPE_CHECKING
15
15
 
16
16
  from ..infrastructure import ledger as _ledger
17
+ from ..infrastructure.symbols import normalize_symbol
17
18
  from . import store as _store
18
19
 
19
20
  if TYPE_CHECKING: # pragma: no cover
@@ -31,9 +32,13 @@ def apply(
31
32
  ) -> str:
32
33
  """Apply a cash dividend to the broker's holding.
33
34
 
35
+ ``symbol`` is normalized (stripped, upper-cased) before use, so
36
+ it matches the position orders created.
37
+
34
38
  Returns the action id. Calling twice on the same dividend
35
39
  double-credits — wrap in your own dedup if needed.
36
40
  """
41
+ symbol = normalize_symbol(symbol)
37
42
  if amount_per_share <= 0:
38
43
  raise ValueError("amount_per_share must be positive")
39
44
  ex_date = ex_date or ctx.clock.now().date().isoformat()
@@ -14,6 +14,7 @@ from typing import TYPE_CHECKING
14
14
 
15
15
  from ..domain.exceptions import InsufficientFundsError
16
16
  from ..infrastructure import ledger as _ledger
17
+ from ..infrastructure.symbols import normalize_symbol
17
18
  from . import store as _store
18
19
 
19
20
  if TYPE_CHECKING: # pragma: no cover
@@ -49,8 +50,12 @@ def apply(
49
50
  subscription cost (preserves the round-trip P&L invariant).
50
51
  - Insufficient cash raises :class:`InsufficientFundsError`.
51
52
 
53
+ ``symbol`` is normalized (stripped, upper-cased) before use, so
54
+ it matches the position orders created.
55
+
52
56
  Returns the action id whether or not the user subscribes.
53
57
  """
58
+ symbol = normalize_symbol(symbol)
54
59
  if ratio_num <= 0 or ratio_den <= 0:
55
60
  raise ValueError("ratio components must be positive integers")
56
61
  if subscription_price <= 0: