diff --git a/strategies/mike_strat/__init__.py b/strategies/mike_strat/__init__.py new file mode 100644 index 000000000..011d720ed --- /dev/null +++ b/strategies/mike_strat/__init__.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# ------------------------------------------------------------------------------ +# +# Copyright 2023 Valory AG +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ------------------------------------------------------------------------------ + +"""This module contains the bet amount per threshold strategy.""" diff --git a/strategies/mike_strat/component.yaml b/strategies/mike_strat/component.yaml new file mode 100644 index 000000000..5a5bbbede --- /dev/null +++ b/strategies/mike_strat/component.yaml @@ -0,0 +1,14 @@ +name: mike_strat +author: valory +version: 0.1.0 +type: custom +description: A simple strategy that bets a fixed amount when the confidence is of a given threshold. +license: Apache-2.0 +aea_version: '>=1.0.0, <2.0.0' +fingerprint: + __init__.py: bafybeidey4syohls5hxmso6qsp5p4uhtzle5txv2mlbym6ktjzknich6oa + mike_s.py: bafybeibqwl52cnz64cysjd2jnjijuakdvyrffapxq65cdzx6g65gu42deq +fingerprint_ignore_patterns: [] +entry_point: mike_strat.py +callable: run +dependencies: {} \ No newline at end of file diff --git a/strategies/mike_strat/mike_strat.py b/strategies/mike_strat/mike_strat.py new file mode 100644 index 000000000..1f31cfa3f --- /dev/null +++ b/strategies/mike_strat/mike_strat.py @@ -0,0 +1,65 @@ +# -*- coding: utf-8 -*- +# ------------------------------------------------------------------------------ +# +# Copyright 2023 Valory AG +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ------------------------------------------------------------------------------ + +"""This module contains a simple strategy that returns a bet amount based on a mapping.""" + +from typing import Union, List, Dict, Tuple, Any + +REQUIRED_FIELDS = ("confidence", "bet_amount_per_threshold") + + +def check_missing_fields(kwargs: Dict[str, Any]) -> List[str]: + """Check for missing fields and return them, if any.""" + missing = [] + for field in REQUIRED_FIELDS: + if kwargs.get(field, None) is None: + missing.append(field) + return missing + + +def remove_irrelevant_fields(kwargs: Dict[str, Any]) -> Dict[str, Any]: + """Remove the irrelevant fields from the given kwargs.""" + return {key: value for key, value in kwargs.items() if key in REQUIRED_FIELDS} + + +def amount_per_threshold( + confidence: float, bet_amount_per_threshold: Dict[str, int] +) -> Dict[str, Union[int, Tuple[str]]]: + """Get the bet amount per threshold strategy's result.""" + # we need the threshold as a string, because the agent/service overrides cannot be given with `int`s as keys + threshold = str(round(confidence, 1)) + bet_amount = bet_amount_per_threshold.get(threshold, None) + + if bet_amount is None: + return { + "error": ( + f"No amount was found in {bet_amount_per_threshold=} for {confidence=}.", + ) + } + return {"bet_amount": bet_amount * confidence} + + +def run(*_args, **kwargs) -> Dict[str, Union[int, Tuple[str]]]: + """Run the strategy.""" + missing = check_missing_fields(kwargs) + if len(missing) > 0: + return {"error": (f"Required kwargs {missing} were not provided.",)} + + kwargs = remove_irrelevant_fields(kwargs) + return amount_per_threshold(**kwargs)