Skip to content

Commit b12a824

Browse files
authored
Merge pull request #1 from Finterion/feature/refactor-poetry-package
Feature/refactor poetry package
2 parents c3fd126 + 17af39c commit b12a824

12 files changed

Lines changed: 2138 additions & 150 deletions

File tree

.github/workflows/build.yml

Lines changed: 0 additions & 41 deletions
This file was deleted.

.github/workflows/publish.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Build and publish python package
2+
3+
on:
4+
release:
5+
types: [ published ]
6+
7+
jobs:
8+
publish-service-client-package:
9+
runs-on: ubuntu-latest
10+
permissions:
11+
contents: write
12+
steps:
13+
- name: Publish PyPi package
14+
uses: code-specialist/pypi-poetry-publish@v1
15+
with:
16+
ACCESS_TOKEN: ${{ secrets.REPOSITORY_ACCESS_TOKEN }}
17+
PUBLISH_REGISTRY_PASSWORD: ${{ secrets.PYPI_TOKEN }}
18+
BRANCH: "main"
19+
POETRY_VERSION: "1.7.1"
20+
POETRY_CORE_VERSION: "1.8.1"

.github/workflows/test.yml

Lines changed: 89 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,99 @@
1-
# This workflow will install Python dependencies, run tests and lint
2-
# with a single version of Python
3-
4-
name: Tests
1+
name: test
52

63
on:
74
push:
85
branches:
96
- '*' # matches every branch that doesn't contain a '/'
107
- '*/*' # matches every branch containing a single '/'
118
- '**' # matches every branch
12-
pull_request:
13-
branches:
14-
- '*' # matches every branch that doesn't contain a '/'
15-
- '*/*' # matches every branch containing a single '/'
16-
- '**' # matches every branch
17-
jobs:
18-
build:
9+
pull_request:
10+
branches:
11+
- '*' # matches every branch that doesn't contain a '/'
12+
- '*/*' # matches every branch containing a single '/'
13+
- '**' # matches every branch
1914

15+
jobs:
16+
linting:
2017
runs-on: ubuntu-latest
21-
2218
steps:
23-
- uses: actions/checkout@v2
24-
- name: Set up Python 3.9
25-
uses: actions/setup-python@v2
26-
with:
27-
python-version: 3.9
28-
- name: Install dependencies
29-
run: |
30-
python -m pip install --upgrade pip
31-
pip install flake8
32-
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
33-
if [ -f requirements-test.txt ]; then pip install -r requirements-test.txt; fi
34-
- name: Lint with flake8
35-
run: |
36-
# stop the build if there are Python syntax errors or undefined names
37-
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
38-
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
39-
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
40-
- name: Test
41-
run: |
42-
python -m unittest discover -s tests/
19+
#----------------------------------------------
20+
# check-out repo and set-up python
21+
#----------------------------------------------
22+
- uses: actions/checkout@v4
23+
- uses: actions/setup-python@v5
24+
#----------------------------------------------
25+
# load pip cache if cache exists
26+
#----------------------------------------------
27+
- uses: actions/cache@v3
28+
with:
29+
path: ~/.cache/pip
30+
key: ${{ runner.os }}-pip
31+
restore-keys: ${{ runner.os }}-pip
32+
#----------------------------------------------
33+
# install and run linters
34+
#----------------------------------------------
35+
- run: python -m pip install black flake8 isort
36+
- run: |
37+
flake8 ./finterion_investing_algorithm_framework
38+
test:
39+
needs: linting
40+
strategy:
41+
fail-fast: true
42+
matrix:
43+
os: [ "ubuntu-latest", "macos-latest" ]
44+
python-version: [ "3.8", "3.9", "3.10", "3.11" ]
45+
runs-on: ${{ matrix.os }}
46+
steps:
47+
#----------------------------------------------
48+
# check-out repo and set-up python
49+
#----------------------------------------------
50+
- name: Check out repository
51+
uses: actions/checkout@v4
52+
- name: Set up python ${{ matrix.python-version }}
53+
id: setup-python
54+
uses: actions/setup-python@v5
55+
with:
56+
python-version: ${{ matrix.python-version }}
57+
#----------------------------------------------
58+
# ----- install & configure poetry -----
59+
#----------------------------------------------
60+
- name: Install Poetry
61+
uses: snok/install-poetry@v1
62+
with:
63+
virtualenvs-create: true
64+
virtualenvs-in-project: true
65+
#----------------------------------------------
66+
# load cached venv if cache exists
67+
#----------------------------------------------
68+
- name: Load cached venv
69+
id: cached-poetry-dependencies
70+
uses: actions/cache@v3
71+
with:
72+
path: .venv
73+
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
74+
#----------------------------------------------
75+
# install dependencies if cache does not exist
76+
#----------------------------------------------
77+
- name: Install dependencies
78+
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
79+
run: poetry install --no-interaction --no-root
80+
#----------------------------------------------
81+
# install your root project, if required
82+
#----------------------------------------------
83+
- name: Install library
84+
run: poetry install --no-interaction
85+
#----------------------------------------------
86+
# add matrix specifics and run test suite
87+
#----------------------------------------------
88+
- name: Run tests
89+
run: |
90+
source .venv/bin/activate
91+
coverage run -m unittest discover -s tests
92+
# #----------------------------------------------
93+
# # upload coverage stats
94+
# #----------------------------------------------
95+
# - name: Upload coverage
96+
# uses: codecov/codecov-action@v3
97+
# with:
98+
# file: ./coverage.xml
99+
# fail_ci_if_error: true

finterion_investing_algorithm_framework/create_app.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def create_app(
2727
# Check that the portfolio is active
2828
check_portfolio_active(client)
2929

30+
# Add a finterion portfolio configuration
3031
portfolio_configuration = FinterionPortfolioConfiguration(
3132
trading_symbol=model['profile']['trading_symbol'],
3233
market_data_markets=model['profile']['markets'],
@@ -39,11 +40,12 @@ def create_app(
3940
secret_key=None,
4041
)
4142
)
43+
market_credential_service = app.container.market_credential_service()
4244
app.container.market_service.override(
4345
FinterionMarketService(
4446
api_key=api_key,
4547
base_url=base_url,
46-
market_credential_service=app.container.market_credential_service,
48+
market_credential_service=market_credential_service
4749
)
4850
)
4951
app.add_portfolio_configuration(portfolio_configuration)

finterion_investing_algorithm_framework/market_service.py

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
from finterion import Finterion
55
from investing_algorithm_framework import Order
66
from investing_algorithm_framework.infrastructure import CCXTMarketService
7+
from finterion_investing_algorithm_framework.exceptions import \
8+
FinterionInvestingAlgorithmFrameworkException
79

810

911
class FinterionMarketService(CCXTMarketService):
@@ -21,6 +23,41 @@ def get_closed_orders(
2123
):
2224
pass
2325

26+
def get_ticker(self, symbol, market):
27+
"""
28+
Finterion does not support get_ticker, please specify a ticker market
29+
data source for symbol {symbol}. Finterion can't provide this data.
30+
31+
Users should register their own ticker data sources to obtain ticker
32+
data.
33+
"""
34+
raise FinterionInvestingAlgorithmFrameworkException(
35+
f"Finterion does not support get_ticker, please specify "
36+
f"a ticker market data source for symbol {symbol}. Finterion "
37+
f"can't provide this data."
38+
)
39+
40+
def get_order_book(self, symbol, market):
41+
raise FinterionInvestingAlgorithmFrameworkException(
42+
f"Finterion does not support get_order_book, please specify "
43+
f"an order book market data source for symbol {symbol}. Finterion "
44+
f"can't provide this data."
45+
)
46+
47+
def get_ohlcv(
48+
self,
49+
symbol,
50+
time_frame,
51+
from_timestamp,
52+
market,
53+
to_timestamp=None
54+
):
55+
raise FinterionInvestingAlgorithmFrameworkException(
56+
f"Finterion does not support get_ohlcv, please specify "
57+
f"an ohlcv market data source for symbol {symbol}. Finterion "
58+
f"can't provide this data."
59+
)
60+
2461
def __init__(
2562
self,
2663
api_key,
@@ -46,7 +83,7 @@ def get_order(self, order, market):
4683
return self._convert_order(order)
4784

4885
def get_orders(self, symbol, market, since: datetime = None):
49-
orders = self._finterion.get_orders(target_symbol=symbol)
86+
orders = self._finterion.get_orders(target_symbol=symbol.split("/")[0])
5087
return [self._convert_order(order) for order in orders]
5188

5289
def get_balance(self, market):
@@ -117,7 +154,11 @@ def _convert_order(self, finterion_order):
117154
target_symbol=finterion_order.get("target_symbol"),
118155
trading_symbol=finterion_order.get("trading_symbol"),
119156
price=finterion_order.get("price"),
120-
trade_closed_price=finterion_order.get("trade_closed_price"),
157+
trade_closed_price=finterion_order.get("trade_closed_price", None),
158+
trade_closed_at=finterion_order.get("trade_closed_at", None),
159+
trade_closed_amount=finterion_order.get(
160+
"trade_closed_amount", None
161+
),
121162
filled=finterion_order.get("filled"),
122163
remaining=finterion_order.get("remaining"),
123164
cost=finterion_order.get("cost"),

finterion_investing_algorithm_framework/models/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33

44
__all__ = [
55
'FinterionPortfolioConfiguration',
6-
]
6+
]

finterion_investing_algorithm_framework/validation.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55

66
def check_portfolio_active(finterion_client: Finterion):
7-
portfolio = finterion_client.get_portfolio()
7+
portfolio = finterion_client\
8+
.get_portfolio(query_params={"ShowMetrics": "False"})
89

910
if portfolio['active'] is False:
1011
raise FinterionInvestingAlgorithmFrameworkException(

0 commit comments

Comments
 (0)