Included stock symbol in order creation.
This commit is contained in:
parent
0c584c6046
commit
9b86599f03
@ -1,4 +1,4 @@
|
||||
#Sun, 10 Dec 2017 09:32:20 +0100
|
||||
#Sun, 10 Dec 2017 12:50:27 +0100
|
||||
annotation.processing.enabled=true
|
||||
annotation.processing.enabled.in.editor=false
|
||||
annotation.processing.processors.list=
|
||||
|
@ -57,6 +57,11 @@ public class Exchange {
|
||||
public Stock getDefaultStock(){
|
||||
return getStock(DEFAULT_STOCK);
|
||||
}
|
||||
|
||||
public String getDefaultStockSymbol(){
|
||||
return DEFAULT_STOCK;
|
||||
}
|
||||
|
||||
|
||||
ConcurrentLinkedQueue<Order> order_queue = new ConcurrentLinkedQueue();
|
||||
|
||||
@ -698,12 +703,14 @@ public class Exchange {
|
||||
}
|
||||
}
|
||||
|
||||
// long time = 0;
|
||||
//double theprice = 12.9;
|
||||
// long orderid = 1;
|
||||
//double lastprice = 100.0;
|
||||
// long lastsvolume;
|
||||
// private final Locker tradelock = new Locker();
|
||||
|
||||
/**
|
||||
*
|
||||
* @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);
|
||||
@ -735,7 +742,10 @@ public class Exchange {
|
||||
return getOrderBook(getDefaultStock(),type,depth);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Quote getLastQuoete() {
|
||||
if (this.quoteHistory.isEmpty()) {
|
||||
return null;
|
||||
@ -857,6 +867,7 @@ public class Exchange {
|
||||
removeOrderIfExecuted(getDefaultStock(),o);
|
||||
}
|
||||
|
||||
|
||||
void checkSLOrders(Stock stock, double price) {
|
||||
SortedSet<Order> sl = stock.order_books.get(OrderType.STOPLOSS);
|
||||
SortedSet<Order> ask = stock.order_books.get(OrderType.SELLLIMIT);
|
||||
@ -1054,17 +1065,23 @@ public class Exchange {
|
||||
* @param limit
|
||||
* @return order_id
|
||||
*/
|
||||
public long createOrder(double account_id, OrderType type, double volume, double limit) {
|
||||
public long createOrder(double account_id,
|
||||
String stocksymbol, OrderType type, double volume, double limit) {
|
||||
|
||||
|
||||
Stock stock = this.getStock(stocksymbol);
|
||||
|
||||
Account a = accounts.get(account_id);
|
||||
if (a == null) {
|
||||
System.out.printf("Order not places account\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
Order o = new Order(order_id_generator.getNext(),
|
||||
timer.currentTimeMillis(),
|
||||
a, type, roundShares(volume), roundMoney(limit));
|
||||
|
||||
o.stock=stock;
|
||||
|
||||
if (o.volume <= 0 || o.limit <= 0) {
|
||||
|
||||
switch (o.type) {
|
||||
@ -1077,12 +1094,10 @@ public class Exchange {
|
||||
buy_failed++;
|
||||
break;
|
||||
}
|
||||
// System.out.printf("Order ffailed %f %f \n",o.volume,o.limit);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
// System.out.printf("Getting executor in create Order\n", Thread.currentThread().getId());
|
||||
synchronized (executor) {
|
||||
|
||||
//num_orders++;
|
||||
|
@ -58,5 +58,7 @@ public class Stock {
|
||||
}
|
||||
|
||||
protected final HashMap<Order.OrderType, SortedSet<Order>> order_books;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -191,7 +191,7 @@ public class CreateOrderDialog extends javax.swing.JDialog {
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
Globals.se.createOrder(account.getID(), type, volume, limit);
|
||||
Globals.se.createOrder(account.getID(), Globals.se.getDefaultStockSymbol(), type, volume, limit);
|
||||
}
|
||||
}.start();
|
||||
|
||||
|
@ -176,7 +176,9 @@ public class ManTraderConsole extends javax.swing.JPanel {
|
||||
|
||||
System.out.printf("Should buy: %f %f\n",volume,limit);
|
||||
|
||||
long createOrder = trader.getSE().createOrder(trader.getAccount().getID(), OrderType.BUYLIMIT, volume, limit);
|
||||
long createOrder = trader.getSE().createOrder(trader.getAccount().getID(),
|
||||
trader.getSE().getDefaultStockSymbol(),
|
||||
OrderType.BUYLIMIT, volume, limit);
|
||||
System.out.printf("The retval is %d",createOrder);
|
||||
|
||||
// this.ordersList.account=this.trader.getAccount();
|
||||
@ -191,7 +193,9 @@ public class ManTraderConsole extends javax.swing.JPanel {
|
||||
|
||||
System.out.printf("Should sell: %f %f\n",volume,limit);
|
||||
|
||||
long createOrder = trader.getSE().createOrder(trader.getAccount().getID(), OrderType.SELLLIMIT, volume, limit);
|
||||
long createOrder = trader.getSE().createOrder(trader.getAccount().getID(),
|
||||
trader.getSE().getDefaultStockSymbol(),
|
||||
OrderType.SELLLIMIT, volume, limit);
|
||||
System.out.printf("The retval is %d",createOrder);
|
||||
}//GEN-LAST:event_sellButtonActionPerformed
|
||||
|
||||
@ -201,7 +205,9 @@ public class ManTraderConsole extends javax.swing.JPanel {
|
||||
|
||||
System.out.printf("Should stoploss: %f %f\n",volume,limit);
|
||||
|
||||
long createOrder = trader.getSE().createOrder(trader.getAccount().getID(), OrderType.STOPLOSS, volume, limit);
|
||||
long createOrder = trader.getSE().createOrder(trader.getAccount().getID(),
|
||||
trader.getSE().getDefaultStockSymbol(),
|
||||
OrderType.STOPLOSS, volume, limit);
|
||||
System.out.printf("The retval is %d",createOrder);
|
||||
}//GEN-LAST:event_stopLossButtonActionPerformed
|
||||
|
||||
|
@ -405,7 +405,7 @@ public class RandomTraderA extends AutoTraderBase implements AccountListener {
|
||||
// System.out.printf("Buy Order wont work\n");
|
||||
// return false;
|
||||
// }
|
||||
long rc = se.createOrder(account_id, type, volume, limit);
|
||||
long rc = se.createOrder(account_id, se.getDefaultStockSymbol(),type, volume, limit);
|
||||
|
||||
if (rc == -1) {
|
||||
|
||||
@ -445,7 +445,7 @@ public class RandomTraderA extends AutoTraderBase implements AccountListener {
|
||||
// return false;
|
||||
// }
|
||||
// System.out.printf("Create a Sell Order %f %f!!!!\n", volume, limit);
|
||||
long rc = se.createOrder(account_id, type, volume, limit);
|
||||
long rc = se.createOrder(account_id, se.getDefaultStockSymbol(), type, volume, limit);
|
||||
return rc != -1;
|
||||
|
||||
}
|
||||
|
@ -296,7 +296,7 @@ public class RandomTraderB extends AutoTraderBase {
|
||||
return false;
|
||||
}
|
||||
|
||||
se.createOrder(account_id, type, volume, limit);
|
||||
se.createOrder(account_id, se.getDefaultStockSymbol(), type, volume, limit);
|
||||
|
||||
return true;
|
||||
|
||||
@ -334,7 +334,7 @@ public class RandomTraderB extends AutoTraderBase {
|
||||
return false;
|
||||
}
|
||||
|
||||
se.createOrder(account_id, type, volume, limit);
|
||||
se.createOrder(account_id, se.getDefaultStockSymbol(), type, volume, limit);
|
||||
|
||||
return true;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user