-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
104 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from typing import List | ||
|
||
from components.orders.order import Order | ||
from components.orders.position import Position | ||
|
||
|
||
class PositionManager: | ||
def __init__(self, strategy: 'BaseStrategy'): | ||
self._strategy = strategy | ||
self.positions: List[Position] = [] | ||
|
||
def open(self, order_type: str, side: str, quantity: int): | ||
"""Opens a new position""" | ||
|
||
# create order | ||
order = Order( | ||
type=order_type, | ||
side=side, | ||
qty=quantity, | ||
symbol=self._strategy.symbol.symbol, | ||
timestamp=self._strategy.data.timestamp, | ||
) | ||
|
||
self.positions.append( | ||
Position( | ||
orders=[order], | ||
) | ||
) | ||
|
||
def close(self): | ||
"""Closes the most recent position""" | ||
self.positions[-1].add_closing_order() | ||
|
||
def all(self): | ||
return self.positions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters