worknig on new random trader

This commit is contained in:
2017-01-12 01:00:42 +01:00
parent d866f33fea
commit 80e48e1ee0
6 changed files with 124 additions and 24 deletions

View File

@ -352,12 +352,36 @@ public class Exchange extends Thread {
src.shares -= shares;
dst.shares += shares;
}
public boolean cancelOrder(double account_id, long order_id){
Account a = accounts.get(account_id);
if (a==null){
return false;
}
boolean ret=false;
tradelock.lock();
Order o = a.orders.get(order_id);
if (o != null){
order_books.get(o.type).remove(o);
a.orders.remove(o.id);
ret=true;
}
tradelock.unlock();
this.updateBookReceivers(OrderType.BID);
return ret;
}
/**
*
* @param o
*/
public void cancelOrder(Order_old o) {
public void cancelOrder_old(Order_old o) {
tradelock.lock();
TreeSet<Order_old> book = this.selectOrderBook(o.type);
book.remove(o);
@ -613,7 +637,9 @@ public class Exchange extends Thread {
addOrderToBook(o);
a.orders.put(o.id, o);
tradelock.lock();
this.executeOrders();
tradelock.unlock();
this.updateBookReceivers(OrderType.ASK);
this.updateBookReceivers(OrderType.BID);
return o.id;
@ -645,6 +671,32 @@ public class Exchange extends Thread {
ad.id = account_id;
ad.money = a.money;
ad.shares = a.shares;
ad.orders=new ArrayList<OrderData>();
ad.orders.iterator();
a.orders.values();
Set s =a.orders.keySet();
Iterator it = s.iterator();
System.out.print("Keys list"+s.size()+"\n");
while (it.hasNext()){
long x = (long)it.next();
System.out.print("X"+x+"\n");
Order o = a.orders.get(x);
System.out.print("oGot: "+o.limit+" "+o.volume+"\n");
OrderData od = new OrderData();
od.id=o.id;
od.limit=o.limit;
od.volume=o.volume;
ad.orders.add(od);
}
//System.exit(0);
//a.orders.keySet();
//KeySet ks = a.orders.keySet();
return ad;
}

View File

@ -30,9 +30,9 @@ package sesim;
* @author 7u83 <7u83@mail.ru>
*/
public class OrderData {
long id;
double limit;
double volume;
double executed;
public long id;
public double limit;
public double volume;
public double executed;
}