Skip to content

Commit

Permalink
Market tweaks (#499)
Browse files Browse the repository at this point in the history
* split into own folder

* round the amounts

* sort the order book

* add test

* don't let one sell go to multiple buys
  • Loading branch information
vilterp authored Nov 25, 2024
1 parent 166f544 commit a35b5a0
Show file tree
Hide file tree
Showing 8 changed files with 833 additions and 957 deletions.
2 changes: 1 addition & 1 deletion apps/actors/systems/kvSync/ddTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export function kvSyncTests(writeResults: boolean): Suite {
name: "commodityMarket",
test() {
runDDTestAtPath(
"apps/actors/systems/kvSync/examples/commodityMarket.dd.txt",
"apps/actors/systems/kvSync/examples/commodityMarket/commodityMarket.dd.txt",
(inputs) => kvSyncTest(commodityMarket, inputs),
writeResults
);
Expand Down
328 changes: 0 additions & 328 deletions apps/actors/systems/kvSync/examples/commodityMarket.tsx

This file was deleted.

32 changes: 32 additions & 0 deletions apps/actors/systems/kvSync/examples/commodityMarket/choose.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { randomFromList, randStep2 } from "../../../../../../util/util";
import { ClientState } from "../../client";
import { MutationInvocation } from "../../types";
import { OrderSide } from "./types";

export function choose(
clients: {
[id: string]: ClientState;
},
randomSeed: number
): [{ clientID: string; invocation: MutationInvocation } | null, number] {
const [clientID, randomSeed1] = randomFromList(
randomSeed,
Object.keys(clients)
);

const [amount1, randomSeed2] = randStep2(randomSeed1);
const [price, randomSeed3] = randStep2(randomSeed2);
const side = randomFromList(randomSeed3, ["buy", "sell"])[0] as OrderSide;

return [
{
clientID,
invocation: {
type: "Invocation",
name: "Order",
args: [Math.round(price * 100), Math.round(amount1 * 100), side],
},
},
randomSeed3,
];
}
Loading

0 comments on commit a35b5a0

Please sign in to comment.