I've the following arrays as pending buy and sell orders:
$sell_orders = [
[amount => 500, price => 103],
[amount => 200, price => 102],
[amount => 150, price => 101],
[amount => 100, price => 100]
];
$buy_orders = [
[amount => 200, price => 98],
[amount => 150, price => 97]
];
$trades = [];
If now a user places a buy order, for example, of 500 units at price 102, first 100 units will be filled at price 100, next 150 units at 101, next 200 units at 102. The remaining (not filled) 50 units will be pushed to $buy_orders
array like:
$buy_orders = [
[amount => 50, price => 102],
[amount => 200, price => 98],
[amount => 150, price => 97]
];
Also I want to push trades at different prices to push to $trades
array like:
$trades = [
[amount => 100, price => 100],
[amount => 150, price => 101],
[amount => 200, price => 102]
];
Aucun commentaire:
Enregistrer un commentaire