Skip to content

Commit

Permalink
approved coins from file; approved coins and ignored coins in backtest
Browse files Browse the repository at this point in the history
  • Loading branch information
enarjord committed Sep 19, 2024
1 parent 2ed63a8 commit 9818458
Showing 1 changed file with 31 additions and 28 deletions.
59 changes: 31 additions & 28 deletions src/procedures.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,38 +163,41 @@ def format_config(config: dict, verbose=True) -> dict:
result[k0][k1] = v
if verbose:
print(f"adding missing parameter {k0} {k1}: {v}")
for k_coins in ["approved_coins", "ignored_coins"]:
if isinstance(path := result["live"][k_coins], str):
if os.path.exists(path):
try:
if path.endswith(".json") or path.endswith(".hjson"):
result["live"][k_coins] = hjson.load(open(path))
if verbose:
print(f"set {k_coins} {result['live'][k_coins]}")
elif path.endswith(".txt"):
with open(path) as f:
result["live"][k_coins] = [xx for x in f.readlines() if (xx := x.strip())]
if verbose:
print(f"set {k_coins} {result['live'][k_coins]}")
else:
print(f"failed to load {k_coins} from file {path}, unknown file format")
except Exception as e:
print(f"failed to load {k_coins} from file {path} {e}")
else:
print(f"path to {k_coins} file does not exist {path}")
result["live"][k_coins] = []
if result["live"]["ignored_coins"]:
result["live"]["ignored_coins"] = coins_to_symbols(
result["live"]["ignored_coins"], verbose=verbose
)
if result["live"]["approved_coins"]:
result["live"]["approved_coins"] = coins_to_symbols(
result["live"]["approved_coins"] = [
x for x in coins_to_symbols(
result["live"]["approved_coins"], verbose=verbose
)
) if x not in result["live"]["ignored_coins"]
]
result["backtest"]["symbols"] = result["live"]["approved_coins"]
else:
result["backtest"]["symbols"] = get_all_eligible_symbols(result["backtest"]["exchange"])
if isinstance(path := result["live"]["ignored_coins"], str):
if os.path.exists(path):
try:
if path.endswith(".json"):
result["live"]["ignored_coins"] = json.load(open(path))
if verbose:
print(f"set ignored coins {result['live']['ignored_coins']}")
elif path.endswith(".hjson"):
result["live"]["ignored_coins"] = hjson.load(open(path))
if verbose:
print(f"set ignored coins {result['live']['ignored_coins']}")
elif path.endswith(".txt"):
with open(path) as f:
result["live"]["ignored_coins"] = [
xx for x in f.readlines() if (xx := x.strip())
]
if verbose:
print(f"set ignored coins {result['live']['ignored_coins']}")
else:
print(f"failed to load ignored coins from file {path}, unknown file format")
except Exception as e:
print(f"failed to load ignored coins from file {path} {e}")
else:
print(f"path to ignored coins file does not exist {path}")
result["live"]["ignored_coins"] = []
result["backtest"]["symbols"] = [
x for x in get_all_eligible_symbols(result["backtest"]["exchange"]) if x not in result["live"]["ignored_coins"]
]
return result


Expand Down

0 comments on commit 9818458

Please sign in to comment.