Skip to content
This repository has been archived by the owner on Aug 27, 2024. It is now read-only.

Commit

Permalink
Merge pull request #87 from auto-trading-temp-name/master
Browse files Browse the repository at this point in the history
Master to algo
  • Loading branch information
fou3fou3 authored Mar 14, 2024
2 parents f3a1459 + fc7cfb3 commit c444a97
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 24 deletions.
1 change: 0 additions & 1 deletion .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ on:
push:
branches:
- 'master'
- 'transaction-service'

jobs:
docker:
Expand Down
2 changes: 1 addition & 1 deletion src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
app.add_url_rule('/signals', view_func=signals.signals)

if __name__ == '__main__':
app.run()
app.run(debug=True)
1 change: 1 addition & 0 deletions src/backtest_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def backtest(algorithm: str,
transactions = []
start_balance = balance
shares = 0
price = 0

for index, price in enumerate(prices, 1):
signal, strength = algorithm_output(algorithm, prices[0:index], backtest=True)
Expand Down
22 changes: 11 additions & 11 deletions src/price.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@
price_collector_interval = 5
supported_intervals = [5, 15, 30, 60, 240, 1440, 10080]

default_coin = 'WETH'
supported_coins = ['WETH']
default_pair = 'USDC-WETH'
supported_pairs = ['USDC-WETH']

def is_supported_interval(interval: int) -> bool:
global supported_intervals
return interval in supported_intervals

def is_supported_coin(coin: str) -> bool:
global supported_coins
return coin in supported_coins
def is_supported_pair(pair: str) -> bool:
global supported_pairs
return pair in supported_pairs

def get_using_interval() -> int:
if has_request_context():
Expand All @@ -30,12 +30,12 @@ def get_using_interval() -> int:
return interval
return default_interval

def get_using_coin() -> str:
def get_using_pair() -> str:
if has_request_context():
coin = request.args.get('coin')
if is_supported_coin(coin):
return coin
return default_coin
pair = request.args.get('pair')
if is_supported_pair(pair):
return pair
return default_pair

def get_prices(interval, pair):
if not interval or not pair:
Expand All @@ -44,7 +44,7 @@ def get_prices(interval, pair):
if not is_supported_interval(interval):
raise Exception(f'Unsupported Interval: {interval}')

if not is_supported_coin(pair):
if not is_supported_pair(pair):
raise Exception(f'Unsupported Pair: {pair}')

slicing_ratio = int(interval / price_collector_interval)
Expand Down
4 changes: 2 additions & 2 deletions src/views/backtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from ipaddress import ip_address
from utils import get_algorithms
from flask import request
from price import get_prices, get_using_coin, get_using_interval
from price import get_prices, get_using_pair, get_using_interval

mpl.use('Agg')

Expand All @@ -15,7 +15,7 @@ def backtest_view(algorithm_name: str):
visualize = request.args.get('plot', type=bool, default=False)

try:
prices, timestamps = get_prices(interval, get_using_coin())
prices, timestamps = get_prices(interval, get_using_pair())
except Exception as error:
return str(error), 400

Expand Down
4 changes: 2 additions & 2 deletions src/views/plot.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from price import get_prices, get_using_coin, get_using_interval, is_supported_interval
from price import get_prices, get_using_pair, get_using_interval
import matplotlib.pyplot as plt
import matplotlib as mpl
import numpy as np
Expand All @@ -15,7 +15,7 @@

def plot(algorithm_name: str):
interval = get_using_interval()
pair = get_using_coin()
pair = get_using_pair()
interactive = request.args.get('interactive', type=bool, default=False)

if algorithm_name not in ['price', *get_algorithms()]:
Expand Down
12 changes: 5 additions & 7 deletions src/views/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,19 @@ def signals():
if not ip_address(request.remote_addr).is_private:
return 'Forbidden', 403

# require explicit interval and coin instead of using get_using_x()
# require explicit interval and pair instead of using get_using_x()
interval = request.args.get('interval', type=int)
coin = request.args.get('coin', type=str)
pair = request.args.get('pair', type=str)

try:
prices, _ = get_prices(interval=interval, pair=coin)
prices, _ = get_prices(interval=interval, pair=pair)
except Exception as error:
return str(error), 400

# Convert list of algorithms into {name: signal}
algorithms = get_algorithms()

base = dict(map(lambda x: algorithm_output(*x), zip(algorithms, [prices] * len(algorithms))))

signals = {k: v[0] for (k, v) in base.items()}
# strengths = {k: v[1] for (k, v) in base.items()}
# @TODO replace amount with user specified max instead of 10
signals = [{'algorithm': k, 'signal': v[0], 'amount': v[1] * 10} for (k, v) in base.items()]

return signals

0 comments on commit c444a97

Please sign in to comment.