Fixed formatting

This commit is contained in:
7u83 2018-12-29 11:14:04 +01:00
parent 0c5b7d5a02
commit 500204819c
1 changed files with 41 additions and 110 deletions

View File

@ -70,6 +70,7 @@ class TradingEngine implements TradingAPI {
AssetPair assetpair; AssetPair assetpair;
TreeSet<Quote> quote_history; TreeSet<Quote> quote_history;
Quote last_quote;
protected final void reset() { protected final void reset() {
order_books = new HashMap<>(); order_books = new HashMap<>();
@ -86,6 +87,12 @@ class TradingEngine implements TradingAPI {
quote_history = new TreeSet<>(); quote_history = new TreeSet<>();
last_quote = null;
Quote q = new Quote(-1);
q.price = 17.0;
last_quote = q;
// ohlc_data = new HashMap(); // ohlc_data = new HashMap();
} }
@ -173,7 +180,6 @@ class TradingEngine implements TradingAPI {
// o.status = OrderStatus.CLOSED; // o.status = OrderStatus.CLOSED;
// o.account.update(o); // o.account.update(o);
} }
Quote last_quote = null;
/** /**
* *
@ -285,8 +291,8 @@ class TradingEngine implements TradingAPI {
// statistics.trades++; // statistics.trades++;
// this.checkSLOrders(price); // this.checkSLOrders(price);
} }
if (volume_total
== 0) { if (volume_total == 0) {
return; return;
} }
@ -386,66 +392,39 @@ class TradingEngine implements TradingAPI {
} }
@Override @Override
public Order public Order createOrder(Account account, Order.Type type,
createOrder(Account account, double volume, double limit) {
Order.Type type,
double volume,
double limit
) {
Order o; Order o;
synchronized (account) { synchronized (account) {
// Round volume // Round volume
double v double v = assetpair.getAsset().roundToDecimals(volume);
= assetpair
.getAsset().roundToDecimals(volume
);
// Order volume must be grater than 0.0. // Order volume must be grater than 0.0.
if (v if (v <= 0.0) {
<= 0.0) {
return null; return null;
} }
// Round currency (limit) // Round currency (limit)
double l double l = assetpair.getCurrency().roundToDecimals(limit);
= assetpair
.getCurrency().roundToDecimals(limit
);
double order_limit; double order_limit;
switch (type) { switch (type) {
case BUYLIMIT: { case BUYLIMIT: {
// verfify available currency for a buy limit order // verfify available currency for a buy limit order
AbstractAsset currency AbstractAsset currency = this.assetpair.getCurrency();
= this.assetpair Double avail = account.getAvail(currency);
.getCurrency();
Double avail
= account
.getAvail(currency
);
// return if not enough money is available // return if not enough money is available
if (avail if (avail < v * l) {
< v
* l) {
return null; return null;
} }
// reduce the available money // reduce the available money
account.assets_avail account.assets_avail.put(currency, avail - v * l);
.put(currency, order_limit = l;
avail
- v
* l
);
order_limit
= l;
break; break;
} }
@ -453,29 +432,19 @@ class TradingEngine implements TradingAPI {
case BUY: { case BUY: {
// For an unlimited by order there is nothing to check // For an unlimited by order there is nothing to check
// other than currency is > 0.0 // other than currency is > 0.0
AbstractAsset currency AbstractAsset currency = this.assetpair.getCurrency();
= this.assetpair Double avail = account.getAvail(currency);
.getCurrency();
Double avail
= account
.getAvail(currency
);
if (avail if (avail <= 0.0) {
<= 0.0) {
return null; return null;
} }
// All available monney is assigned to this unlimited order // All available monney is assigned to this unlimited order
account.assets_avail account.assets_avail.put(currency, 0.0);
.put(currency,
0.0);
// we "mis"use order_limit to memorize occupied ammount \ // we "mis"use order_limit to memorize occupied ammount \
// of currency // of currency
order_limit order_limit = avail;
= avail;
break; break;
} }
@ -484,28 +453,16 @@ class TradingEngine implements TradingAPI {
case SELL: { case SELL: {
// verfiy sell limit // verfiy sell limit
AbstractAsset asset AbstractAsset asset = this.assetpair.getAsset();
= this.assetpair Double avail = account.getAvail(asset);
.getAsset();
Double avail
= account
.getAvail(asset
);
if (avail if (avail < v) {
< v) {
// 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, .put(asset, avail - v);
avail order_limit = l;
- v
);
order_limit
= l;
break; break;
} }
@ -515,70 +472,44 @@ class TradingEngine implements TradingAPI {
} }
o o = new Order(this, account, type, v, order_limit);
= new opensesim.world.Order(this, account,
type,
v,
order_limit
);
System.out //System.out.printf("The new Order has: volume: %f limit: %f\n", o.getVolume(), o.getLimit());
.printf("The new Order has: volume: %f limit: %f\n", o
.getVolume(), o
.getLimit());
synchronized (this) { synchronized (this) {
order_books order_books.get(o.type).add(o);
.get(o.type
).add(o
);
} }
} }
executeOrders(); executeOrders();
for (FiringEvent e for (FiringEvent e : book_listener) {
: book_listener) { e.fire();
e
.fire();
} }
return o; return o;
} }
HashSet<FiringEvent> book_listener HashSet<FiringEvent> book_listener = new HashSet<>();
= new HashSet<>();
@Override @Override
public void addOrderBookListener(EventListener listener public void addOrderBookListener(EventListener listener) {
) { book_listener.add(new FiringEvent(listener));
book_listener
.add(new FiringEvent(listener
));
} }
@Override @Override
public Set public Set getOrderBook(Order.Type type) {
getOrderBook(Order.Type type
) {
switch (type) { switch (type) {
case BUYLIMIT: case BUYLIMIT:
case BUY: case BUY:
return Collections return Collections.unmodifiableSet(bidbook);
.unmodifiableSet(bidbook
);
case SELLLIMIT: case SELLLIMIT:
case SELL: case SELL:
return Collections return Collections.unmodifiableSet(askbook);
.unmodifiableSet(askbook
);
} }
return null; return null;
// return Collections.unmodifiableSet(order_books.get(type));
} }
@Override @Override