Last active
December 15, 2019 03:56
-
-
Save yurenju/13f58c1c3f3265a15a7c9e6501f1cfb6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Trader(Agent): | |
def __init__(self, unique_id, model, eth, dai, is_arbitrageur): | |
super().__init__(unique_id, model) | |
self.eth = eth | |
self.dai = dai | |
self.is_arbitrageur = is_arbitrageur | |
def buy_eth(self): | |
amount = min(random.random() * 1000, self.dai) | |
self.model.uniswap.trade(self, "eth", amount) | |
def buy_dai(self): | |
amount = min(random.random() * 10, self.eth) | |
self.model.uniswap.trade(self, "dai", amount) | |
def step(self): | |
uniswap = self.model.uniswap | |
if self.is_arbitrageur: | |
if (uniswap.external_price > uniswap.get_price()): | |
self.buy_eth() | |
else: | |
self.buy_dai() | |
else: | |
if random.random() > 0.5: | |
self.buy_eth() | |
else: | |
self.buy_dai() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment