Refactoring

This commit is contained in:
7u83 2018-12-28 13:06:15 +01:00
parent c9721ac5f5
commit 370af3cf9e
27 changed files with 509 additions and 712 deletions

View File

@ -1,4 +1,4 @@
#Wed, 26 Dec 2018 12:44:17 +0100
#Fri, 28 Dec 2018 12:28:45 +0100
annotation.processing.enabled=true
annotation.processing.enabled.in.editor=false
annotation.processing.processors.list=

View File

@ -1,34 +0,0 @@
/*
* Copyright (c) 2018, tohe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package opensesim.gui;
/**
*
* @author tohe
*/
public interface AdmInterface {
}

View File

@ -48,6 +48,7 @@ import javax.swing.filechooser.FileFilter;
import javax.swing.filechooser.FileNameExtensionFilter;
import opensesim.gui.AssetPairEditor.NewJDialog;
import static opensesim.gui.Globals.getWorld;
import opensesim.gui.account.AccountDialog;
import opensesim.gui.exchangeeditor.ExchangeListDialog;
import org.json.JSONArray;
@ -65,10 +66,9 @@ import opensesim.world.Order;
import opensesim.world.Trader;
import opensesim.world.TradingAPI;
import opensesim.world.World;
import opensesim.world.scheduler.Event;
import opensesim.world.scheduler.FiringEvent;
import opensesim.world.scheduler.EventListener;
import opensesim.util.scheduler.Event;
import opensesim.util.scheduler.FiringEvent;
import opensesim.util.scheduler.EventListener;
/**
*
@ -605,6 +605,8 @@ public class SeSimApplication extends javax.swing.JFrame {
+ "}");
Trader t = godworld.createTrader(cfg);
t.start();
AccountDialog.runDialog(this, t.getAccount());
updateGodWorld(godworld);
@ -614,7 +616,7 @@ public class SeSimApplication extends javax.swing.JFrame {
TradingAPI api = ex.getAPI(p);
opensesim.world.scheduler.Scheduler s = godworld.getScheduler();
opensesim.util.scheduler.Scheduler s = godworld.getScheduler();
class MyListener implements EventListener {
@ -625,7 +627,7 @@ public class SeSimApplication extends javax.swing.JFrame {
}
@Override
public long receive(opensesim.world.scheduler.Event task) {
public long receive(opensesim.util.scheduler.Event task) {
System.out.printf("Received an Event %d\n", Thread.currentThread().getId());
// e.count++;
@ -972,7 +974,7 @@ public class SeSimApplication extends javax.swing.JFrame {
private void clearMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_clearMenuItemActionPerformed
int dialogResult = JOptionPane.showConfirmDialog(this, "Are you sure?", "Warning", JOptionPane.YES_NO_OPTION);
int dialogResult = JOptionPane.showConfirmDialog(this, "Are you sure you want to clear all data?", "Warning", JOptionPane.YES_NO_OPTION);
if (dialogResult != JOptionPane.YES_OPTION) {
return;
}

View File

@ -23,9 +23,11 @@
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="orderBookPanel1" max="32767" attributes="0"/>
<Component id="bidbook" min="-2" pref="293" max="-2" attributes="0"/>
<EmptySpace pref="91" max="32767" attributes="0"/>
<Component id="askbook" min="-2" pref="315" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
@ -34,14 +36,19 @@
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="orderBookPanel1" max="32767" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="bidbook" pref="326" max="32767" attributes="0"/>
<Component id="askbook" max="32767" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="opensesim.gui.orderbook.OrderBookPanel" name="orderBookPanel1">
<Component class="opensesim.gui.orderbook.OrderBookPanel" name="bidbook">
</Component>
<Component class="opensesim.gui.orderbook.OrderBookPanel" name="askbook">
</Component>
</SubComponents>
</Form>

View File

@ -30,8 +30,9 @@ import java.awt.Frame;
import opensesim.world.AssetPair;
import opensesim.world.Exchange;
import opensesim.world.GodWorld;
import opensesim.world.scheduler.Event;
import opensesim.world.scheduler.EventListener;
import opensesim.world.Order;
import opensesim.util.scheduler.Event;
import opensesim.util.scheduler.EventListener;
/**
*
@ -52,7 +53,11 @@ public class OrderBookDialog extends javax.swing.JDialog implements EventListene
void init(){
this.setTitle(asset_pair.getSymbol()+" on "+ex.getSymbol());
this.orderBookPanel1.init(godworld, ex, asset_pair);
this.bidbook.type=Order.Type.BUYLIMIT;
this.bidbook.init(godworld, ex, asset_pair);
this.askbook.type=Order.Type.SELLLIMIT;
this.askbook.init(godworld, ex, asset_pair);
}
AssetPair asset_pair;
@ -83,7 +88,8 @@ public class OrderBookDialog extends javax.swing.JDialog implements EventListene
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
orderBookPanel1 = new opensesim.gui.orderbook.OrderBookPanel();
bidbook = new opensesim.gui.orderbook.OrderBookPanel();
askbook = new opensesim.gui.orderbook.OrderBookPanel();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
@ -91,16 +97,20 @@ public class OrderBookDialog extends javax.swing.JDialog implements EventListene
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(orderBookPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(bidbook, javax.swing.GroupLayout.PREFERRED_SIZE, 293, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 91, Short.MAX_VALUE)
.addComponent(askbook, javax.swing.GroupLayout.PREFERRED_SIZE, 315, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(orderBookPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(bidbook, javax.swing.GroupLayout.DEFAULT_SIZE, 326, Short.MAX_VALUE)
.addComponent(askbook, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap())
);
@ -150,7 +160,8 @@ public class OrderBookDialog extends javax.swing.JDialog implements EventListene
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private opensesim.gui.orderbook.OrderBookPanel orderBookPanel1;
private opensesim.gui.orderbook.OrderBookPanel askbook;
private opensesim.gui.orderbook.OrderBookPanel bidbook;
// End of variables declaration//GEN-END:variables
@Override

View File

@ -28,6 +28,7 @@ package opensesim.gui.orderbook;
import opensesim.gui.Globals;
import opensesim.gui.util.NummericCellRenderer;
import java.util.Collection;
import java.util.Iterator;
import java.util.Timer;
import java.util.TimerTask;
import javax.swing.SwingUtilities;
@ -40,10 +41,11 @@ import opensesim.world.GodWorld;
import opensesim.world.Order;
import opensesim.world.TradingAPI;
import opensesim.world.scheduler.Event;
import opensesim.world.scheduler.EventListener;
import opensesim.util.scheduler.Event;
import opensesim.util.scheduler.EventListener;
/**
* Displays an orderbook
*
* @author 7u83 <7u83@mail.ru>
*/
@ -57,8 +59,6 @@ public class OrderBookPanel extends javax.swing.JPanel implements EventListener
@Override
public long receive(Event task) {
System.out.printf("There is an o event \n");
synchronized (this) {
if (oupdate) {
new_oupdate = true;
@ -109,6 +109,7 @@ public class OrderBookPanel extends javax.swing.JPanel implements EventListener
}
public void init(GodWorld godworld, Exchange ex, AssetPair pair) {
api = ex.getAPI(pair);
api.addOrderBookListener(this);
@ -116,7 +117,7 @@ public class OrderBookPanel extends javax.swing.JPanel implements EventListener
trader_column = list.getColumnModel().getColumn(0);
list.getColumnModel().getColumn(1).setCellRenderer(new NummericCellRenderer(api.getAssetPair().getCurrency().getDecimals()));
list.getColumnModel().getColumn(2).setCellRenderer(new NummericCellRenderer(api.getAssetPair().getAsset().getDecimals()));
this.setGodMode(true);
this.oupdater();
}
@ -144,17 +145,45 @@ public class OrderBookPanel extends javax.swing.JPanel implements EventListener
long ouctr = 0;
Order.Type type;
void oupdater() {
Collection<Order> ob = api.getOrderBook(type);
model.setRowCount(ob.size());
private void drawBookSimple(Collection<Order> orderbook) {
model.setRowCount(orderbook.size());
int row = 0;
for (Order ob1 : ob) {
for (Order order : orderbook) {
// model.setValueAt(ob1.getAccount().getOwner().getName(), row, 0);
model.setValueAt(ob1.getLimit(), row, 1);
model.setValueAt(ob1.getVolume(), row, 2);
model.setValueAt(order.getID(), row, 0);
model.setValueAt(order.getLimit(), row, 1);
model.setValueAt(order.getVolume(), row, 2);
row++;
}
}
private void drawBookCmplex(Collection<Order> orderbook){
model.setRowCount(orderbook.size());
int row = 0;
double volume = 0.0;
double limit = 0.0;
Iterator<Order> it;
for (Order order : orderbook) {
// model.setValueAt(ob1.getAccount().getOwner().getName(), row, 0);
model.setValueAt(order.getLimit(), row, 1);
model.setValueAt(order.getVolume(), row, 2);
row++;
}
}
void oupdater() {
// get order book from API
Collection<Order> orderbook = api.getOrderBook(type);
this.drawBookSimple(orderbook);
synchronized (this) {
oupdate = new_oupdate;

View File

@ -1,43 +0,0 @@
/*
* Copyright (c) 2018, 7u83 <7u83@mail.ru>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package opensesim.gui.util;
import javax.swing.JComboBox;
/**
*
* @author 7u83 <7u83@mail.ru>
*/
public class Misc {
public class AssetTypeComboBox extends JComboBox
{
AssetTypeComboBox(){
super();
}
}
}

View File

@ -25,6 +25,7 @@
*/
package opensesim.old_sesim;
import opensesim.util.idgenerator.LongIDGenerator;
import java.text.DecimalFormat;
import java.util.*;
import java.util.concurrent.ConcurrentLinkedQueue;
@ -124,7 +125,7 @@ public class Exchange {
return shares_formatter;
}
IDGenerator account_id_generator = new IDGenerator();
LongIDGenerator account_id_generator = new LongIDGenerator();
//public static Timer timer = new Timer();
public Scheduler timer; // = new Scheduler();
@ -299,7 +300,7 @@ public class Exchange {
}
IDGenerator order_id_generator = new IDGenerator();
LongIDGenerator order_id_generator = new LongIDGenerator();
final void initExchange() {

View File

@ -32,9 +32,8 @@ import opensesim.world.Exchange;
import opensesim.world.Order;
import opensesim.world.TradingAPI;
import opensesim.world.World;
import opensesim.world.scheduler.Event;
import opensesim.world.scheduler.FiringEvent;
import opensesim.world.scheduler.EventListener;
import opensesim.util.scheduler.Event;
import opensesim.util.scheduler.EventListener;
import org.json.JSONObject;
/**
@ -104,12 +103,15 @@ public class SimpleTrader extends AbstractTrader implements EventListener {
ex = getWorld().getDefaultExchange();
api = ex.getAPI(p);
Order o = api.createOrder(account, Order.Type.BUY, 100, 200);
Order o = api.createOrder(account, Order.Type.BUYLIMIT, 13, 10.0);
Order ou = api.createOrder(account, Order.Type.BUY, 1500, 10.0);
Order o2 = api.createOrder(account, Order.Type.SELLLIMIT, 200, 278);
Order o1 = api.createOrder(account, Order.Type.SELLLIMIT, 250, 278);
long delay = (long) (1000.0f * getWorld().randNextFloat(3.0f, 12.7f));
setStatus(String.format("Initial delay: Sleeping for %d seconds.", delay));
getWorld().schedule(this, delay);
// getWorld().schedule(this, delay);
// long delay = (long) (getRandom(initial_delay[0], initial_delay[1]) * 1000);
// setStatus("Inital delay: %d", delay);

View File

@ -1,57 +0,0 @@
/*
* Copyright (c) 2018, 7u83 <7u83@mail.ru>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package opensesim.util;
import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.node.ObjectNode;
/**
*
* @author 7u83 <7u83@mail.ru>
*/
public final class SeSimObjectMapper extends ObjectMapper {
Object object;
public SeSimObjectMapper(Object o) {
super();
object = o;
// disable auto detection
disable(MapperFeature.AUTO_DETECT_CREATORS,
MapperFeature.AUTO_DETECT_FIELDS,
MapperFeature.AUTO_DETECT_GETTERS,
MapperFeature.AUTO_DETECT_IS_GETTERS);
// if you want to prevent an exception when classes have no annotated properties
disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
}
ObjectNode getObjectNode() {
return valueToTree(object);
}
}

View File

@ -25,16 +25,21 @@
*/
package opensesim.util.idgenerator;
import java.util.function.Supplier;
/**
* Implementation of a simple ID generator to create uniqe IDs of type long
* Implementation of a simple ID generator to create unique IDs
*
* @author 7u83 <7u83@mail.ru>
*/
public class IDGenerator {
public class IDGenerator<T extends Number> {
private Long next_id;
private Long next_id ;
private Long start_id;
/**
* Initialize the ID generator
*
@ -50,6 +55,7 @@ public class IDGenerator {
*/
public IDGenerator() {
this(0L);
}
/**
@ -65,6 +71,6 @@ public class IDGenerator {
* @return the next generated ID
*/
public synchronized Id getNext() {
return new Id<>(next_id++);
return new Id<Long>(next_id++);
}
}

View File

@ -23,14 +23,14 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package opensesim.old_sesim;
package opensesim.util.idgenerator;
/**
* Implementation of a simple ID generator to create uniqe IDs of type long
* Implementation of a simple ID generator to create unique IDs of type long
*
* @author 7u83 <7u83@mail.ru>
*/
public class IDGenerator {
public class LongIDGenerator {
private long next_id;
private long start_id;
@ -40,7 +40,7 @@ public class IDGenerator {
*
* @param start ID value to start with
*/
public IDGenerator(long start) {
public LongIDGenerator(long start) {
start_id=start;
reset();
}
@ -48,7 +48,7 @@ public class IDGenerator {
/**
* Initialize ID Generator with start ID = 0
*/
public IDGenerator() {
public LongIDGenerator() {
this(0);
}

View File

@ -25,7 +25,7 @@
*/
package opensesim.world;
import java.util.HashSet;
import org.json.JSONObject;
/**
@ -100,7 +100,13 @@ public abstract class AbstractTrader implements Trader {
public AbstractTrader(World world, JSONObject cfg) {
this.world=world;
this.account = new Account();
AssetPack pack;
pack = new AssetPack(this.world.getDefaultAssetPair().getCurrency(),1000);
this.account.add(pack);
pack = new AssetPack(this.world.getDefaultAssetPair().getAsset(),2000);
this.account.add(pack);
}
protected void log(String s){
@ -111,4 +117,8 @@ public abstract class AbstractTrader implements Trader {
}
@Override
public Account getAccount(){
return account;
}
}

View File

@ -25,17 +25,10 @@
*/
package opensesim.world;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
import opensesim.sesim.interfaces.Configurable;
import opensesim.sesim.interfaces.GetJson;
import opensesim.util.idgenerator.IDGenerator;
import opensesim.world.scheduler.FiringEvent;
import opensesim.world.scheduler.EventListener;
import org.json.JSONObject;
/**

View File

@ -38,10 +38,9 @@ import java.util.logging.Logger;
import opensesim.sesim.interfaces.GetJson;
import opensesim.util.SeSimException;
import opensesim.world.scheduler.Event;
import opensesim.world.scheduler.EventListener;
import opensesim.world.scheduler.Scheduler;
import opensesim.util.scheduler.Event;
import opensesim.util.scheduler.EventListener;
import opensesim.util.scheduler.Scheduler;
import org.json.JSONArray;
import org.json.JSONException;

View File

@ -26,7 +26,7 @@
package opensesim.world;
import java.util.Collection;
import opensesim.world.scheduler.EventListener;
import opensesim.util.scheduler.EventListener;
/**
*

View File

@ -26,7 +26,7 @@
package opensesim.world;
import java.util.Set;
import opensesim.world.scheduler.EventListener;
import opensesim.util.scheduler.EventListener;
/**
*

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, tube
* Copyright (c) 2018, 7u83
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -32,12 +32,12 @@ import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
import opensesim.util.idgenerator.IDGenerator;
import opensesim.world.scheduler.EventListener;
import opensesim.world.scheduler.FiringEvent;
import opensesim.util.scheduler.EventListener;
import opensesim.util.scheduler.FiringEvent;
/**
*
* @author tube
* @author 7u83
*/
class TradingEngine implements TradingAPI {
@ -46,7 +46,7 @@ class TradingEngine implements TradingAPI {
/**
* Construct a trading engine for an asset pair
*
* @param pair The AssetPair obect to create the tradinge engine for
* @param pair The AssetPair obect to create the trading engine for
* @param outer Outer class - points to an Exchange object thins trading
* engine belongs to.
*/
@ -62,19 +62,24 @@ class TradingEngine implements TradingAPI {
}
IDGenerator id_generator = new IDGenerator();
private HashMap<Order.Type, SortedSet<Order>> order_books;
private SortedSet<Order> bidbook;
private SortedSet<Order> askbook;
private SortedSet<Order> bidbook, askbook;
private SortedSet<Order> ul_buy,ul_sell;
AssetPair assetpair;
protected final void reset() {
order_books = new HashMap();
order_books = new HashMap<>();
// Create an order book for each order type
for (Order.Type type : Order.Type.values()) {
order_books.put(type, new TreeSet<>());
}
// Save bidbook and askboo for quicker access
// Save order books to variables for quicker access
bidbook = order_books.get(Order.Type.BUYLIMIT);
askbook = order_books.get(Order.Type.SELLLIMIT);
ul_buy=order_books.get(Order.Type.BUY);
ul_sell=order_books.get(Order.Type.SELL);
// quoteHistory = new TreeSet();
// ohlc_data = new HashMap();
}
@ -83,10 +88,6 @@ class TradingEngine implements TradingAPI {
*
*/
private void executeOrders() {
SortedSet<Order> bid = order_books.get(Order.Type.BUYLIMIT);
SortedSet<Order> ask = order_books.get(Order.Type.SELLLIMIT);
SortedSet<Order> ul_buy = order_books.get(Order.Type.BUY);
SortedSet<Order> ul_sell = order_books.get(Order.Type.SELL);
double volume_total = 0;
double money_total = 0;
@ -127,13 +128,14 @@ class TradingEngine implements TradingAPI {
this.checkSLOrders(price);
}
*/
// Match limited orders against limited orders
if (bid.isEmpty() || ask.isEmpty()) {
if (bidbook.isEmpty() || askbook.isEmpty()) {
// there is nothing to do
break;
}
Order b = bid.first();
Order a = ask.first();
Order b = bidbook.first();
Order a = askbook.first();
if (b.limit < a.limit) {
break;
}
@ -156,7 +158,7 @@ class TradingEngine implements TradingAPI {
// addQuoteToHistory(q);
}
protected void addOrderToBook(Order o) {
/* protected void addOrderToBook(Order o) {
order_books.get(o.type).add(o);
switch (o.type) {
case BUY:
@ -167,10 +169,14 @@ class TradingEngine implements TradingAPI {
break;
}
}
*/
public Double getBestPrice() {
SortedSet<Order> bid = order_books.get(Order.Type.BUYLIMIT);
SortedSet<Order> ask = order_books.get(Order.Type.SELLLIMIT);
Quote lq = null; //this.getLastQuoete();
Order b = null;
Order a = null;
@ -310,6 +316,8 @@ class TradingEngine implements TradingAPI {
synchronized (this) {
order_books.get(o.type).add(o);
}
executeOrders();
for (FiringEvent e : book_listener) {
e.fire();

View File

@ -27,7 +27,7 @@ package opensesim.world;
import java.util.Collection;
import opensesim.world.scheduler.EventListener;
import opensesim.util.scheduler.EventListener;
/**
*

View File

@ -1,103 +0,0 @@
/*
* Copyright (c) 2018, 7u83
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package opensesim.world.scheduler;
/**
*
* @author 7u83 <7u83@mail.ru>
*/
public class Clock {
private double current_millis;
private long last_nanos;
private double current_nanos;
private double acceleration;
public double getAcceleration() {
return acceleration;
}
public void setAcceleration(double acceleration) {
synchronized (this) {
this.acceleration = acceleration;
this.notifyAll();
}
}
private boolean pause = false;
public boolean isPause() {
return pause;
}
public void setPause(boolean pause) {
this.pause = pause;
}
Clock() {
this.acceleration = 1.0;
this.current_nanos = 0;
this.current_millis = 0.0;
this.last_nanos = System.nanoTime();
}
private long currentTimeMillis1() {
long nanos = System.nanoTime();
long diff = nanos - last_nanos;
last_nanos = nanos;
if (pause) {
return (long) this.current_millis;
}
this.current_nanos += (double) diff * (double) this.acceleration;
this.current_millis = this.current_nanos / 1000000.0;
return (long) this.current_millis;
}
public long currentTimeMillis() {
return (long) this.current_millis;
}
synchronized long getDelay(long t) {
long current = currentTimeMillis1();
if (t > current) {
return (long) (((double) t - this.current_millis) / this.acceleration);
}
/* if (t < ct) {
// System.out.printf("Time is overslipping: %d\n",ct-t);
this.current_millis = t;
this.current_nanos = this.current_millis * 1000000.0;
}*/
return 0;
}
}

View File

@ -1,34 +0,0 @@
/*
* Copyright (c) 2018, tube
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package opensesim.world.scheduler;
/**
*
* @author tube
*/
public abstract class Event {
}

View File

@ -1,36 +0,0 @@
/*
* Copyright (c) 2018, 7u83 <7u83@mail.ru>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package opensesim.world.scheduler;
/**
*
* @author 7u83 <7u83@mail.ru>
*/
public interface EventListener {
long receive(Event task);
}

View File

@ -1,45 +0,0 @@
/*
* Copyright (c) 2018, 7u83 <7u83@mail.ru>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package opensesim.world.scheduler;
/**
*
* @author 7u83 <7u83@mail.ru>
*/
public class FiringEvent extends Event {
EventListener listener;
public FiringEvent(EventListener listener) {
this.listener = listener;
}
public void fire(){
listener.receive(this);
}
}

View File

@ -1,163 +0,0 @@
/*
* Copyright (c) 2018, 7u83
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package opensesim.world.scheduler;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.SortedMap;
import java.util.TreeMap;
import opensesim.world.scheduler.EventListener;
/**
*
* @author tohe
*/
public class Scheduler {
private final SortedMap<Long, LinkedList<FiringEvent>> event_queue = new TreeMap<>();
private class Worker extends Thread {
boolean terminate = false;
@Override
public void run() {
while (!terminate) {
long delay = getDelay();
//System.out.printf("Worker %d has delay %d\n",Thread.currentThread().getId(), delay);
if (delay > 0 || delay==-1) {
//System.out.printf("Worker %d sleeps for %d\n",Thread.currentThread().getId(), delay);
synchronized (clock) {
try {
if (delay != -1 && !clock.isPause()) {
clock.wait(delay);
} else {
clock.wait();
}
} catch (InterruptedException e) {
//System.out.printf("Interrupted\n");
}
}
continue;
}
FiringEvent e = getNextEvent();
if (e == null) {
continue;
}
//System.out.printf("Worker %d got event %d\n",Thread.currentThread().getId(), e.t);
e.listener.receive(e);
}
}
}
ArrayList<Worker> workers;
final private Clock clock = new Clock();
// int next = 0;
public Scheduler(int nthreads) {
workers = new ArrayList<>();
for (int i = 0; i < nthreads; i++) {
workers.add(i, new Worker());
}
}
public Scheduler() {
this(10);
}
public void start() {
for (Worker w : workers) {
w.start();
}
}
public FiringEvent startTimerTask(EventListener listener, long time) {
FiringEvent e = new FiringEvent(listener);
long t = time + clock.currentTimeMillis();
synchronized (event_queue) {
LinkedList<FiringEvent> s = event_queue.get(t);
if (s == null) {
s = new LinkedList<>();
event_queue.put(t, s);
}
s.add(e);
}
synchronized (clock) {
clock.notifyAll();
}
return e;
}
protected long getDelay() {
synchronized (event_queue) {
if (event_queue.isEmpty()) {
return -1;
}
long t = event_queue.firstKey();
//System.out.printf("Worker: %d - queu is not empty: cur millis %d til %d\n", Thread.currentThread().getId(), clock.currentTimeMillis(),t);
return clock.getDelay(t);
}
}
protected FiringEvent getNextEvent() {
// System.out.printf("RunEvents in Thread %d\n",Thread.currentThread().getId());
synchronized (event_queue) {
if (event_queue.isEmpty()) {
return null;
}
long t = event_queue.firstKey();
LinkedList<FiringEvent> s = event_queue.get(t);
FiringEvent e = s.pop();
if (s.isEmpty()) {
event_queue.remove(t);
}
return e;
}
}
public long currentTimeMillis(){
return clock.currentTimeMillis();
}
public void setAcceleration(double a){
clock.setAcceleration(a);
}
}

View File

@ -1,115 +0,0 @@
/*
* Copyright (c) 2018, 7u83 <7u83@mail.ru>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package opensesim.world;
import opensesim.util.idgenerator.IDGenerator;
import org.json.JSONObject;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;
/**
*
* @author 7u83 <7u83@mail.ru>
*/
public class OrderTest {
public OrderTest() {
}
@BeforeClass
public static void setUpClass() {
}
@AfterClass
public static void tearDownClass() {
}
GodWorld world;
@Before
public void setUp() {
world = new GodWorld(new JSONObject("{}"));
}
@After
public void tearDown() {
}
/**
* Test of getVolume method, of class Order.
*/
@Test
public void testGetVolume() {
System.out.println("getVolume");
double expResult = 13.7;
Order instance = new opensesim.world.Order(world, null, null, Order.Type.BUY, expResult, 0.0);
double result = instance.getVolume();
assertEquals(expResult, result, 0.0);
// TODO review the generated test code and remove the default call to // fail.
// fail("The test case is a prototype.");
}
/**
* Test of getLimit method, of class Order.
*/
@Test
public void testGetLimit() {
System.out.println("getLimit");
Order instance = new opensesim.world.Order(world, null, null, Order.Type.BUY, 0, 17.4);
double expResult = 0.0;
double result = instance.getLimit();
assertEquals(expResult, result, 17.4);
// TODO review the generated test code and remove the default call to // fail.
// fail("The test case is a prototype.");
}
/**
* Test of getType method, of class Order.
*/
@Test
public void testGetType() {
System.out.println("getType");
Order.Type expResult = Order.Type.BUY;
Order instance = new opensesim.world.Order(world, null, null, expResult, 0, 17.4);
Order.Type result = instance.getType();
assertEquals(expResult, result);
// TODO review the generated test code and remove the default call to // fail.
// fail("The test case is a prototype.");
}
}

View File

@ -0,0 +1,176 @@
/*
* Copyright (c) 2018, tube
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package opensesim.world;
import java.util.Set;
import opensesim.util.scheduler.EventListener;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;
/**
*
* @author tube
*/
public class TradingAPITest {
public TradingAPITest() {
}
@BeforeClass
public static void setUpClass() {
}
@AfterClass
public static void tearDownClass() {
}
@Before
public void setUp() {
}
@After
public void tearDown() {
}
/**
* Test of addOrderBookListener method, of class TradingAPI.
*/
@Test
public void testAddOrderBookListener() {
System.out.println("addOrderBookListener");
EventListener listener = null;
TradingAPI instance = new TradingAPIImpl();
instance.addOrderBookListener(listener);
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}
/**
* Test of createOrder method, of class TradingAPI.
*/
@Test
public void testCreateOrder() {
System.out.println("createOrder");
Account account = null;
Order.Type type = null;
double volume = 0.0;
double limit = 0.0;
TradingAPI instance = new TradingAPIImpl();
Order expResult = null;
Order result = instance.createOrder(account, type, volume, limit);
assertEquals(expResult, result);
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}
/**
* Test of getBidBook method, of class TradingAPI.
*/
@Test
public void testGetBidBook() {
System.out.println("getBidBook");
TradingAPI instance = new TradingAPIImpl();
Set expResult = null;
Set result = instance.getBidBook();
assertEquals(expResult, result);
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}
/**
* Test of getAskBook method, of class TradingAPI.
*/
@Test
public void testGetAskBook() {
System.out.println("getAskBook");
TradingAPI instance = new TradingAPIImpl();
Set expResult = null;
Set result = instance.getAskBook();
assertEquals(expResult, result);
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}
/**
* Test of getOrderBook method, of class TradingAPI.
*/
@Test
public void testGetOrderBook() {
System.out.println("getOrderBook");
Order.Type type = null;
TradingAPI instance = new TradingAPIImpl();
Set expResult = null;
Set result = instance.getOrderBook(type);
assertEquals(expResult, result);
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}
/**
* Test of getAssetPair method, of class TradingAPI.
*/
@Test
public void testGetAssetPair() {
System.out.println("getAssetPair");
TradingAPI instance = new TradingAPIImpl();
AssetPair expResult = null;
AssetPair result = instance.getAssetPair();
assertEquals(expResult, result);
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}
public class TradingAPIImpl implements TradingAPI {
public void addOrderBookListener(EventListener listener) {
}
public Order createOrder(Account account, Order.Type type, double volume, double limit) {
return null;
}
public Set getBidBook() {
return null;
}
public Set getAskBook() {
return null;
}
public Set getOrderBook(Order.Type type) {
return null;
}
public AssetPair getAssetPair() {
return null;
}
}
}

View File

@ -0,0 +1,183 @@
/*
* Copyright (c) 2018, tube
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package opensesim.world;
import java.util.Set;
import opensesim.sesim.Assets.CurrencyAsset;
import opensesim.util.scheduler.EventListener;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;
/**
*
* @author tube
*/
public class TradingEngineTest {
public TradingEngineTest() {
}
@BeforeClass
public static void setUpClass() {
}
@AfterClass
public static void tearDownClass() {
}
@Before
public void setUp() {
}
@After
public void tearDown() {
}
/**
* Test of getAssetPair method, of class TradingEngine.
*/
@Test
public void testGetAssetPair() {
System.out.println("getAssetPair");
TradingEngine instance = null;
AssetPair expResult = null;
AssetPair result = instance.getAssetPair();
assertEquals(expResult, result);
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}
/**
* Test of reset method, of class TradingEngine.
*/
@Test
public void testReset() {
System.out.println("reset");
TradingEngine instance = null;
instance.reset();
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}
/**
* Test of getBestPrice method, of class TradingEngine.
*/
@Test
public void testGetBestPrice() {
System.out.println("getBestPrice");
TradingEngine instance = null;
Double expResult = null;
Double result = instance.getBestPrice();
assertEquals(expResult, result);
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}
/**
* Test of createOrder method, of class TradingEngine.
*/
@Test
public void testCreateOrder() {
System.out.println("createOrder");
GodWorld gdworld = new GodWorld();
// AbstractAsset currency = gdworld.createAsset(cfg);
Account account = new Account();
Order.Type type = null;
double volume = 0.0;
double limit = 0.0;
TradingEngine instance = null;
Order expResult = null;
Order result = instance.createOrder(account, type, volume, limit);
assertEquals(expResult, result);
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}
/**
* Test of addOrderBookListener method, of class TradingEngine.
*/
@Test
public void testAddOrderBookListener() {
System.out.println("addOrderBookListener");
EventListener listener = null;
TradingEngine instance = null;
instance.addOrderBookListener(listener);
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}
/**
* Test of getOrderBook method, of class TradingEngine.
*/
@Test
public void testGetOrderBook() {
System.out.println("getOrderBook");
Order.Type type = null;
TradingEngine instance = null;
Set expResult = null;
Set result = instance.getOrderBook(type);
assertEquals(expResult, result);
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}
/**
* Test of getBidBook method, of class TradingEngine.
*/
@Test
public void testGetBidBook() {
System.out.println("getBidBook");
TradingEngine instance = null;
Set expResult = null;
Set result = instance.getBidBook();
assertEquals(expResult, result);
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}
/**
* Test of getAskBook method, of class TradingEngine.
*/
@Test
public void testGetAskBook() {
System.out.println("getAskBook");
TradingEngine instance = null;
Set expResult = null;
Set result = instance.getAskBook();
assertEquals(expResult, result);
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}
}