reintroduced the finishTrade function
This commit is contained in:
parent
f7601aea3a
commit
0c5b7d5a02
@ -137,8 +137,9 @@ class TradingEngine implements TradingAPI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void finishTrade(Order b, Order a, double price, double volume) {
|
private void finishTrade(Order b, Order a, double price, double volume) {
|
||||||
|
|
||||||
// Transfer money and shares
|
// Transfer money and shares
|
||||||
transferMoneyAndShares(b.account, a.account, volume * price, -volume);
|
transferMoneyAndShares(b.account, a.account, volume * price, volume);
|
||||||
|
|
||||||
// Update volume
|
// Update volume
|
||||||
b.volume -= volume;
|
b.volume -= volume;
|
||||||
@ -149,6 +150,10 @@ class TradingEngine implements TradingAPI {
|
|||||||
|
|
||||||
removeOrderIfExecuted(a);
|
removeOrderIfExecuted(a);
|
||||||
removeOrderIfExecuted(b);
|
removeOrderIfExecuted(b);
|
||||||
|
|
||||||
|
a.account.notfiyListeners();
|
||||||
|
b.account.notfiyListeners();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void removeOrderIfExecuted(Order o) {
|
private void removeOrderIfExecuted(Order o) {
|
||||||
@ -168,7 +173,7 @@ class TradingEngine implements TradingAPI {
|
|||||||
// o.status = OrderStatus.CLOSED;
|
// o.status = OrderStatus.CLOSED;
|
||||||
// o.account.update(o);
|
// o.account.update(o);
|
||||||
}
|
}
|
||||||
Quote last_quote;
|
Quote last_quote = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -187,9 +192,12 @@ class TradingEngine implements TradingAPI {
|
|||||||
Order b = ul_buy.first();
|
Order b = ul_buy.first();
|
||||||
Double price = getBestPrice();
|
Double price = getBestPrice();
|
||||||
|
|
||||||
// if (price == null) {
|
if (price == null) {
|
||||||
// break;
|
// Threre is no price available, we can't match, we
|
||||||
// }
|
// have to wait until some limited orders come in
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
// double volume = b.volume >= a.volume ? a.volume : b.volume;
|
// double volume = b.volume >= a.volume ? a.volume : b.volume;
|
||||||
// finishTrade(b, a, price, volume);
|
// finishTrade(b, a, price, volume);
|
||||||
// volume_total += volume;
|
// volume_total += volume;
|
||||||
@ -260,21 +268,7 @@ class TradingEngine implements TradingAPI {
|
|||||||
double avdiff = b.limit * volume - price * volume;
|
double avdiff = b.limit * volume - price * volume;
|
||||||
b.account.addAvail(assetpair.getCurrency(), avdiff);
|
b.account.addAvail(assetpair.getCurrency(), avdiff);
|
||||||
|
|
||||||
// Transfer money and shares
|
finishTrade(b, a, price, volume);
|
||||||
transferMoneyAndShares(b.account, a.account, volume * price, volume);
|
|
||||||
|
|
||||||
// Update order volume
|
|
||||||
b.volume -= volume;
|
|
||||||
a.volume -= volume;
|
|
||||||
|
|
||||||
b.cost += price * volume;
|
|
||||||
a.cost += price * volume;
|
|
||||||
|
|
||||||
a.account.notfiyListeners();
|
|
||||||
b.account.notfiyListeners();
|
|
||||||
|
|
||||||
removeOrderIfExecuted(a);
|
|
||||||
removeOrderIfExecuted(b);
|
|
||||||
|
|
||||||
if (!compact_history) {
|
if (!compact_history) {
|
||||||
q = new Quote(quote_id_generator.getNext());
|
q = new Quote(quote_id_generator.getNext());
|
||||||
|
Loading…
Reference in New Issue
Block a user