Margin stuff

This commit is contained in:
7u83 2018-12-31 14:11:18 +01:00
parent d661de2892
commit 3853beac19
1 changed files with 15 additions and 9 deletions

View File

@ -220,7 +220,7 @@ class TradingEngine implements TradingAPI {
q.price = price; q.price = price;
q.volume = volume; q.volume = volume;
q.time = outer.world.currentTimeMillis(); q.time = outer.world.currentTimeMillis();
q.type = type; q.type = type;
addQuoteToHistory(q); addQuoteToHistory(q);
} }
@ -250,7 +250,6 @@ class TradingEngine implements TradingAPI {
this.checkSLOrders(price); this.checkSLOrders(price);
} }
*/ */
// //
// Match limited orders against limited orders // Match limited orders against limited orders
// //
@ -290,6 +289,8 @@ class TradingEngine implements TradingAPI {
// For sellers there is no need to update. // For sellers there is no need to update.
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);
// b.account.addMarginAvail(assetpair.getCurrency(), avdiff/b.account.getLeverage());
finishTrade(b, a, price, volume); finishTrade(b, a, price, volume);
@ -432,15 +433,21 @@ class TradingEngine implements TradingAPI {
case BUYLIMIT: { case BUYLIMIT: {
// verfify available currency for a buy limit order // verfify available currency for a buy limit order
AbstractAsset currency = this.assetpair.getCurrency(); AbstractAsset currency = this.assetpair.getCurrency();
Double avail = account.getAvail(currency); Double avail = 0.0; ///account.getMarginAvail(currency);
Double margin = account.getValue(assetpair.getCurrency());
// return if not enough money is available // return if not enough money is available
if (avail < v * l) { if (avail * account.getLeverage() < v * l) {
return null; // return null;
} }
// reduce the available money // reduce the available money
account.assets_avail.put(currency, avail - v * l); // account.assets_avail.put(currency, avail - v * l);
account.addAvail(currency, -(v * l));
//account.addMarginAvail(currency, -((v * l)/account.getLeverage()));
order_limit = l; order_limit = l;
break; break;
@ -477,8 +484,7 @@ class TradingEngine implements TradingAPI {
// not enough items of asset (shares) available // not enough items of asset (shares) available
return null; return null;
} }
account.assets_avail account.assets_avail.put(asset, avail - v);
.put(asset, avail - v);
order_limit = l; order_limit = l;
break; break;
@ -498,7 +504,7 @@ class TradingEngine implements TradingAPI {
} }
} }
executeOrders(); executeOrders();
last_quote.price=200;
for (FiringEvent e : book_listener) { for (FiringEvent e : book_listener) {
e.fire(); e.fire();
} }