examples/blocks/src/market/README.md
A simple market simulation implemented in Perspective, designed to be simple rather than accurate. The simulation proceeds in steps:
Table using the "max" or "min" aggregates
(respectively).{
columns: ["price"],
group_by: ["security"],
aggregates: { price: "max" },
filter: [
["side", "==", "buy"],
["status", "==", "open"],
],
}
Table. To match orders, we fetch all open
orders on both sides which are outside of the best price, then update an
equal number of both "buy" and "sell" side orders to "closed". The
sort field guarantees that orders are closed in best, then oldest, order.{
columns: ["id"],
filter: [
["side", "==", "buy"],
["status", "==", "open"],
["price", ">", price],
],
sort: [
["price", "desc"],
["timestamp", "asc"],
],
}
"open" by fetching orders older
than the expiration ID and update thair status' to "expired".{
columns: ["id"],
filter: [
["status", "==", "open"],
["id", "<", 12345],
],
}