Interface improved
This commit is contained in:
parent
80e48e1ee0
commit
68d7925f82
@ -16,8 +16,6 @@ public class Exchange extends Thread {
|
||||
BID, ASK
|
||||
}
|
||||
|
||||
|
||||
|
||||
IDGenerator account_id = new IDGenerator();
|
||||
|
||||
private class Account implements Comparable {
|
||||
@ -77,7 +75,15 @@ public class Exchange extends Thread {
|
||||
return d > 0 ? 1 : -1;
|
||||
}
|
||||
|
||||
return left.id < right.id ? -1 : 1;
|
||||
if(left.id<right.id)
|
||||
return -1;
|
||||
if(left.id>right.id)
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
|
||||
|
||||
// return left.id < right.id ? -1 : 1;
|
||||
}
|
||||
|
||||
}
|
||||
@ -277,6 +283,7 @@ public class Exchange extends Thread {
|
||||
}
|
||||
|
||||
public class OrderBookItem {
|
||||
|
||||
public long id;
|
||||
public double limit;
|
||||
public double volume;
|
||||
@ -353,7 +360,6 @@ public class Exchange extends Thread {
|
||||
dst.shares += shares;
|
||||
}
|
||||
|
||||
|
||||
public boolean cancelOrder(double account_id, long order_id) {
|
||||
Account a = accounts.get(account_id);
|
||||
if (a == null) {
|
||||
@ -364,13 +370,26 @@ public class Exchange extends Thread {
|
||||
|
||||
tradelock.lock();
|
||||
Order o = a.orders.get(order_id);
|
||||
|
||||
// System.out.print("The Order:"+o.limit+"\n");
|
||||
|
||||
if (o != null) {
|
||||
order_books.get(o.type).remove(o);
|
||||
TreeSet ob =order_books.get(o.type);
|
||||
|
||||
System.out.print("We have the orderbook"+ob.size()+"\n");
|
||||
|
||||
System.out.print("Want to remove:"+o.limit+" "+o.volume+" "+o.id+"\n");
|
||||
|
||||
|
||||
|
||||
boolean rc = ob.remove(o);
|
||||
|
||||
|
||||
System.out.print("My first rc = :" + rc);
|
||||
a.orders.remove(o.id);
|
||||
ret = true;
|
||||
}
|
||||
|
||||
|
||||
tradelock.unlock();
|
||||
this.updateBookReceivers(OrderType.BID);
|
||||
|
||||
@ -460,7 +479,6 @@ public class Exchange extends Thread {
|
||||
|
||||
}
|
||||
|
||||
|
||||
Quote q = new Quote();
|
||||
q.price = money_total / volume_total;
|
||||
q.volume = volume_total;
|
||||
@ -645,7 +663,6 @@ public class Exchange extends Thread {
|
||||
return o.id;
|
||||
}
|
||||
|
||||
|
||||
public double getBestLimit(OrderType type) {
|
||||
Order o = order_books.get(type).first();
|
||||
if (o == null) {
|
||||
@ -656,8 +673,9 @@ public class Exchange extends Thread {
|
||||
|
||||
public int getNumberOfOpenOrders(double account_id) {
|
||||
Account a = accounts.get(account_id);
|
||||
if (a==null)
|
||||
if (a == null) {
|
||||
return 0;
|
||||
}
|
||||
return a.orders.size();
|
||||
}
|
||||
|
||||
@ -672,7 +690,6 @@ public class Exchange extends Thread {
|
||||
ad.money = a.money;
|
||||
ad.shares = a.shares;
|
||||
|
||||
|
||||
ad.orders = new ArrayList<OrderData>();
|
||||
ad.orders.iterator();
|
||||
|
||||
@ -693,18 +710,17 @@ public class Exchange extends Thread {
|
||||
}
|
||||
|
||||
//System.exit(0);
|
||||
|
||||
//a.orders.keySet();
|
||||
//KeySet ks = a.orders.keySet();
|
||||
|
||||
return ad;
|
||||
}
|
||||
|
||||
public ArrayList<OrderData> getOpenOrders(double account_id) {
|
||||
|
||||
Account a = accounts.get(account_id);
|
||||
if (a==null)
|
||||
if (a == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
ArrayList<OrderData> al = new ArrayList();
|
||||
|
||||
|
@ -54,9 +54,9 @@ public class RandomTrader extends AutoTrader {
|
||||
long event(){
|
||||
|
||||
System.out.print("Hello world Iam a trader\n");
|
||||
this.cancelOrders();
|
||||
return this.cancelOrders();
|
||||
// doBuy();
|
||||
return 10000;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -142,13 +142,12 @@ public class RandomTrader extends AutoTrader {
|
||||
System.out.print("Killing: "+od.id+"\n");
|
||||
}
|
||||
}
|
||||
else{
|
||||
|
||||
doBuy();
|
||||
}
|
||||
|
||||
|
||||
|
||||
return 10000;
|
||||
return 15000;
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user