I'm trying to build a mock asset exchange in PHP. For a given asset, XYZ, below is the orderbook:
| buy_price | amount | sell_price | amount |
|-----------|--------|------------|--------|
| 99.3 | 100 | 99.6 | 110 |
| 99.2 | 150 | 99.7 | 170 |
| 99.1 | 125 | 99.8 | 200 |
Now if a user places a buy order of 400 units at market price, the orders will be executed as follows:
110 units filled at 99.6
170 units filled at 99.7
120 units filled at 99.8
How would I conditionally loop through open sell orders so that the buy order of 400 units are filled at different existing sell order prices in orderbook? I'd also like to store the executed trades arrays like:
$trade1 = ["amount" => 110, "price" => 99.6]
$trade2 = ["amount" => 170, "price" => 99.7]
$trade3 = ["amount" => 120, "price" => 99.8]
Aucun commentaire:
Enregistrer un commentaire