Skip to content

Commit

Permalink
add unused supply_orders to rejected_orders
Browse files Browse the repository at this point in the history
clean up setting accepted_volume and price on rejected orders
fix setting the volume of the split order in clearing
  • Loading branch information
maurerle committed Sep 15, 2023
1 parent 7f12324 commit 0d5e42d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 19 deletions.
3 changes: 3 additions & 0 deletions assume/markets/base_market.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,9 @@ async def clear_market(self, market_products: list[MarketProduct]):
market_meta,
) = self.clear(self.all_orders, market_products)
self.all_orders = []
for order in rejected_orderbook:
order["accepted_volume"] = 0
order["accepted_price"] = 0
self.open_auctions - set(market_products)
# self.all_orders = pending_orderbook

Expand Down
12 changes: 0 additions & 12 deletions assume/markets/clearing_algorithms/all_or_nothing.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,6 @@ def clear(
# resulting i is the cut point
accepted_product_orders.extend(demand_orders[:i])
accepted_product_orders.extend(supply_orders[:i])

for order in supply_orders[i:]:
order["accepted_volume"] = 0
for order in demand_orders[i:]:
order["accepted_volume"] = 0

rejected_orders.extend(demand_orders[i:])
rejected_orders.extend(supply_orders[i:])

Expand Down Expand Up @@ -168,12 +162,6 @@ def clear(

accepted_product_orders.extend(demand_orders[:i])
accepted_product_orders.extend(supply_orders[:i])

for order in supply_orders[i:]:
order["accepted_volume"] = 0
for order in demand_orders[i:]:
order["accepted_volume"] = 0

rejected_orders.extend(demand_orders[i:])
rejected_orders.extend(supply_orders[i:])

Expand Down
16 changes: 9 additions & 7 deletions assume/markets/clearing_algorithms/simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ def clear(
for demand_order in demand_orders:
if not supply_orders:
# if no more generation - reject left over demand
demand_order["accepted_volume"] = 0
rejected_orders.append(demand_order)
continue

Expand All @@ -100,7 +99,6 @@ def clear(
to_commit.append(supply_order)
gen_vol += supply_order["volume"]
else:
supply_order["accepted_volume"] = 0
rejected_orders.append(supply_order)
# now we know which orders we need
# we only need to see how to arrange it.
Expand All @@ -118,7 +116,7 @@ def clear(
# generation left over - split last generation bid
supply_order = to_commit[-1]
split_supply_order = supply_order.copy()
split_supply_order["accepted_volume"] = diff
split_supply_order["volume"] = diff
supply_order["accepted_volume"] = supply_order["volume"] - diff
# changed supply_order is still part of to_commit and will be added
# only volume-diff can be sold for current price
Expand All @@ -133,6 +131,9 @@ def clear(
accepted_product_orders.append(demand_order)
accepted_product_orders.extend(to_commit)

for order in supply_orders:
rejected_orders.append(order)

# set clearing price - merit order - uniform pricing
accepted_supply_orders = [
x for x in accepted_product_orders if x["accepted_volume"] > 0
Expand Down Expand Up @@ -204,7 +205,6 @@ def clear(
for demand_order in demand_orders:
if not supply_orders:
# if no more generation - reject left over demand
demand_order["accepted_volume"] = 0
rejected_orders.append(demand_order)
continue

Expand All @@ -218,7 +218,6 @@ def clear(
to_commit.append(supply_order)
gen_vol += supply_order["volume"]
else:
supply_order["accepted_volume"] = 0
rejected_orders.append(supply_order)
# now we know which orders we need
# we only need to see how to arrange it.
Expand All @@ -236,8 +235,8 @@ def clear(
# generation left over - split generation
supply_order = to_commit[-1]
split_supply_order = supply_order.copy()
split_supply_order["accepted_volume"] = diff
supply_order["accepted_volume"] -= supply_order["volume"] - diff
split_supply_order["volume"] = diff
supply_order["accepted_volume"] = supply_order["volume"] - diff
# only volume-diff can be sold for current price
# add left over to supply_orders again
gen_vol -= diff
Expand All @@ -255,6 +254,9 @@ def clear(
demand_order["accepted_price"] = supply_order["price"]
accepted_product_orders.extend(to_commit)

for order in supply_orders:
rejected_orders.append(order)

accepted_supply_orders = [
x for x in accepted_product_orders if x["accepted_volume"] > 0
]
Expand Down

0 comments on commit 0d5e42d

Please sign in to comment.