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 #86 from auto-trading-temp-name/coin-pair
Browse files Browse the repository at this point in the history
coin -> pair
  • Loading branch information
fou3fou3 authored Feb 23, 2024
2 parents 0487d3b + dfb69b9 commit 6181c63
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
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 = 'USDC-WETH'
supported_coins = ['USDC-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
2 changes: 1 addition & 1 deletion src/views/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ 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)
pair = request.args.get('pair', type=str)

Expand Down

0 comments on commit 6181c63

Please sign in to comment.