investing-algorithm-framework 1.7.9__tar.gz → 1.7.10__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 (135) hide show
  1. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/PKG-INFO +1 -1
  2. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/app/algorithm.py +75 -16
  3. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/__init__.py +4 -2
  4. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/constants.py +1 -0
  5. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/services/order_service.py +4 -7
  6. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework.egg-info/PKG-INFO +1 -1
  7. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/AUTHORS.md +0 -0
  8. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/LICENSE +0 -0
  9. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/README.md +0 -0
  10. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/__init__.py +0 -0
  11. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/app/__init__.py +0 -0
  12. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/app/app.py +0 -0
  13. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/app/stateless/__init__.py +0 -0
  14. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/app/stateless/action_handlers/__init__.py +0 -0
  15. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/app/stateless/action_handlers/action_handler_strategy.py +0 -0
  16. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/app/stateless/action_handlers/check_online_handler.py +0 -0
  17. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/app/stateless/action_handlers/run_strategy_handler.py +0 -0
  18. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/app/stateless/exception_handler.py +0 -0
  19. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/app/strategy.py +0 -0
  20. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/app/task.py +0 -0
  21. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/app/web/__init__.py +0 -0
  22. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/app/web/controllers/__init__.py +0 -0
  23. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/app/web/controllers/orders.py +0 -0
  24. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/app/web/controllers/portfolio.py +0 -0
  25. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/app/web/controllers/positions.py +0 -0
  26. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/app/web/create_app.py +0 -0
  27. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/app/web/error_handler.py +0 -0
  28. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/app/web/responses.py +0 -0
  29. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/app/web/run_strategies.py +0 -0
  30. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/app/web/schemas/__init__.py +0 -0
  31. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/app/web/schemas/order.py +0 -0
  32. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/app/web/schemas/portfolio.py +0 -0
  33. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/app/web/schemas/position.py +0 -0
  34. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/app/web/setup_cors.py +0 -0
  35. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/create_app.py +0 -0
  36. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/dependency_container.py +0 -0
  37. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/config.py +0 -0
  38. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/decimal_parsing.py +0 -0
  39. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/exceptions.py +0 -0
  40. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/models/__init__.py +0 -0
  41. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/models/backtest_profile.py +0 -0
  42. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/models/base_model.py +0 -0
  43. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/models/market_data/__init__.py +0 -0
  44. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/models/market_data/asset_price.py +0 -0
  45. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/models/market_data/ohlcv.py +0 -0
  46. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/models/market_data/order_book.py +0 -0
  47. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/models/market_data/ticker.py +0 -0
  48. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/models/order/__init__.py +0 -0
  49. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/models/order/order.py +0 -0
  50. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/models/order/order_fee.py +0 -0
  51. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/models/order/order_side.py +0 -0
  52. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/models/order/order_status.py +0 -0
  53. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/models/order/order_type.py +0 -0
  54. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/models/portfolio/__init__.py +0 -0
  55. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/models/portfolio/backtest_portfolio_configuration.py +0 -0
  56. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/models/portfolio/portfolio.py +0 -0
  57. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/models/portfolio/portfolio_configuration.py +0 -0
  58. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/models/portfolio/portfolio_snapshot.py +0 -0
  59. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/models/position/__init__.py +0 -0
  60. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/models/position/position.py +0 -0
  61. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/models/position/position_snapshot.py +0 -0
  62. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/models/strategy_profile.py +0 -0
  63. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/models/time_frame.py +0 -0
  64. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/models/time_interval.py +0 -0
  65. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/models/time_unit.py +0 -0
  66. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/models/trade.py +1 -1
  67. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/models/trading_data_types.py +0 -0
  68. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/models/trading_time_frame.py +0 -0
  69. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/services/__init__.py +0 -0
  70. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/services/market_data_sources.py +0 -0
  71. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/services/order_executor_service.py +0 -0
  72. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/singleton.py +0 -0
  73. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/stateless_actions.py +0 -0
  74. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/strategy.py +0 -0
  75. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/utils/__init__.py +0 -0
  76. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/utils/backtesting.py +0 -0
  77. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/utils/csv.py +0 -0
  78. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/utils/random.py +0 -0
  79. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/utils/signatures.py +0 -0
  80. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/utils/stoppable_thread.py +0 -0
  81. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/utils/synchronized.py +0 -0
  82. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/__init__.py +0 -0
  83. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/database/__init__.py +0 -0
  84. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/database/sql_alchemy.py +0 -0
  85. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/models/__init__.py +0 -0
  86. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/models/decimal_parser.py +0 -0
  87. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/models/market_data_sources/__init__.py +0 -0
  88. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/models/market_data_sources/ccxt.py +0 -0
  89. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/models/market_data_sources/csv.py +0 -0
  90. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/models/model_extension.py +0 -0
  91. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/models/order/__init__.py +0 -0
  92. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/models/order/order.py +0 -0
  93. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/models/order/order_fee.py +0 -0
  94. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/models/portfolio/__init__.py +0 -0
  95. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/models/portfolio/portfolio.py +0 -0
  96. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/models/portfolio/portfolio_snapshot.py +0 -0
  97. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/models/position/__init__.py +0 -0
  98. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/models/position/position.py +0 -0
  99. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/models/position/position_snapshot.py +0 -0
  100. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/repositories/__init__.py +0 -0
  101. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/repositories/order_fee_repository.py +0 -0
  102. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/repositories/order_repository.py +0 -0
  103. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/repositories/portfolio_repository.py +0 -0
  104. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/repositories/portfolio_snapshot_repository.py +0 -0
  105. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/repositories/position_repository.py +0 -0
  106. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/repositories/position_snapshot_repository.py +0 -0
  107. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/repositories/repository.py +0 -0
  108. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/services/__init__.py +0 -0
  109. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/services/market_service/__init__.py +0 -0
  110. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/services/market_service/backtest_market_service.py +0 -0
  111. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/services/market_service/ccxt_market_service.py +0 -0
  112. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/services/market_service/market_service.py +0 -0
  113. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/services/performance_service/__init__.py +0 -0
  114. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/services/performance_service/backtest_performance_service.py +0 -0
  115. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/services/performance_service/performance_service.py +0 -0
  116. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/services/__init__.py +0 -0
  117. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/services/backtest_service.py +0 -0
  118. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/services/configuration_service.py +0 -0
  119. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/services/market_data_service.py +0 -0
  120. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/services/order_backtest_service.py +0 -0
  121. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/services/portfolio_configuration_service.py +0 -0
  122. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/services/portfolio_service.py +0 -0
  123. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/services/portfolio_snapshot_service.py +0 -0
  124. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/services/position_cost_service.py +0 -0
  125. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/services/position_service.py +0 -0
  126. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/services/position_snapshot_service.py +0 -0
  127. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/services/repository_service.py +0 -0
  128. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/services/strategy_orchestrator_service.py +0 -0
  129. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework.egg-info/SOURCES.txt +0 -0
  130. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework.egg-info/dependency_links.txt +0 -0
  131. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework.egg-info/requires.txt +0 -0
  132. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework.egg-info/top_level.txt +0 -0
  133. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/setup.cfg +0 -0
  134. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/setup.py +0 -0
  135. {investing_algorithm_framework-1.7.9 → investing_algorithm_framework-1.7.10}/tests/test_create_app.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: investing_algorithm_framework
3
- Version: 1.7.9
3
+ Version: 1.7.10
4
4
  Summary: A framework for creating an investment algorithm
5
5
  Home-page: https://github.com/coding-kitties/investing-algorithm-framework.git
6
6
  Download-URL: https://github.com/coding-kitties/investing-algorithm-framework/archive/v0.1.1.tar.gz
@@ -1,5 +1,6 @@
1
1
  import logging
2
2
  from typing import List
3
+ from queue import Queue
3
4
 
4
5
  from investing_algorithm_framework.domain import OrderStatus, OrderFee, \
5
6
  Position, Order, Portfolio, OrderType, OrderSide, ApiException, \
@@ -9,6 +10,49 @@ from investing_algorithm_framework.domain import OrderStatus, OrderFee, \
9
10
  logger = logging.getLogger("investing_algorithm_framework")
10
11
 
11
12
 
13
+ class PeekableQueue:
14
+ def __init__(self):
15
+ self.queue = []
16
+ self.index = 0
17
+
18
+ def enqueue(self, item):
19
+ self.queue.append(item)
20
+
21
+ def dequeue(self):
22
+ if not self.is_empty():
23
+ return self.queue.pop(0)
24
+ else:
25
+ raise IndexError("Queue is empty")
26
+
27
+ def peek(self):
28
+ if not self.is_empty():
29
+ return self.queue[0]
30
+ else:
31
+ raise IndexError("Queue is empty")
32
+
33
+ def is_empty(self):
34
+ return len(self.queue) == 0
35
+
36
+ def __len__(self):
37
+ return len(self.queue)
38
+
39
+ def size(self):
40
+ return len(self.queue)
41
+
42
+ def __iter__(self):
43
+ self.index = 0
44
+ return self
45
+
46
+ def __next__(self):
47
+ if self.index < len(self.queue):
48
+ result = self.queue[self.index]
49
+ self.index += 1
50
+ return result
51
+ else:
52
+ self.index = 0 # Reset index for next iteration
53
+ raise StopIteration
54
+
55
+
12
56
  class Algorithm:
13
57
 
14
58
  def __init__(
@@ -726,6 +770,7 @@ class Algorithm:
726
770
  def get_open_trades(self, target_symbol=None):
727
771
  portfolios = self.portfolio_service.get_all()
728
772
  trades = []
773
+
729
774
  for portfolio in portfolios:
730
775
 
731
776
  if target_symbol is not None:
@@ -735,38 +780,51 @@ class Algorithm:
735
780
  "portfolio_id": portfolio.id,
736
781
  "target_symbol": target_symbol
737
782
  })
783
+ sell_orders = self.order_service.get_all({
784
+ "status": OrderStatus.OPEN.value,
785
+ "order_side": OrderSide.SELL.value,
786
+ "portfolio_id": portfolio.id,
787
+ "target_symbol": target_symbol
788
+ })
738
789
  else:
739
790
  buy_orders = self.order_service.get_all({
740
791
  "status": OrderStatus.CLOSED.value,
741
792
  "order_side": OrderSide.BUY.value,
742
793
  "portfolio_id": portfolio.id
743
794
  })
795
+ sell_orders = self.order_service.get_all({
796
+ "status": OrderStatus.OPEN.value,
797
+ "order_side": OrderSide.SELL.value,
798
+ "portfolio_id": portfolio.id
799
+ })
800
+
744
801
  buy_orders = [
745
802
  buy_order for buy_order in buy_orders
746
803
  if buy_order.get_trade_closed_at() is None
747
804
  ]
748
- sell_orders = self.order_service.get_all({
749
- "status": OrderStatus.OPEN.value,
750
- "order_side": OrderSide.SELL.value,
751
- "portfolio_id": portfolio.id
752
- })
753
- sell_amount = sum([order.get_amount() for order in sell_orders])
805
+ sell_amount = sum([order.amount for order in sell_orders])
754
806
 
755
807
  # Subtract the amount of the open sell orders
756
808
  # from the amount of the buy orders
757
- while sell_amount > 0 and len(buy_orders) > 0:
758
- first_order = buy_orders[0]
809
+ buy_orders_queue = PeekableQueue()
759
810
 
760
- if first_order.get_available_amount() > sell_amount:
761
- first_order.set_available_amount(
762
- first_order.get_available_amount() - sell_amount
763
- )
811
+ for buy_order in buy_orders:
812
+ buy_orders_queue.enqueue(buy_order)
813
+
814
+ while sell_amount > 0 and not buy_orders_queue.is_empty():
815
+ first_buy_order = buy_orders_queue.peek()
816
+ available = first_buy_order.get_filled() \
817
+ - first_buy_order.get_trade_closed_amount()
818
+
819
+ if available > sell_amount:
820
+ remaining = available - sell_amount
764
821
  sell_amount = 0
822
+ first_buy_order.set_filled(remaining)
765
823
  else:
766
- sell_amount = sell_amount - first_order.get_available_amount()
767
- buy_orders.pop(0)
824
+ sell_amount = sell_amount - available
825
+ buy_orders_queue.dequeue()
768
826
 
769
- for buy_order in buy_orders:
827
+ for buy_order in buy_orders_queue:
770
828
  symbol = buy_order.get_symbol()
771
829
 
772
830
  try:
@@ -792,7 +850,8 @@ class Algorithm:
792
850
  buy_order_id=buy_order.id,
793
851
  target_symbol=buy_order.get_target_symbol(),
794
852
  trading_symbol=buy_order.get_trading_symbol(),
795
- amount=buy_order.get_amount(),
853
+ amount=buy_order.get_filled()
854
+ - buy_order.get_trade_closed_amount(),
796
855
  open_price=buy_order.get_price(),
797
856
  opened_at=buy_order.get_created_at(),
798
857
  current_price=ticker["bid"]
@@ -12,7 +12,8 @@ from .constants import ITEMIZE, ITEMIZED, PER_PAGE, PAGE, ENVIRONMENT, \
12
12
  DEFAULT_PAGE_VALUE, SQLALCHEMY_DATABASE_URI, RESOURCE_DIRECTORY, \
13
13
  DATETIME_FORMAT, DATETIME_FORMAT_BACKTESTING, BACKTESTING_FLAG, \
14
14
  BACKTESTING_INDEX_DATETIME, BACKTESTING_START_DATE, CCXT_DATETIME_FORMAT, \
15
- BACKTEST_DATA_DIRECTORY_NAME, TICKER_DATA_TYPE, OHLCV_DATA_TYPE
15
+ BACKTEST_DATA_DIRECTORY_NAME, TICKER_DATA_TYPE, OHLCV_DATA_TYPE, \
16
+ CURRENT_UTC_DATETIME
16
17
  from .singleton import Singleton
17
18
  from .utils import random_string, append_dict_as_row_to_csv, \
18
19
  add_column_headers_to_csv, get_total_amount_of_rows, \
@@ -90,5 +91,6 @@ __all__ = [
90
91
  "OHLCVMarketDataSource",
91
92
  "BacktestMarketDataSource",
92
93
  "BacktestPortfolioConfiguration",
93
- "MarketDataSource"
94
+ "MarketDataSource",
95
+ "CURRENT_UTC_DATETIME"
94
96
  ]
@@ -69,3 +69,4 @@ BACKTESTING_INDEX_DATETIME = "BACKTESTING_INDEX_DATETIME"
69
69
  BACKTESTING_START_DATE = "BACKTESTING_START_DATE"
70
70
  TICKER_DATA_TYPE = "TICKER"
71
71
  OHLCV_DATA_TYPE = "OHLCV"
72
+ CURRENT_UTC_DATETIME = "CURRENT_UTC_DATETIME"
@@ -651,12 +651,8 @@ class OrderService(RepositoryService):
651
651
 
652
652
  while amount_to_close > 0 and not order_queue.empty():
653
653
  buy_order = order_queue.get()
654
-
655
- if buy_order.get_trade_closed_amount() != None:
656
- available_to_close = buy_order.get_filled() \
657
- - buy_order.get_trade_closed_amount()
658
- else:
659
- available_to_close = buy_order.get_filled()
654
+ available_to_close = buy_order.get_filled() \
655
+ - buy_order.get_trade_closed_amount()
660
656
 
661
657
  if amount_to_close >= available_to_close:
662
658
  to_be_closed = available_to_close
@@ -682,7 +678,8 @@ class OrderService(RepositoryService):
682
678
  self.order_repository.update(
683
679
  buy_order.id,
684
680
  {
685
- "trade_closed_amount": buy_order.get_trade_closed_amount() + to_be_closed,
681
+ "trade_closed_amount":
682
+ buy_order.get_trade_closed_amount() + to_be_closed,
686
683
  "trade_closed_price": sell_order.get_price(),
687
684
  "net_gain": buy_order.get_net_gain() + net_gain
688
685
  }
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: investing-algorithm-framework
3
- Version: 1.7.9
3
+ Version: 1.7.10
4
4
  Summary: A framework for creating an investment algorithm
5
5
  Home-page: https://github.com/coding-kitties/investing-algorithm-framework.git
6
6
  Download-URL: https://github.com/coding-kitties/investing-algorithm-framework/archive/v0.1.1.tar.gz
@@ -160,10 +160,10 @@ class Trade(BaseModel):
160
160
  trading_symbol=self.trading_symbol,
161
161
  amount=self.amount,
162
162
  open_price=self.open_price,
163
+ current_price=self.current_price,
163
164
  closed_price=self.closed_price,
164
165
  opened_at=self.opened_at,
165
166
  closed_at=self.closed_at,
166
- current_price=self.current_price,
167
167
  value=self.value,
168
168
  change=self.percentage_change,
169
169
  absolute_change=self.absolute_change,