Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add return type annotations for buy and sell methods #975

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions backtesting/_plotting.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import os
import re
import sys
Expand Down
2 changes: 2 additions & 0 deletions backtesting/_stats.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from typing import TYPE_CHECKING, List, Union

import numpy as np
Expand Down
2 changes: 2 additions & 0 deletions backtesting/_util.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import warnings
from numbers import Number
from typing import Dict, List, Optional, Sequence, Union, cast
Expand Down
15 changes: 10 additions & 5 deletions backtesting/backtesting.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

from backtesting import Backtest, Strategy
"""

from __future__ import annotations

import multiprocessing as mp
import os
import sys
Expand Down Expand Up @@ -200,9 +203,10 @@ def buy(self, *,
stop: Optional[float] = None,
sl: Optional[float] = None,
tp: Optional[float] = None,
tag: object = None):
tag: object = None) -> 'Order':
"""
Place a new long order. For explanation of parameters, see `Order` and its properties.
Place a new long order and return it. For explanation of parameters, see `Order`
and its properties.

See `Position.close()` and `Trade.close()` for closing existing positions.

Expand All @@ -218,9 +222,10 @@ def sell(self, *,
stop: Optional[float] = None,
sl: Optional[float] = None,
tp: Optional[float] = None,
tag: object = None):
tag: object = None) -> 'Order':
"""
Place a new short order. For explanation of parameters, see `Order` and its properties.
Place a new short order and return it. For explanation of parameters, see `Order`
and its properties.

See also `Strategy.buy()`.

Expand Down Expand Up @@ -730,7 +735,7 @@ def new_order(self,
tp: Optional[float] = None,
tag: object = None,
*,
trade: Optional[Trade] = None):
trade: Optional[Trade] = None) -> Order:
"""
Argument size indicates whether the order is long or short
"""
Expand Down
2 changes: 2 additions & 0 deletions backtesting/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
[issue tracker]: https://github.com/kernc/backtesting.py
"""

from __future__ import annotations

from collections import OrderedDict
from inspect import currentframe
from itertools import compress
Expand Down
3 changes: 3 additions & 0 deletions backtesting/test/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
"""Data and utilities for testing."""

from __future__ import annotations

import pandas as pd


Expand Down