Skip to content

Commit

Permalink
Merge pull request #124 from valory-xyz/fix/balance-check
Browse files Browse the repository at this point in the history
Add missing balance check
  • Loading branch information
DavidMinarsch authored Nov 2, 2023
2 parents fa8b8ea + 17081e9 commit f7894da
Show file tree
Hide file tree
Showing 12 changed files with 266 additions and 154 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/common_checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ jobs:
run: tomte check-copyright --author valory --exclude-part abci --exclude-part http_client --exclude-part ipfs --exclude-part ledger --exclude-part p2p_libp2p_client --exclude-part gnosis_safe --exclude-part gnosis_safe_proxy_factory --exclude-part multisend --exclude-part service_registry --exclude-part protocols --exclude-part abstract_abci --exclude-part abstract_round_abci --exclude-part registration_abci --exclude-part reset_pause_abci --exclude-part termination_abci --exclude-part transaction_settlement_abci --exclude-part websocket_client --exclude-part contract_subscription
- name: License compatibility check
run: tox -e liccheck
- name: Check dependencies
run: tox -e check-dependencies
# TODO reintroduce when bumping 0.13.1 to a newer version with a fix for the check
# - name: Check dependencies
# run: tox -e check-dependencies
- name: Check doc links
run: tomte check-doc-links --url-skips https://github.com/valory-xyz/trader.git
- name: Check doc IPFS hashes
Expand Down
10 changes: 5 additions & 5 deletions packages/packages.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"dev": {
"skill/valory/market_manager_abci/0.1.0": "bafybeidropskas24c4lcekzdbwoflhnzaglmeqxvpyuoa7cf7q2rf2yex4",
"skill/valory/decision_maker_abci/0.1.0": "bafybeie4k3s546hx4p5g3dtn75hlrysyh3ieslszexctwal4odmarx34fm",
"skill/valory/trader_abci/0.1.0": "bafybeigpzcq345ed5acmehnp7uj4nwv22xtl35mbp4x2howw7sps3iwi2e",
"skill/valory/decision_maker_abci/0.1.0": "bafybeic2yjuwtfxekyukqgewbdnqc56ywuhn3pjgohjedzz7oaylbwqufy",
"skill/valory/trader_abci/0.1.0": "bafybeidnjemlz2kisz3slmdid53bwas44wnu7loubcjahgdzvofskfqzpi",
"contract/valory/market_maker/0.1.0": "bafybeif4mm2s3gxtvp227yypkcnna5ftec7vajcftvtbdmqddh7nprah5m",
"agent/valory/trader/0.1.0": "bafybeicda6weararan4qyidf7dd4vxwesektyrjmu6mhvraew6q2mrezhu",
"service/valory/trader/0.1.0": "bafybeigwj6jajdge5qcjz6mimoylkv6zhbso45w4t6zo2m7olwkbb5puyq",
"agent/valory/trader/0.1.0": "bafybeihqpkckhv2rkldbnaav6jlkiziacqdsbw3suykjzgqls7v3jkomz4",
"service/valory/trader/0.1.0": "bafybeid3r54ylrhu7vhrhzqb3vaqrecvpeuksgnfkjryhpt6ofsqqsa2ve",
"contract/valory/erc20/0.1.0": "bafybeieqj7dea4tcv6z2yqkgtmhd23vbiycsr5trhwxdvlbwulpl6vhmam",
"skill/valory/tx_settlement_multiplexer_abci/0.1.0": "bafybeiet3hqejz7rtutuzmvyl7wqwqqi2buqagryawav4yeuem45ohpr2e",
"skill/valory/tx_settlement_multiplexer_abci/0.1.0": "bafybeifdiag5des6schlumiyes2nvrlhi6nupvneup247iaswehttg7wqu",
"contract/valory/mech/0.1.0": "bafybeihvc6btuk3nvernzcx4qpezvuhiw2wwnagqj5nkeljvszghv7mq64",
"contract/valory/realitio/0.1.0": "bafybeid6kh4tiqswpeufkr7eowmq7seoyhkssnedgzw6pe4h7wswui6dlm",
"contract/valory/realitio_proxy/0.1.0": "bafybeidx37xzjjmapwacedgzhum6grfzhp5vhouz4zu3pvpgdy5pgb2fr4",
Expand Down
6 changes: 3 additions & 3 deletions packages/valory/agents/trader/aea-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ skills:
- valory/reset_pause_abci:0.1.0:bafybeicpxn2khtaesuf4cq6ypwdmdmonlqroj2q2i6cxvpizc2y4cw66pe
- valory/termination_abci:0.1.0:bafybeieqm46zuccaagnko3qlw6p3nvoohdrfgvpmw467r5lyil2dqrzjsy
- valory/transaction_settlement_abci:0.1.0:bafybeia6cdxdlqrcwk2maw25fo7dafzd2p3rs7syropvufophk2pitzbwy
- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeiet3hqejz7rtutuzmvyl7wqwqqi2buqagryawav4yeuem45ohpr2e
- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeifdiag5des6schlumiyes2nvrlhi6nupvneup247iaswehttg7wqu
- valory/market_manager_abci:0.1.0:bafybeidropskas24c4lcekzdbwoflhnzaglmeqxvpyuoa7cf7q2rf2yex4
- valory/decision_maker_abci:0.1.0:bafybeie4k3s546hx4p5g3dtn75hlrysyh3ieslszexctwal4odmarx34fm
- valory/trader_abci:0.1.0:bafybeigpzcq345ed5acmehnp7uj4nwv22xtl35mbp4x2howw7sps3iwi2e
- valory/decision_maker_abci:0.1.0:bafybeic2yjuwtfxekyukqgewbdnqc56ywuhn3pjgohjedzz7oaylbwqufy
- valory/trader_abci:0.1.0:bafybeidnjemlz2kisz3slmdid53bwas44wnu7loubcjahgdzvofskfqzpi
default_ledger: ethereum
required_ledgers:
- ethereum
Expand Down
2 changes: 1 addition & 1 deletion packages/valory/services/trader/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ license: Apache-2.0
fingerprint:
README.md: bafybeigtuothskwyvrhfosps2bu6suauycolj67dpuxqvnicdrdu7yhtvq
fingerprint_ignore_patterns: []
agent: valory/trader:0.1.0:bafybeicda6weararan4qyidf7dd4vxwesektyrjmu6mhvraew6q2mrezhu
agent: valory/trader:0.1.0:bafybeihqpkckhv2rkldbnaav6jlkiziacqdsbw3suykjzgqls7v3jkomz4
number_of_agents: 4
deployment: {}
---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ def get_bet_amount(
selected_type_tokens_in_pool: int,
other_tokens_in_pool: int,
bet_fee: int,
) -> int:
) -> Generator[None, None, int]:
"""Get the bet amount given a specified trading strategy."""

if strategy == "bet_amount_per_conf_threshold":
Expand All @@ -310,6 +310,7 @@ def get_bet_amount(

self.context.logger.info("Used trading strategy: Kelly Criterion")
# bankroll: the max amount of DAI available to trade
yield from self.wait_for_condition_with_sleep(self.check_balance)
bankroll = self.token_balance + self.wallet_balance
# keep `floor_balance` xDAI in the bankroll
floor_balance = 500000000000000000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,14 +307,14 @@ def _calc_binary_shares(self, net_bet_amount: int, vote: int) -> Tuple[int, int]

def _is_profitable(
self, vote: int, win_probability: float, confidence: float
) -> Tuple[bool, int]:
) -> Generator[None, None, Tuple[bool, int]]:
"""Whether the decision is profitable or not."""
bet = self.synchronized_data.sampled_bet
selected_type_tokens_in_pool, other_tokens_in_pool = self._get_bet_sample_info(
bet, vote
)

bet_amount = self.get_bet_amount(
bet_amount = yield from self.get_bet_amount(
self.params.trading_strategy,
win_probability,
confidence,
Expand Down Expand Up @@ -368,7 +368,7 @@ def async_act(self) -> Generator:
and confidence is not None
and win_probability is not None
):
is_profitable, bet_amount = self._is_profitable(
is_profitable, bet_amount = yield from self._is_profitable(
vote, win_probability, confidence
)
payload = DecisionReceivePayload(
Expand Down
4 changes: 2 additions & 2 deletions packages/valory/skills/decision_maker_abci/skill.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ fingerprint:
README.md: bafybeia367zzdwndvlhw27rvnwodytjo3ms7gbc3q7mhrrjqjgfasnk47i
__init__.py: bafybeih563ujnigeci2ldzh7hakbau6a222vsed7leg3b7lq32vcn3nm4a
behaviours/__init__.py: bafybeih6ddz2ocvm6x6ytvlbcz6oi4snb5ee5xh5h65nq4w2qf7fd7zfky
behaviours/base.py: bafybeige65wi6lqzq26sbl5n6y7haqkgjltlwb65k6sohzv77pp3rmhsjm
behaviours/base.py: bafybeiffvzohjzr6rubdccfcbhgbjyyxxx2flldavubwtjuac2hai2nrdy
behaviours/bet_placement.py: bafybeigtz4uimsqjjwq4r5p3a5v6niqdtqezbuf2ghy6o7syhsh4k5gjfa
behaviours/blacklisting.py: bafybeicl6b4hcmqmekta2mcuhkkydnzk7jmic6k44e6ns3u2ibad3awzvu
behaviours/decision_receive.py: bafybeidw2etz4k5zbmqp6qfg2ba5eimgpjl3w5bv7fz2xd6ah6vrns3g4i
behaviours/decision_receive.py: bafybeifacce2ke7oltnwnpdjdqfd74eaaw5wxnjfzk6c5tqdsxsmbzjj3m
behaviours/decision_request.py: bafybeibrk6jxalkgspinmjboqr3o6d6hl6mxtlkif74a5p32vp2zzhhzua
behaviours/handle_failed_tx.py: bafybeidxpc6u575ymct5tdwutvzov6zqfdoio5irgldn3fw7q3lg36mmxm
behaviours/reedem.py: bafybeiewhlzhvrjtllym3jyk5fzci4r67fgutgzgrsmv4t3uvrejm7aaki
Expand Down
4 changes: 2 additions & 2 deletions packages/valory/skills/trader_abci/skill.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ skills:
- valory/transaction_settlement_abci:0.1.0:bafybeia6cdxdlqrcwk2maw25fo7dafzd2p3rs7syropvufophk2pitzbwy
- valory/termination_abci:0.1.0:bafybeieqm46zuccaagnko3qlw6p3nvoohdrfgvpmw467r5lyil2dqrzjsy
- valory/market_manager_abci:0.1.0:bafybeidropskas24c4lcekzdbwoflhnzaglmeqxvpyuoa7cf7q2rf2yex4
- valory/decision_maker_abci:0.1.0:bafybeie4k3s546hx4p5g3dtn75hlrysyh3ieslszexctwal4odmarx34fm
- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeiet3hqejz7rtutuzmvyl7wqwqqi2buqagryawav4yeuem45ohpr2e
- valory/decision_maker_abci:0.1.0:bafybeic2yjuwtfxekyukqgewbdnqc56ywuhn3pjgohjedzz7oaylbwqufy
- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeifdiag5des6schlumiyes2nvrlhi6nupvneup247iaswehttg7wqu
behaviours:
main:
args: {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ contracts: []
protocols: []
skills:
- valory/abstract_round_abci:0.1.0:bafybeid7neqpxxe4ualp23gxgrtpf6r5u3myr2mmc4uvwameyqshfdoydq
- valory/decision_maker_abci:0.1.0:bafybeie4k3s546hx4p5g3dtn75hlrysyh3ieslszexctwal4odmarx34fm
- valory/decision_maker_abci:0.1.0:bafybeic2yjuwtfxekyukqgewbdnqc56ywuhn3pjgohjedzz7oaylbwqufy
behaviours:
main:
args: {}
Expand Down
Loading

0 comments on commit f7894da

Please sign in to comment.