quantex 0.6.1__tar.gz → 0.6.2__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: quantex
3
- Version: 0.6.1
3
+ Version: 0.6.2
4
4
  Summary: A simple quant strategy creation and backtesting package.
5
5
  License-Expression: MIT
6
6
  License-File: LICENSE.md
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "quantex"
3
- version = "0.6.1"
3
+ version = "0.6.2"
4
4
  description = "A simple quant strategy creation and backtesting package."
5
5
  authors = [
6
6
  {name = "Daniel Green",email = "dangreen07@outlook.com"}
@@ -75,7 +75,7 @@ class Broker:
75
75
  openPositionsDirection = self.openPositions[name][0].direction
76
76
  curr_timestamp = self.__context__.datas[name].Timestamp[-1]
77
77
  if openPositionsDirection and openPositionsDirection != order.direction:
78
- price: float = self.__context__.datas[name].Close[-1]
78
+ price: float = self.__context__.datas[name].Open[-1]
79
79
  if self.execute_condition(order, price):
80
80
  amount = order.amount
81
81
  for i in range(len(self.openPositions[name])):
@@ -93,18 +93,14 @@ class Broker:
93
93
  amount -= closed_amount
94
94
  if amount == 0:
95
95
  if order.parentId is not None:
96
- idx = 0
97
- for i in range(len(self.orderQueue[name])):
98
- if self.orderQueue[name][i].id == order.id:
99
- continue
100
- elif (
101
- self.orderQueue[name][i].parentId == order.parentId
96
+ for queued_order in self.orderQueue[name]:
97
+ if (
98
+ queued_order.id != order.id
99
+ and queued_order.parentId == order.parentId
102
100
  ):
103
- idx = i
104
- break
105
- self.orderQueue[name].pop(
106
- idx
107
- ) ## OCO - One Cancels the Other
101
+ self.cancelQueue[name].append(
102
+ queued_order
103
+ ) ## OCO - One Cancels the Other
108
104
  break
109
105
  positions = []
110
106
  for openOrder in self.openPositions[name]:
@@ -154,7 +150,7 @@ class Broker:
154
150
  self.cash += total
155
151
  return True
156
152
  else:
157
- price: float = self.__context__.datas[name].Close[-1]
153
+ price: float = self.__context__.datas[name].Open[-1]
158
154
  if self.execute_condition(order, price):
159
155
  total = order.amount * price
160
156
  self.openPositions[name].append(
@@ -388,38 +384,35 @@ class Broker:
388
384
  """
389
385
  if name is None:
390
386
  name = list(self.__context__.datas.keys())[0]
391
- totalPositionAmount = 0
392
387
  if len(self.openPositions[name]) == 0:
393
388
  return
394
- direction = self.openPositions[name][0].direction
395
389
  for order in self.openPositions[name]:
396
- totalPositionAmount += order.amount_filled
397
- if direction == OrderDirection.BUY:
398
- self.orderQueue[name].append(
399
- NewOrder(
400
- self.__orderId__,
401
- self.__context__.datas[name].Timestamp[-1],
402
- OrderType.MARKET,
403
- OrderDirection.SELL,
404
- totalPositionAmount,
405
- None,
406
- None,
390
+ if order.direction == OrderDirection.BUY:
391
+ self.orderQueue[name].append(
392
+ NewOrder(
393
+ self.__orderId__,
394
+ self.__context__.datas[name].Timestamp[-1],
395
+ OrderType.MARKET,
396
+ OrderDirection.SELL,
397
+ order.amount_filled,
398
+ None,
399
+ order.parentId or order.id,
400
+ )
407
401
  )
408
- )
409
- self.__orderId__ += 1
410
- else:
411
- self.orderQueue[name].append(
412
- NewOrder(
413
- self.__orderId__,
414
- self.__context__.datas[name].Timestamp[-1],
415
- OrderType.MARKET,
416
- OrderDirection.BUY,
417
- totalPositionAmount,
418
- None,
419
- None,
402
+ self.__orderId__ += 1
403
+ elif order.direction == OrderDirection.SELL:
404
+ self.orderQueue[name].append(
405
+ NewOrder(
406
+ self.__orderId__,
407
+ self.__context__.datas[name].Timestamp[-1],
408
+ OrderType.MARKET,
409
+ OrderDirection.BUY,
410
+ order.amount_filled,
411
+ None,
412
+ order.parentId or order.id,
413
+ )
420
414
  )
421
- )
422
- self.__orderId__ += 1
415
+ self.__orderId__ += 1
423
416
 
424
417
  def is_long(self, name: str | None = None) -> bool:
425
418
  """
File without changes
File without changes
File without changes
File without changes