praparation of Account for multiple stokcs

This commit is contained in:
7u83 2017-10-10 07:38:00 +02:00
parent f7731c2381
commit afe26c0f9c
3 changed files with 53 additions and 87 deletions

View File

@ -1,4 +1,4 @@
#Mon, 09 Oct 2017 17:19:53 +0200
#Mon, 09 Oct 2017 22:37:48 +0200
annotation.processing.enabled=true
annotation.processing.enabled.in.editor=false
annotation.processing.processors.list=

View File

@ -40,7 +40,7 @@ import java.util.concurrent.ConcurrentHashMap;
protected AutoTraderInterface owner;
protected final ConcurrentHashMap<Long , Order> orders;
protected ConcurrentHashMap<String,Integer> sharesm;
protected ConcurrentHashMap<String,Double> sharesm;
@Override
public int compareTo(Object a) {

View File

@ -23,7 +23,6 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package sesim;
import java.text.DecimalFormat;
@ -39,13 +38,18 @@ import org.json.JSONObject;
import sesim.Order.OrderStatus;
import sesim.Order.OrderType;
/**
* @desc Echchange class
* @author 7u83
*/
public class Exchange {
HashMap<String, Stock> stocks;
Stock getStock(String symbol) {
return stocks.get(symbol);
}
ConcurrentLinkedQueue<Order> order_queue = new ConcurrentLinkedQueue();
private double money_df = 10000;
@ -111,8 +115,6 @@ public class Exchange {
return shares_formatter;
}
IDGenerator account_id_generator = new IDGenerator();
//public static Timer timer = new Timer();
@ -210,7 +212,6 @@ public class Exchange {
}
}
public void createTraders(JSONArray traderdefs) {
for (int i = 0; i < traderdefs.length(); i++) {
JSONObject o = traderdefs.getJSONObject(i);
@ -234,7 +235,6 @@ public class Exchange {
return a.id;
}
class OrderComparator implements Comparator<Order> {
OrderType type;
@ -287,7 +287,6 @@ public class Exchange {
IDGenerator order_id_generator = new IDGenerator();
/**
* Histrory of quotes
*/
@ -353,7 +352,6 @@ public class Exchange {
// long num_trades = 0;
// long num_orders = 0;
public Statistics getStatistics() {
return statistics;
/* Statistics s = new Statistics();
@ -684,7 +682,6 @@ public class Exchange {
// long orderid = 1;
//double lastprice = 100.0;
// long lastsvolume;
// private final Locker tradelock = new Locker();
public ArrayList<Order> getOrderBook(OrderType type, int depth) {
@ -858,20 +855,15 @@ public class Exchange {
removeOrderIfExecuted(b);
}
void addQuoteToHistory(Quote q) {
if (statistics.heigh == null) {
statistics.heigh = q.price;
}
else if (statistics.heigh<q.price){
} else if (statistics.heigh < q.price) {
statistics.heigh = q.price;
}
if (statistics.low == null) {
statistics.low = q.price;
}
else if(statistics.low>q.price){
} else if (statistics.low > q.price) {
statistics.low = q.price;
}
@ -880,7 +872,6 @@ public class Exchange {
updateQuoteReceivers(q);
}
/**
*
*/
@ -977,13 +968,11 @@ public class Exchange {
q.volume = volume_total;
q.time = timer.currentTimeMillis();
addQuoteToHistory(q);
//this.quoteHistory.add(q);
//this.updateOHLCData(q);
//this.updateQuoteReceivers(q);
}
long buy_orders = 0;
@ -1008,14 +997,13 @@ public class Exchange {
long buy_failed = 0;
long sell_failed = 0;
/**
*
* @param account_id
* @param type
* @param volume
* @param limit
* @return
* @return order_id
*/
public long createOrder(double account_id, OrderType type, double volume, double limit) {
@ -1025,8 +1013,6 @@ public class Exchange {
return -1;
}
Order o = new Order(order_id_generator.getNext(),
timer.currentTimeMillis(),
a, type, roundShares(volume), roundMoney(limit));
@ -1044,7 +1030,6 @@ public class Exchange {
}
// System.out.printf("Order ffailed %f %f \n",o.volume,o.limit);
return -1;
}
@ -1067,7 +1052,7 @@ public class Exchange {
// executor.notify();
}
// a.update(o);
return o.id;
return o.getID();
}
public double getBestLimit(OrderType type) {
@ -1090,24 +1075,6 @@ public class Exchange {
return accounts.get(account_id);
}
/*public AccountData getAccountData(double account_id_generator) {
tradelock.lock();
Account a = accounts.get(account_id_generator);
@ -1169,5 +1136,4 @@ public class Exchange {
return al;
}
*/
}