something something i broke it meh
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -89,6 +89,14 @@ class Price_Believe_Aquire_Agent(Base_Aquire_Agent):
|
||||
else:
|
||||
# timeout
|
||||
self.update_trades()
|
||||
buy = o.qty-o.leaves_qty
|
||||
buyp=buy/o.qty
|
||||
sup = cx.total_supply[self.resource]+buy
|
||||
if sup == 0:
|
||||
sup = 1
|
||||
coverage = buy/sup
|
||||
# 50 % coverage limit
|
||||
modifier = (max([coverage,buyp])*2)-1
|
||||
cx.cancel_order(i["id"])
|
||||
self.collect_balance_from_cxs()
|
||||
self.collect_resource_from_cxs(self.resource)
|
||||
|
||||
@@ -22,9 +22,9 @@ class Price_Believe_Distribiute_Agent(Base_Distribution_Agent):
|
||||
# aquire based on current price belive
|
||||
cx_id = self.select_best_cx()
|
||||
|
||||
price=round(self.price_believe[cx_id])
|
||||
if price<self.min_price:
|
||||
price=self.min_price
|
||||
price = round(self.price_believe[cx_id])
|
||||
if price < self.min_price:
|
||||
price = self.min_price
|
||||
order = self.distribute_resource(
|
||||
price, order_error, cx_id)
|
||||
self.register_order(cx_id, order)
|
||||
@@ -53,7 +53,7 @@ class Price_Believe_Distribiute_Agent(Base_Distribution_Agent):
|
||||
'lifetime': self.max_price_adj_rate,
|
||||
'leaves': order.leaves_qty
|
||||
})
|
||||
if order.leaves_qty!=order.qty:
|
||||
if order.leaves_qty != order.qty:
|
||||
self.update_trades()
|
||||
|
||||
def tick_open_orders(self) -> int:
|
||||
@@ -68,22 +68,32 @@ class Price_Believe_Distribiute_Agent(Base_Distribution_Agent):
|
||||
for i in cx_orders:
|
||||
# Check for each order if it is fullfiled or if it is timed
|
||||
o = self.orders[cx_id][i["id"]]
|
||||
leaves=o.leaves_qty
|
||||
leaves = o.leaves_qty
|
||||
if o.leaves_qty == 0:
|
||||
# order is done
|
||||
self.open_orders[cx_id].remove(i) # remove order from open
|
||||
self.update_believe(cx_id, 1) # update price believe
|
||||
sold = o.qty-o.leaves_qty
|
||||
if o.qty==0:
|
||||
o.qty=1
|
||||
soldperc=sold/o.qty
|
||||
dem = cx.total_demand[self.resource]+sold
|
||||
if dem == 0:
|
||||
dem = 1
|
||||
coverage = sold/dem
|
||||
# 50 % coverage limit
|
||||
modifier = (max([coverage,soldperc])*2)-1
|
||||
self.update_believe(cx_id, modifier) # update price believe
|
||||
self.collect_balance_from_cxs()
|
||||
self.collect_resource_from_cxs(self.resource)
|
||||
self.update_trades()
|
||||
continue
|
||||
|
||||
if not (i["leaves"]==leaves):
|
||||
#update in order
|
||||
i["leaves"]=leaves
|
||||
|
||||
if not (i["leaves"] == leaves):
|
||||
# update in order
|
||||
i["leaves"] = leaves
|
||||
self.update_trades()
|
||||
#reset lifetime
|
||||
i["lifetime"]=self.max_price_adj_rate
|
||||
# reset lifetime
|
||||
#i["lifetime"] = self.max_price_adj_rate
|
||||
|
||||
if i["lifetime"] > 0:
|
||||
self.open_qty += o.leaves_qty
|
||||
@@ -91,10 +101,19 @@ class Price_Believe_Distribiute_Agent(Base_Distribution_Agent):
|
||||
else:
|
||||
# timeout
|
||||
self.update_trades()
|
||||
|
||||
sold = o.qty-o.leaves_qty
|
||||
soldperc=sold/o.qty
|
||||
dem = cx.total_demand[self.resource]+sold
|
||||
if dem == 0:
|
||||
dem = 1
|
||||
coverage = sold/dem
|
||||
# 50 % coverage limit
|
||||
modifier = (max([coverage,soldperc])*2)-1
|
||||
cx.cancel_order(i["id"])
|
||||
self.collect_balance_from_cxs()
|
||||
self.collect_resource_from_cxs(self.resource)
|
||||
self.update_believe(cx_id, -1)
|
||||
self.update_believe(cx_id, modifier)
|
||||
self.open_orders[cx_id].remove(i)
|
||||
|
||||
def update_believe(self, cx_id, modifier):
|
||||
@@ -104,6 +123,7 @@ class Price_Believe_Distribiute_Agent(Base_Distribution_Agent):
|
||||
If negative will sub lr to believe
|
||||
"""
|
||||
self.price_believe[cx_id] += modifier*self.lr
|
||||
self.price_believe[cx_id] = round(self.price_believe[cx_id], 2)
|
||||
if self.price_believe[cx_id] < 1:
|
||||
self.price_believe[cx_id] = 1
|
||||
|
||||
|
||||
Reference in New Issue
Block a user