Removed Order Id
This commit is contained in:
parent
c3812b7660
commit
e3ed6d1043
@ -1,4 +1,4 @@
|
|||||||
#Sun, 10 Dec 2017 23:09:50 +0100
|
#Mon, 11 Dec 2017 16:05:46 +0100
|
||||||
annotation.processing.enabled=true
|
annotation.processing.enabled=true
|
||||||
annotation.processing.enabled.in.editor=false
|
annotation.processing.enabled.in.editor=false
|
||||||
annotation.processing.processors.list=
|
annotation.processing.processors.list=
|
||||||
|
@ -228,8 +228,10 @@ public class OpenOrdersList extends javax.swing.JPanel {
|
|||||||
int r = table.getSelectedRow();
|
int r = table.getSelectedRow();
|
||||||
Long id = (Long) model.getValueAt(r, 0);
|
Long id = (Long) model.getValueAt(r, 0);
|
||||||
|
|
||||||
|
Order co = account.getOrders().get(id);
|
||||||
|
|
||||||
System.out.printf("Should cancel %d\n", id);
|
System.out.printf("Should cancel %d\n", id);
|
||||||
Globals.se.cancelOrder(account.getID(), id);
|
Globals.se.cancelOrder(account.getID(), co);
|
||||||
|
|
||||||
}//GEN-LAST:event_ctxMenuCancelOrderActionPerformed
|
}//GEN-LAST:event_ctxMenuCancelOrderActionPerformed
|
||||||
|
|
||||||
|
@ -32,8 +32,6 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||||||
*/
|
*/
|
||||||
public class Account implements Comparable {
|
public class Account implements Comparable {
|
||||||
|
|
||||||
static String default_symbold = "DFLT";
|
|
||||||
|
|
||||||
private Exchange.AccountListener listener = null;
|
private Exchange.AccountListener listener = null;
|
||||||
|
|
||||||
protected final double id;
|
protected final double id;
|
||||||
|
@ -640,42 +640,9 @@ public class Exchange {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param stock
|
|
||||||
* @param type
|
|
||||||
* @param depth
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public ArrayList<Order> getOrderBook(Stock stock, OrderType type, int depth) {
|
|
||||||
|
|
||||||
SortedSet<Order> book = stock.order_books.get(type);
|
|
||||||
if (book == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
ArrayList<Order> ret;
|
|
||||||
synchronized (stock) {
|
|
||||||
|
|
||||||
ret = new ArrayList<>();
|
|
||||||
|
|
||||||
Iterator<Order> it = book.iterator();
|
|
||||||
|
|
||||||
for (int i = 0; i < depth && it.hasNext(); i++) {
|
|
||||||
Order o = it.next();
|
|
||||||
// System.out.print(o.volume);
|
|
||||||
if (o.volume <= 0) {
|
|
||||||
System.out.printf("Volume < 0\n");
|
|
||||||
System.exit(0);
|
|
||||||
}
|
|
||||||
ret.add(o);
|
|
||||||
}
|
|
||||||
// System.out.println();
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ArrayList<Order> getOrderBook(OrderType type, int depth) {
|
public ArrayList<Order> getOrderBook(OrderType type, int depth) {
|
||||||
return getOrderBook(getDefaultStock(), type, depth);
|
return getDefaultStock().getOrderBook(type, depth);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -740,8 +707,9 @@ public class Exchange {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean cancelOrder(double account_id, long order_id) {
|
public boolean cancelOrder(double account_id, Order order) {
|
||||||
return cancelOrder(getDefaultStock(), account_id, order_id);
|
|
||||||
|
return cancelOrder(getDefaultStock(), account_id, order.getID());
|
||||||
}
|
}
|
||||||
|
|
||||||
Random random;
|
Random random;
|
||||||
@ -972,23 +940,21 @@ public class Exchange {
|
|||||||
* @param limit
|
* @param limit
|
||||||
* @return order_id
|
* @return order_id
|
||||||
*/
|
*/
|
||||||
public long createOrder(double account_id,
|
public Order createOrder(double account_id,
|
||||||
String stocksymbol, OrderType type, double volume, double limit) {
|
String stocksymbol, OrderType type, double volume, double limit) {
|
||||||
|
|
||||||
Stock stock = getStock(stocksymbol);
|
Stock stock = getStock(stocksymbol);
|
||||||
|
|
||||||
Account a = accounts.get(account_id);
|
Account a = accounts.get(account_id);
|
||||||
if (a == null) {
|
if (a == null) {
|
||||||
return -1;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Order o = new Order(order_id_generator.getNext(),
|
Order o = new Order(order_id_generator.getNext(),
|
||||||
timer.currentTimeMillis(),
|
timer.currentTimeMillis(),
|
||||||
a, type, roundShares(volume), roundMoney(limit));
|
a, stock, type, roundShares(volume), roundMoney(limit));
|
||||||
|
|
||||||
o.stock = stock;
|
if (o.volume <= 0 || o.limit <= 0) {
|
||||||
|
|
||||||
if (o.volume <= 0 || o.limit <= 0) {
|
|
||||||
|
|
||||||
switch (o.type) {
|
switch (o.type) {
|
||||||
case SELL:
|
case SELL:
|
||||||
@ -1001,7 +967,7 @@ public class Exchange {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
return o;
|
||||||
}
|
}
|
||||||
|
|
||||||
synchronized (stock) {
|
synchronized (stock) {
|
||||||
@ -1022,7 +988,7 @@ public class Exchange {
|
|||||||
// executor.notify();
|
// executor.notify();
|
||||||
}
|
}
|
||||||
// a.update(o);
|
// a.update(o);
|
||||||
return o.getID();
|
return o;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getBestLimit(Stock stock, OrderType type) {
|
public double getBestLimit(Stock stock, OrderType type) {
|
||||||
|
@ -45,9 +45,9 @@ public class Order {
|
|||||||
BUYLIMIT, SELLLIMIT, STOPLOSS, STOPBUY, BUY, SELL
|
BUYLIMIT, SELLLIMIT, STOPLOSS, STOPBUY, BUY, SELL
|
||||||
}
|
}
|
||||||
|
|
||||||
Stock stock;
|
protected final Stock stock;
|
||||||
OrderStatus status;
|
protected OrderStatus status;
|
||||||
OrderType type;
|
protected OrderType type;
|
||||||
protected double limit;
|
protected double limit;
|
||||||
protected double volume;
|
protected double volume;
|
||||||
|
|
||||||
@ -59,8 +59,8 @@ public class Order {
|
|||||||
|
|
||||||
double cost;
|
double cost;
|
||||||
|
|
||||||
Order(long id, long created, Account account, OrderType type, double volume, double limit) {
|
Order(long id, long created, Account account, Stock stock, OrderType type,
|
||||||
//id = order_id_generator.getNext();
|
double volume, double limit) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.account = account;
|
this.account = account;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
@ -69,6 +69,7 @@ public class Order {
|
|||||||
this.initial_volume = this.volume;
|
this.initial_volume = this.volume;
|
||||||
this.created = created;
|
this.created = created;
|
||||||
this.status = OrderStatus.OPEN;
|
this.status = OrderStatus.OPEN;
|
||||||
|
this.stock=stock;
|
||||||
this.cost = 0;
|
this.cost = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,4 +120,13 @@ public class Order {
|
|||||||
public long getCreated() {
|
public long getCreated() {
|
||||||
return created;
|
return created;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the stock symbol that this order belongs to
|
||||||
|
* @return Stock symbol
|
||||||
|
*/
|
||||||
|
public String getStockSymbol(){
|
||||||
|
return stock.getSymbol();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
*/
|
*/
|
||||||
package sesim;
|
package sesim;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.SortedSet;
|
import java.util.SortedSet;
|
||||||
@ -131,4 +132,38 @@ public class Stock {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param stock
|
||||||
|
* @param type
|
||||||
|
* @param depth
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public ArrayList<Order> getOrderBook(Order.OrderType type, int depth) {
|
||||||
|
|
||||||
|
SortedSet<Order> book = order_books.get(type);
|
||||||
|
if (book == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
ArrayList<Order> ret;
|
||||||
|
synchronized (this) {
|
||||||
|
|
||||||
|
ret = new ArrayList<>();
|
||||||
|
|
||||||
|
Iterator<Order> it = book.iterator();
|
||||||
|
|
||||||
|
for (int i = 0; i < depth && it.hasNext(); i++) {
|
||||||
|
Order o = it.next();
|
||||||
|
|
||||||
|
if (o.volume <= 0) {
|
||||||
|
// throw an exception here
|
||||||
|
}
|
||||||
|
ret.add(o);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,7 @@ package traders.ManTrader;
|
|||||||
import gui.OpenOrdersList;
|
import gui.OpenOrdersList;
|
||||||
|
|
||||||
import sesim.Exchange;
|
import sesim.Exchange;
|
||||||
|
import sesim.Order;
|
||||||
import sesim.Order.OrderType;
|
import sesim.Order.OrderType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -176,7 +177,7 @@ public class ManTraderConsole extends javax.swing.JPanel {
|
|||||||
|
|
||||||
System.out.printf("Should buy: %f %f\n",volume,limit);
|
System.out.printf("Should buy: %f %f\n",volume,limit);
|
||||||
|
|
||||||
long createOrder = trader.getSE().createOrder(trader.getAccount().getID(),
|
Order createOrder = trader.getSE().createOrder(trader.getAccount().getID(),
|
||||||
trader.getSE().getDefaultStockSymbol(),
|
trader.getSE().getDefaultStockSymbol(),
|
||||||
OrderType.BUYLIMIT, volume, limit);
|
OrderType.BUYLIMIT, volume, limit);
|
||||||
System.out.printf("The retval is %d",createOrder);
|
System.out.printf("The retval is %d",createOrder);
|
||||||
@ -193,7 +194,7 @@ public class ManTraderConsole extends javax.swing.JPanel {
|
|||||||
|
|
||||||
System.out.printf("Should sell: %f %f\n",volume,limit);
|
System.out.printf("Should sell: %f %f\n",volume,limit);
|
||||||
|
|
||||||
long createOrder = trader.getSE().createOrder(trader.getAccount().getID(),
|
Order createOrder = trader.getSE().createOrder(trader.getAccount().getID(),
|
||||||
trader.getSE().getDefaultStockSymbol(),
|
trader.getSE().getDefaultStockSymbol(),
|
||||||
OrderType.SELLLIMIT, volume, limit);
|
OrderType.SELLLIMIT, volume, limit);
|
||||||
System.out.printf("The retval is %d",createOrder);
|
System.out.printf("The retval is %d",createOrder);
|
||||||
@ -205,7 +206,7 @@ public class ManTraderConsole extends javax.swing.JPanel {
|
|||||||
|
|
||||||
System.out.printf("Should stoploss: %f %f\n",volume,limit);
|
System.out.printf("Should stoploss: %f %f\n",volume,limit);
|
||||||
|
|
||||||
long createOrder = trader.getSE().createOrder(trader.getAccount().getID(),
|
Order createOrder = trader.getSE().createOrder(trader.getAccount().getID(),
|
||||||
trader.getSE().getDefaultStockSymbol(),
|
trader.getSE().getDefaultStockSymbol(),
|
||||||
OrderType.STOPLOSS, volume, limit);
|
OrderType.STOPLOSS, volume, limit);
|
||||||
System.out.printf("The retval is %d",createOrder);
|
System.out.printf("The retval is %d",createOrder);
|
||||||
|
@ -184,13 +184,15 @@ public class RandomTraderA extends AutoTraderBase implements AccountListener {
|
|||||||
if (n > 0) {
|
if (n > 0) {
|
||||||
Account ad = se.getAccount(account_id);
|
Account ad = se.getAccount(account_id);
|
||||||
|
|
||||||
|
|
||||||
Set<Long> keys = ad.getOrders().keySet();
|
Set<Long> keys = ad.getOrders().keySet();
|
||||||
|
|
||||||
Iterator<Long> it = keys.iterator();
|
Iterator<Long> it = keys.iterator();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
// Order od = it.next();
|
Order od = ad.getOrders().get(it.next());
|
||||||
boolean rc = se.cancelOrder(account_id, it.next());
|
boolean rc = se.cancelOrder(account_id, od);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return n;
|
return n;
|
||||||
|
|
||||||
@ -405,9 +407,9 @@ public class RandomTraderA extends AutoTraderBase implements AccountListener {
|
|||||||
// System.out.printf("Buy Order wont work\n");
|
// System.out.printf("Buy Order wont work\n");
|
||||||
// return false;
|
// return false;
|
||||||
// }
|
// }
|
||||||
long rc = se.createOrder(account_id, se.getDefaultStockSymbol(),type, volume, limit);
|
Order rc = se.createOrder(account_id, se.getDefaultStockSymbol(),type, volume, limit);
|
||||||
|
|
||||||
if (rc == -1) {
|
if (rc == null) {
|
||||||
|
|
||||||
// System.out.printf("Buy failed %f, %f / %f (%f)\n", volume, money, limit, ad.getMoney());
|
// System.out.printf("Buy failed %f, %f / %f (%f)\n", volume, money, limit, ad.getMoney());
|
||||||
return false;
|
return false;
|
||||||
@ -445,8 +447,8 @@ public class RandomTraderA extends AutoTraderBase implements AccountListener {
|
|||||||
// return false;
|
// return false;
|
||||||
// }
|
// }
|
||||||
// System.out.printf("Create a Sell Order %f %f!!!!\n", volume, limit);
|
// System.out.printf("Create a Sell Order %f %f!!!!\n", volume, limit);
|
||||||
long rc = se.createOrder(account_id, se.getDefaultStockSymbol(), type, volume, limit);
|
Order rc = se.createOrder(account_id, se.getDefaultStockSymbol(), type, volume, limit);
|
||||||
return rc != -1;
|
return rc != null;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,6 +36,7 @@ import org.json.JSONObject;
|
|||||||
import sesim.AutoTraderBase;
|
import sesim.AutoTraderBase;
|
||||||
import sesim.AutoTraderGui;
|
import sesim.AutoTraderGui;
|
||||||
import sesim.Account;
|
import sesim.Account;
|
||||||
|
import sesim.Order;
|
||||||
import sesim.Order.OrderType;
|
import sesim.Order.OrderType;
|
||||||
import sesim.Quote;
|
import sesim.Quote;
|
||||||
|
|
||||||
@ -166,7 +167,8 @@ public class RandomTraderB extends AutoTraderBase {
|
|||||||
Iterator<Long> it = keys.iterator();
|
Iterator<Long> it = keys.iterator();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
// Order od = it.next();
|
// Order od = it.next();
|
||||||
boolean rc = se.cancelOrder(account_id, it.next());
|
Order od = ad.getOrders().get(it.next());
|
||||||
|
boolean rc = se.cancelOrder(account_id, od);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return n;
|
return n;
|
||||||
|
Loading…
Reference in New Issue
Block a user