Skip to content

Commit

Permalink
add logging, update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
robswc committed Mar 24, 2023
1 parent f792ce1 commit c5e7269
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
24 changes: 16 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,21 @@ the full power of python at your disposal.
```python
class OHLCDemo(Strategy):

@on_step # the on_step decorator runs the function on every "step" of the OHLC data
@on_step # on_step decorated, runs every "step" of the OHLC data
def print_ohlc(self):

# strategy shorthands for the OHLC data
# shorthands for the OHLC data
timestamp = self.data.timestamp
close = self.data.close

# if the timestamp is a multiple of 3600000 (1 hour), print the timestamp and close price
# if the timestamp is a multiple of 3600000 (1 hour)
if timestamp % 3600000 == 0:
print(f'{timestamp}: {close}')

# create a datetime object from the timestamp
dt = datetime.datetime.fromtimestamp(timestamp / 1000)
if dt.hour == 10:
print(f'{dt}: {close}')
```

```python
data = CSVAdapter('data/AAPL.csv')
strategy = OHLCDemo().run(data)
Expand All @@ -64,12 +67,15 @@ strategy = OHLCDemo().run(data)
## Table of Contents

- [Installation](#Installation)
- [Features](#features)
- [Docker](#Docker)
- [Python and NPM](#Python-and-NPM)

[//]: # (- [Features](#features))

## Installation

It is heavily recommended to use Docker to run stratis. This is because stratis requires a number of dependencies that
can be difficult to install.
It is heavily recommended to use [Docker](https://www.docker.com/resources/what-container/) to run stratis. This is because stratis requires a number of dependencies that
can be difficult to install without Docker.


### Docker
Expand Down Expand Up @@ -99,6 +105,8 @@ And the Stratis backend (core) should be accessible via:
### Python and NPM

For more advanced usage, you can run app with python directly, as it is a FastAPI app under the hood.
Please note, this may or may not work for Windows and MacOS, as I have only tested it on Linux.

I would recommend using a [virtual environment](https://docs.python.org/3/library/venv.html) for this.
You will also have to [install the requirements](https://pip.pypa.io/en/latest/user_guide/#requirements-files).
The following commands will start the backend of stratis.
Expand Down
11 changes: 8 additions & 3 deletions app/components/positions/position_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from components.positions.position import Position
from components.positions.utils import add_closing_order_to_position

from loguru import logger


class PositionManager:
def __init__(self, strategy: 'BaseStrategy'):
Expand Down Expand Up @@ -39,8 +41,11 @@ def open(self, order_type: str, side: str, quantity: int):

def close(self):
"""Closes the most recent position"""
position_to_close = self.positions[-1]
add_closing_order_to_position(position=position_to_close, ohlc=self._strategy.data)
try:
position_to_close = self.positions[-1]
add_closing_order_to_position(position=position_to_close, ohlc=self._strategy.data)
except IndexError:
logger.error(f'{self._strategy} has no positions to close')

def all(self):
return self.positions
return self.positions

0 comments on commit c5e7269

Please sign in to comment.