-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
Showing
8 changed files
with
833 additions
and
957 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
328 changes: 0 additions & 328 deletions
328
apps/actors/systems/kvSync/examples/commodityMarket.tsx
This file was deleted.
Oops, something went wrong.
32 changes: 32 additions & 0 deletions
32
apps/actors/systems/kvSync/examples/commodityMarket/choose.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
]; | ||
} |
Oops, something went wrong.