a lot of fixes

This commit is contained in:
2023-06-26 11:31:47 +02:00
parent 966db6e5ad
commit f60dca6367
23 changed files with 338 additions and 45 deletions

View File

@@ -23,4 +23,16 @@ class BaseAgent(ABC):
Resets agent to new episode.
"""
assert "No reset method has been provided"
pass
pass
def unregister(self):
"""
Disables agent by removing it from the simulation
"""
self.simulation.unregister_agent(id)
def register(self):
"""
Enables agent by adding it to the simulation:
"""
self.simulation.register_agent(self.id,self.tick,self.reset)

View File

@@ -9,7 +9,7 @@ class Base_Aquire_Agent(BaseAgent,ABC):
Agent for aquire of resources.
business: Business to aquire resources for.
resource: Resource to aquire.
exchanges: list of exchanges to aquire resources from
exchanges: list of exchanges to acquire resources from
"""
self.business=business
self.resource=resource

View File

@@ -90,8 +90,11 @@ class Base_Distribution_Agent(BaseAgent,ABC):
cx=self.exchanges[cx_id]
orders=self.orders[cx_id]
if len(orders)>0:
for o in orders:
trades.append(cx.order_trades_map[o.order_id])
for k,o in orders.items():
if k in cx.order_trades_map:
trades.append(cx.order_trades_map[k])
self.trades=trades
return trades

View File

@@ -8,7 +8,7 @@ class Price_Believe_Aquire_Agent(Base_Aquire_Agent):
super().__init__(simulation, business, resource, exchanges)
self.lr=lr
self.max_price_adj_rate=max_price_adj_rate
self.price_believe={i: 0 for i in range(len(self.exchanges))}
self.price_believe={i: 1 for i in range(len(self.exchanges))}
self.open_orders={i: [] for i in range(len(self.exchanges))}
self.open_qty=0
@@ -18,7 +18,7 @@ class Price_Believe_Aquire_Agent(Base_Aquire_Agent):
order_error=self.open_qty+self.target_error()
if order_error<0:
# aquire based on current price belive
# aquire based on current price believe
cx_id=self.select_best_cx()
order=self.order_resource(self.price_believe[cx_id],order_error*-1,cx_id)
if not order==None:
@@ -32,10 +32,14 @@ class Price_Believe_Aquire_Agent(Base_Aquire_Agent):
def select_best_cx(self):
best_id=-1
best=0
best=999999999
for cx_id in range(len(self.exchanges)):
cx=self.exchanges[cx_id]
potential=cx.get_total_supply(self.resource)*self.price_believe[cx_id]
available=(cx.get_total_supply(self.resource)>0)
if available:
potential=1*self.price_believe[cx_id]
else:
continue
if potential<best:
best=potential
best_id=cx_id

View File

@@ -8,7 +8,7 @@ class Price_Believe_Distribiute_Agent(Base_Distribution_Agent):
super().__init__(simulation, business, resource, exchanges)
self.lr=lr
self.max_price_adj_rate=max_price_adj_rate
self.price_believe={i: 0 for i in range(len(self.exchanges))}
self.price_believe={i: 1 for i in range(len(self.exchanges))}
self.open_orders={i: [] for i in range(len(self.exchanges))}
self.open_qty=0
@@ -24,10 +24,14 @@ class Price_Believe_Distribiute_Agent(Base_Distribution_Agent):
def select_best_cx(self):
best_id=-1
best=0
best=-1
for cx_id in range(len(self.exchanges)):
cx=self.exchanges[cx_id]
potential=cx.get_total_supply(self.resource)*self.price_believe[cx_id]
available=(cx.get_total_demand(self.resource)>0)
if available:
potential=1*self.price_believe[cx_id]
else:
continue
if potential>best:
best=potential
best_id=cx_id