-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #134 from AsyncAlgoTrading/calendar
Trading day and misc other fixes
- Loading branch information
Showing
18 changed files
with
312 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,68 @@ | ||
# Contributing | ||
|
||
Thank you for your interest in contributing to aat! | ||
|
||
|
||
## Reporting bugs, feature requests, etc. | ||
|
||
To report bugs, request new features or similar, please open an issue on the Github | ||
repository. | ||
|
||
A good bug report includes: | ||
|
||
- Expected behavior | ||
- Actual behavior | ||
- Steps to reproduce (preferably as minimal as possible) | ||
|
||
## Minor changes, typos etc. | ||
|
||
Minor changes can be contributed by navigating to the relevant files on the Github repository, | ||
and clicking the "edit file" icon. By following the instructions on the page you should be able to | ||
create a pull-request proposing your changes. A repository maintainer will then review your changes, | ||
and either merge them, propose some modifications to your changes, or reject them (with a reason for | ||
the rejection). | ||
|
||
## Setting up a development environment | ||
|
||
If you want to help resolve an issue by making some changes that are larger than that covered by the above paragraph, it is recommended that you: | ||
|
||
- Fork the repository on Github | ||
- Clone your fork to your computer | ||
- Run the following commands inside the cloned repository: | ||
- `pip install -e .[dev]` - This will install the Python package in development | ||
mode. | ||
- Validate the install by running the tests: | ||
- `py.test` - This command will run the Python tests. | ||
- `flake8 aat/` - This command will run the Python linters. | ||
|
||
Once you have such a development setup, you should: | ||
|
||
- Make the changes you consider necessary | ||
- Run the tests to ensure that your changes does not break anything | ||
- Run the linters to ensure that your changes does not break anything | ||
- Run mypy if necessary to alert for problems with type annotations | ||
- If you add new code, preferably write one or more tests for checking that your code works as expected. | ||
- Commit your changes and publish the branch to your github repo. | ||
- Open a pull-request (PR) back to the main repo on Github. | ||
|
||
## Style | ||
### Docstrings | ||
Docstrings are [google format](https://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_google.html). | ||
|
||
|
||
### Python | ||
Python code is formatted with [black](https://github.com/psf/black) and [flake8](https://github.com/PyCQA/flake8) and annotated for typings with [mypy](https://github.com/python/mypy). | ||
|
||
#### Misc | ||
- Public methods should be `camelCase` | ||
- Public attributes should be `camelCase` | ||
- Private methods should be `snake_case` | ||
- Private attributes should be `snake_case` | ||
- JSON import/export should be `snake_case` | ||
|
||
### JS | ||
JS Code is writted in `typescript` and formatted with `eslint` and `prettier`. | ||
|
||
### C++ | ||
C++ Code is formateed with [cpplint](https://github.com/cpplint/cpplint) and [clang-format](https://clang.llvm.org/docs/ClangFormat.html). | ||
|
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 |
---|---|---|
@@ -1,26 +1,26 @@ | ||
from .exchange import ExchangeType # noqa: F401 | ||
from .data import Data, Error, Event, Order, Trade | ||
from .exchange import ExchangeType | ||
|
||
# from .execution import OrderManager # noqa: F401 | ||
from .handler import EventHandler, PrintHandler # noqa: F401 | ||
from .instrument import Instrument # noqa: F401 | ||
from .data import Data, Error, Event, Order, Trade # noqa: F401 | ||
from .position import Account, Position, CashPosition # noqa: F401 | ||
from .order_book import OrderBook # noqa: F401 | ||
# from .execution import OrderManager | ||
from .handler import EventHandler, PrintHandler | ||
from .instrument import Instrument, TradingDay | ||
from .order_book import OrderBook | ||
from .position import Account, CashPosition, Position | ||
|
||
# from .portfolio import Portfolio, PortfolioManager # noqa: F401 | ||
# from .risk import RiskManager # noqa: F401 | ||
from .table import TableHandler # noqa: F401 | ||
# from .portfolio import Portfolio, PortfolioManager | ||
# from .risk import RiskManager | ||
from .table import TableHandler | ||
|
||
try: | ||
from ..binding import ( # type: ignore # noqa: F401 | ||
InstrumentCpp, | ||
from ..binding import ( | ||
AccountCpp, | ||
DataCpp, | ||
EventCpp, | ||
InstrumentCpp, | ||
OrderBookCpp, | ||
OrderCpp, | ||
TradeCpp, | ||
AccountCpp, | ||
PositionCpp, | ||
OrderBookCpp, | ||
TradeCpp, | ||
) | ||
except ImportError: | ||
pass |
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
from .calendar import TradingDay # noqa: F401 | ||
from .instrument import Instrument # noqa: F401 |
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,72 @@ | ||
from datetime import time | ||
from typing import Optional, Tuple, Union, cast | ||
|
||
from aat.common import AATException | ||
from pytz import UTC | ||
|
||
|
||
class TradingDay(object): | ||
"""Construct a representation of an instrument's trading day | ||
Args: | ||
open_times (Union[time, Tuple[time]]): time or tuple of times representing the time/s of market open. If missing tzinfo, will assume UTC. | ||
close_times (Union[time, Tuple[time]]): time or tuple of times representing the time/s of market close. If missing tzinfo, will assume UTC. | ||
""" | ||
|
||
__slots__ = [ | ||
"_open_times", | ||
"_close_times", | ||
] | ||
|
||
def __init__( | ||
self, | ||
open_times: Union[time, Tuple[time, ...]] = None, | ||
close_times: Union[time, Tuple[time, ...]] = None, | ||
): | ||
if open_times and not isinstance(open_times, (tuple, time)): | ||
# raise exception if wrong type | ||
raise AATException( | ||
"`open_times` must be time or tuple of times, got: {}".format( | ||
type(open_times) | ||
) | ||
) | ||
elif isinstance(open_times, time): | ||
# force tuple | ||
open_times = cast(Tuple[time, ...], (open_times,)) | ||
|
||
if open_times: | ||
# force tz | ||
open_times = tuple( | ||
tm if tm.tzinfo else time(tm.hour, tm.minute, tzinfo=UTC) | ||
for tm in open_times | ||
) | ||
|
||
self._open_times: Optional[Tuple[time, ...]] = open_times | ||
|
||
if close_times and not isinstance(close_times, (tuple, time)): | ||
# raise exception if wrong type | ||
raise AATException( | ||
"`close_times` must be time or tuple of times, got: {}".format( | ||
type(close_times) | ||
) | ||
) | ||
elif isinstance(close_times, time): | ||
# force tuple | ||
close_times = cast(Tuple[time, ...], (close_times,)) | ||
|
||
if close_times: | ||
# force tz | ||
close_times = tuple( | ||
tm if tm.tzinfo else time(tm.hour, tm.minute, tzinfo=UTC) | ||
for tm in close_times | ||
) | ||
|
||
self._close_times: Optional[Tuple[time, ...]] = close_times | ||
|
||
@property | ||
def open(self) -> Optional[Tuple[time, ...]]: | ||
return self._open_times | ||
|
||
@property | ||
def close(self) -> Optional[Tuple[time, ...]]: | ||
return self._close_times |
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
Oops, something went wrong.