Skip to content

Instantly share code, notes, and snippets.

@yurenju
Last active December 15, 2019 03:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yurenju/13f58c1c3f3265a15a7c9e6501f1cfb6 to your computer and use it in GitHub Desktop.
Save yurenju/13f58c1c3f3265a15a7c9e6501f1cfb6 to your computer and use it in GitHub Desktop.
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