Working stop button
This commit is contained in:
parent
4a01d8f1f6
commit
98965eed43
@ -37,13 +37,19 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver, Scrollab
|
||||
protected Rectangle clip_bounds = new Rectangle();
|
||||
protected Dimension gdim;
|
||||
|
||||
protected int first_bar, last_bar;
|
||||
private int first_bar, last_bar;
|
||||
|
||||
|
||||
public final void initChart(){
|
||||
data = new OHLCData(60000*30);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates new form Chart
|
||||
*/
|
||||
public Chart() {
|
||||
initComponents();
|
||||
initChart();
|
||||
if (Globals.se == null) {
|
||||
return;
|
||||
}
|
||||
@ -52,16 +58,15 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver, Scrollab
|
||||
|
||||
}
|
||||
|
||||
// int item_width = 10;
|
||||
//int items = 350;
|
||||
//long ntime = 0;
|
||||
OHLCData data = new OHLCData(60000*30);
|
||||
|
||||
OHLCData data;
|
||||
|
||||
|
||||
OHLCDataItem current = null;
|
||||
|
||||
void drawCandle(Graphics2D g, OHLCData d, int x, int y) {
|
||||
|
||||
}
|
||||
//void drawCandle(Graphics2D g, OHLCData d, int x, int y) {
|
||||
//
|
||||
// }
|
||||
|
||||
@Override
|
||||
public Dimension getPreferredScrollableViewportSize() {
|
||||
|
@ -26,6 +26,15 @@
|
||||
<Property name="text" type="java.lang.String" value="File"/>
|
||||
</Properties>
|
||||
<SubComponents>
|
||||
<MenuItem class="javax.swing.JMenuItem" name="jMenuItem1">
|
||||
<Properties>
|
||||
<Property name="mnemonic" type="int" value="110"/>
|
||||
<Property name="text" type="java.lang.String" value="New"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jMenuItem1ActionPerformed"/>
|
||||
</Events>
|
||||
</MenuItem>
|
||||
<MenuItem class="javax.swing.JMenuItem" name="openMenuItem">
|
||||
<Properties>
|
||||
<Property name="mnemonic" type="int" value="111"/>
|
||||
@ -110,6 +119,34 @@
|
||||
</MenuItem>
|
||||
</SubComponents>
|
||||
</Menu>
|
||||
<Menu class="javax.swing.JMenu" name="jMenu1">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Sim"/>
|
||||
</Properties>
|
||||
<SubComponents>
|
||||
<MenuItem class="javax.swing.JMenuItem" name="jMenuItem4">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Start"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jMenuItem4ActionPerformed"/>
|
||||
</Events>
|
||||
</MenuItem>
|
||||
<MenuItem class="javax.swing.JMenuItem" name="jMenuItem5">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Stop"/>
|
||||
</Properties>
|
||||
</MenuItem>
|
||||
<MenuItem class="javax.swing.JMenuItem" name="jMenuItem6">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Reset"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jMenuItem6ActionPerformed"/>
|
||||
</Events>
|
||||
</MenuItem>
|
||||
</SubComponents>
|
||||
</Menu>
|
||||
<Menu class="javax.swing.JMenu" name="viewMenu">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="View"/>
|
||||
@ -201,9 +238,9 @@
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Component id="jPanel2" max="32767" attributes="0"/>
|
||||
<Group type="102" attributes="0">
|
||||
<Component id="orderBookPanel1" min="-2" pref="233" max="-2" attributes="0"/>
|
||||
<Component id="orderBookPanel" min="-2" pref="233" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="jScrollPane1" max="32767" attributes="0"/>
|
||||
<Component id="jChartScrollPane" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
@ -217,8 +254,8 @@
|
||||
<Component id="jPanel2" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Component id="jScrollPane1" max="32767" attributes="0"/>
|
||||
<Component id="orderBookPanel1" max="32767" attributes="0"/>
|
||||
<Component id="jChartScrollPane" max="32767" attributes="0"/>
|
||||
<Component id="orderBookPanel" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
</Group>
|
||||
@ -226,13 +263,13 @@
|
||||
</DimensionLayout>
|
||||
</Layout>
|
||||
<SubComponents>
|
||||
<Component class="gui.OrderBookPanel" name="orderBookPanel1">
|
||||
<Component class="gui.OrderBookPanel" name="orderBookPanel">
|
||||
</Component>
|
||||
<Container class="javax.swing.JScrollPane" name="jScrollPane1">
|
||||
<Container class="javax.swing.JScrollPane" name="jChartScrollPane">
|
||||
|
||||
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
|
||||
<SubComponents>
|
||||
<Container class="chart.Chart" name="chart1">
|
||||
<Container class="chart.Chart" name="chart">
|
||||
|
||||
<Layout>
|
||||
<DimensionLayout dim="0">
|
||||
@ -297,6 +334,9 @@
|
||||
<Property name="horizontalTextPosition" type="int" value="0"/>
|
||||
<Property name="verticalTextPosition" type="int" value="3"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jButton1ActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="jRunButton">
|
||||
<Properties>
|
||||
@ -335,7 +375,7 @@
|
||||
<Component class="javax.swing.JSpinner" name="jSpinner2">
|
||||
<Properties>
|
||||
<Property name="model" type="javax.swing.SpinnerModel" editor="org.netbeans.modules.form.editors2.SpinnerModelEditor">
|
||||
<SpinnerModel initial="0.0" maximum="10000.0" minimum="0.0" numberType="java.lang.Double" stepSize="0.1" type="number"/>
|
||||
<SpinnerModel initial="1.0" minimum="0.0" numberType="java.lang.Double" stepSize="100.0" type="number"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
<Events>
|
||||
|
@ -98,31 +98,12 @@ public class NewMDIApplication extends javax.swing.JFrame {
|
||||
|
||||
Globals.se.fairValue=moneyTotal/sharesTotal;
|
||||
|
||||
Globals.se.fairValue=1.0;
|
||||
|
||||
for (int i=0; i<Globals.se.traders.size(); i++){
|
||||
Globals.se.traders.get(i).start();
|
||||
}
|
||||
|
||||
// System.exit(0);
|
||||
|
||||
|
||||
/*
|
||||
AutoTraderConfig cfg1 = new RandomTraderConfig();
|
||||
AutoTrader rt1 = cfg1.createTrader(Globals.se, null, 100000, 100000);
|
||||
Globals.se.traders.add(rt1);
|
||||
|
||||
rt1.setName("Alice");
|
||||
rt1.start();
|
||||
|
||||
AutoTraderConfig cfg2 = new RandomTraderConfig();
|
||||
|
||||
for (int i = 0; i < 700; i++) {
|
||||
AutoTrader randt = cfg2.createTrader(Globals.se, null, 100, 100);
|
||||
|
||||
Globals.se.traders.add(randt);
|
||||
randt.setName("Bob");
|
||||
randt.start();
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
@ -137,9 +118,9 @@ public class NewMDIApplication extends javax.swing.JFrame {
|
||||
|
||||
jScrollPane2 = new javax.swing.JScrollPane();
|
||||
jTextArea1 = new javax.swing.JTextArea();
|
||||
orderBookPanel1 = new gui.OrderBookPanel();
|
||||
jScrollPane1 = new javax.swing.JScrollPane();
|
||||
chart1 = new chart.Chart();
|
||||
orderBookPanel = new gui.OrderBookPanel();
|
||||
jChartScrollPane = new javax.swing.JScrollPane();
|
||||
chart = new chart.Chart();
|
||||
jPanel2 = new javax.swing.JPanel();
|
||||
jButton1 = new javax.swing.JButton();
|
||||
jRunButton = new javax.swing.JButton();
|
||||
@ -148,6 +129,7 @@ public class NewMDIApplication extends javax.swing.JFrame {
|
||||
clock1 = new gui.Clock();
|
||||
menuBar = new javax.swing.JMenuBar();
|
||||
fileMenu = new javax.swing.JMenu();
|
||||
jMenuItem1 = new javax.swing.JMenuItem();
|
||||
openMenuItem = new javax.swing.JMenuItem();
|
||||
saveMenuItem = new javax.swing.JMenuItem();
|
||||
saveAsMenuItem = new javax.swing.JMenuItem();
|
||||
@ -159,6 +141,10 @@ public class NewMDIApplication extends javax.swing.JFrame {
|
||||
deleteMenuItem = new javax.swing.JMenuItem();
|
||||
jSeparator2 = new javax.swing.JPopupMenu.Separator();
|
||||
editPreferences = new javax.swing.JMenuItem();
|
||||
jMenu1 = new javax.swing.JMenu();
|
||||
jMenuItem4 = new javax.swing.JMenuItem();
|
||||
jMenuItem5 = new javax.swing.JMenuItem();
|
||||
jMenuItem6 = new javax.swing.JMenuItem();
|
||||
viewMenu = new javax.swing.JMenu();
|
||||
jMenuItem2 = new javax.swing.JMenuItem();
|
||||
jMenuItem3 = new javax.swing.JMenuItem();
|
||||
@ -176,24 +162,29 @@ public class NewMDIApplication extends javax.swing.JFrame {
|
||||
setMinimumSize(new java.awt.Dimension(640, 480));
|
||||
setPreferredSize(new java.awt.Dimension(800, 561));
|
||||
|
||||
javax.swing.GroupLayout chart1Layout = new javax.swing.GroupLayout(chart1);
|
||||
chart1.setLayout(chart1Layout);
|
||||
chart1Layout.setHorizontalGroup(
|
||||
chart1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
javax.swing.GroupLayout chartLayout = new javax.swing.GroupLayout(chart);
|
||||
chart.setLayout(chartLayout);
|
||||
chartLayout.setHorizontalGroup(
|
||||
chartLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGap(0, 300, Short.MAX_VALUE)
|
||||
);
|
||||
chart1Layout.setVerticalGroup(
|
||||
chart1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
chartLayout.setVerticalGroup(
|
||||
chartLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGap(0, 300, Short.MAX_VALUE)
|
||||
);
|
||||
|
||||
jScrollPane1.setViewportView(chart1);
|
||||
jChartScrollPane.setViewportView(chart);
|
||||
|
||||
jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/toolbarButtonGraphics/general/Stop24.gif"))); // NOI18N
|
||||
jButton1.setText("Stop");
|
||||
jButton1.setFocusable(false);
|
||||
jButton1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
|
||||
jButton1.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
|
||||
jButton1.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
jButton1ActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
jRunButton.setFont(jRunButton.getFont());
|
||||
jRunButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/run.gif"))); // NOI18N
|
||||
@ -219,7 +210,7 @@ public class NewMDIApplication extends javax.swing.JFrame {
|
||||
}
|
||||
});
|
||||
|
||||
jSpinner2.setModel(new javax.swing.SpinnerNumberModel(0.0d, 0.0d, 10000.0d, 0.1d));
|
||||
jSpinner2.setModel(new javax.swing.SpinnerNumberModel(1.0d, 0.0d, null, 100.0d));
|
||||
jSpinner2.addChangeListener(new javax.swing.event.ChangeListener() {
|
||||
public void stateChanged(javax.swing.event.ChangeEvent evt) {
|
||||
jSpinner2StateChanged(evt);
|
||||
@ -260,6 +251,15 @@ public class NewMDIApplication extends javax.swing.JFrame {
|
||||
fileMenu.setMnemonic('f');
|
||||
fileMenu.setText("File");
|
||||
|
||||
jMenuItem1.setMnemonic('n');
|
||||
jMenuItem1.setText("New");
|
||||
jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
jMenuItem1ActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
fileMenu.add(jMenuItem1);
|
||||
|
||||
openMenuItem.setMnemonic('o');
|
||||
openMenuItem.setText("Open");
|
||||
openMenuItem.addActionListener(new java.awt.event.ActionListener() {
|
||||
@ -337,6 +337,29 @@ public class NewMDIApplication extends javax.swing.JFrame {
|
||||
|
||||
menuBar.add(editMenu);
|
||||
|
||||
jMenu1.setText("Sim");
|
||||
|
||||
jMenuItem4.setText("Start");
|
||||
jMenuItem4.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
jMenuItem4ActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
jMenu1.add(jMenuItem4);
|
||||
|
||||
jMenuItem5.setText("Stop");
|
||||
jMenu1.add(jMenuItem5);
|
||||
|
||||
jMenuItem6.setText("Reset");
|
||||
jMenuItem6.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
jMenuItem6ActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
jMenu1.add(jMenuItem6);
|
||||
|
||||
menuBar.add(jMenu1);
|
||||
|
||||
viewMenu.setText("View");
|
||||
|
||||
jMenuItem2.setText("Traders");
|
||||
@ -394,9 +417,9 @@ public class NewMDIApplication extends javax.swing.JFrame {
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addComponent(orderBookPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 233, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(orderBookPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 233, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(jScrollPane1)))
|
||||
.addComponent(jChartScrollPane)))
|
||||
.addContainerGap())
|
||||
);
|
||||
layout.setVerticalGroup(
|
||||
@ -406,8 +429,8 @@ public class NewMDIApplication extends javax.swing.JFrame {
|
||||
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(jScrollPane1)
|
||||
.addComponent(orderBookPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
|
||||
.addComponent(jChartScrollPane)
|
||||
.addComponent(orderBookPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
|
||||
.addContainerGap())
|
||||
);
|
||||
|
||||
@ -424,9 +447,32 @@ public class NewMDIApplication extends javax.swing.JFrame {
|
||||
|
||||
}//GEN-LAST:event_aboutMenuItemActionPerformed
|
||||
|
||||
private void jRunButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRunButtonActionPerformed
|
||||
|
||||
void startSim(){
|
||||
resetSim();
|
||||
this.startTraders();
|
||||
Globals.se.timer.start();
|
||||
|
||||
}
|
||||
|
||||
void stopSim(){
|
||||
Globals.se.timer.terminate();
|
||||
}
|
||||
|
||||
void resetSim(){
|
||||
Globals.se.terminate();
|
||||
Globals.se.reset();
|
||||
chart.initChart();
|
||||
chart.invalidate();
|
||||
chart.repaint();
|
||||
this.orderBookPanel.invalidate();
|
||||
this.orderBookPanel.repaint();
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void jRunButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRunButtonActionPerformed
|
||||
startSim();
|
||||
}//GEN-LAST:event_jRunButtonActionPerformed
|
||||
|
||||
private void editPreferencesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editPreferencesActionPerformed
|
||||
@ -527,6 +573,25 @@ public class NewMDIApplication extends javax.swing.JFrame {
|
||||
Globals.se.timer.setMultiply(val);
|
||||
}//GEN-LAST:event_jSpinner2StateChanged
|
||||
|
||||
private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
|
||||
// TODO add your handling code here:
|
||||
}//GEN-LAST:event_jMenuItem1ActionPerformed
|
||||
|
||||
private void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem4ActionPerformed
|
||||
startSim();
|
||||
}//GEN-LAST:event_jMenuItem4ActionPerformed
|
||||
|
||||
private void jMenuItem6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem6ActionPerformed
|
||||
resetSim();
|
||||
|
||||
//this.chart.
|
||||
//this.initComponents();
|
||||
}//GEN-LAST:event_jMenuItem6ActionPerformed
|
||||
|
||||
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
|
||||
stopSim();
|
||||
}//GEN-LAST:event_jButton1ActionPerformed
|
||||
|
||||
/**
|
||||
* @param args the command line arguments
|
||||
* @throws java.lang.IllegalAccessException
|
||||
@ -583,7 +648,7 @@ public class NewMDIApplication extends javax.swing.JFrame {
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private javax.swing.JMenuItem aboutMenuItem;
|
||||
private chart.Chart chart1;
|
||||
private chart.Chart chart;
|
||||
private gui.Clock clock1;
|
||||
private javax.swing.JMenuItem contentMenuItem;
|
||||
private javax.swing.JMenuItem deleteMenuItem;
|
||||
@ -595,11 +660,16 @@ public class NewMDIApplication extends javax.swing.JFrame {
|
||||
private javax.swing.JMenu helpMenu;
|
||||
private javax.swing.JButton jButton1;
|
||||
private javax.swing.JButton jButton2;
|
||||
private javax.swing.JScrollPane jChartScrollPane;
|
||||
private javax.swing.JMenu jMenu1;
|
||||
private javax.swing.JMenuItem jMenuItem1;
|
||||
private javax.swing.JMenuItem jMenuItem2;
|
||||
private javax.swing.JMenuItem jMenuItem3;
|
||||
private javax.swing.JMenuItem jMenuItem4;
|
||||
private javax.swing.JMenuItem jMenuItem5;
|
||||
private javax.swing.JMenuItem jMenuItem6;
|
||||
private javax.swing.JPanel jPanel2;
|
||||
private javax.swing.JButton jRunButton;
|
||||
private javax.swing.JScrollPane jScrollPane1;
|
||||
private javax.swing.JScrollPane jScrollPane2;
|
||||
private javax.swing.JPopupMenu.Separator jSeparator1;
|
||||
private javax.swing.JPopupMenu.Separator jSeparator2;
|
||||
@ -607,7 +677,7 @@ public class NewMDIApplication extends javax.swing.JFrame {
|
||||
private javax.swing.JTextArea jTextArea1;
|
||||
private javax.swing.JMenuBar menuBar;
|
||||
private javax.swing.JMenuItem openMenuItem;
|
||||
private gui.OrderBookPanel orderBookPanel1;
|
||||
private gui.OrderBookPanel orderBookPanel;
|
||||
private javax.swing.JMenuItem pasteMenuItem;
|
||||
private javax.swing.JMenuItem saveAsMenuItem;
|
||||
private javax.swing.JMenuItem saveMenuItem;
|
||||
|
@ -79,6 +79,8 @@ public class TraderListPanel extends javax.swing.JPanel
|
||||
}
|
||||
|
||||
final ArrayList<TraderListItem> getTraderList() {
|
||||
if (se.traders==null)
|
||||
return new ArrayList<>();
|
||||
|
||||
sesim.Quote q = se.getLastQuoete();
|
||||
double price = q == null ? 0 : q.price;
|
||||
|
@ -56,12 +56,12 @@ public class Exchange {
|
||||
IDGenerator account_id = new IDGenerator();
|
||||
//public static Timer timer = new Timer();
|
||||
|
||||
public Scheduler timer = new Scheduler();
|
||||
public Scheduler timer; // = new Scheduler();
|
||||
|
||||
|
||||
|
||||
|
||||
public ArrayList<AutoTrader> traders = new ArrayList();
|
||||
public ArrayList<AutoTrader> traders;
|
||||
|
||||
/**
|
||||
* Implements a trading account
|
||||
@ -113,7 +113,7 @@ public class Exchange {
|
||||
}
|
||||
|
||||
// private final ConcurrentHashMap<Double, Account> accounts = new ConcurrentHashMap<>();
|
||||
private final ConcurrentHashMap<Double, Account> accounts = new ConcurrentHashMap<>();
|
||||
private ConcurrentHashMap<Double, Account> accounts;
|
||||
|
||||
public double createAccount(double money, double shares) {
|
||||
|
||||
@ -167,7 +167,7 @@ public class Exchange {
|
||||
|
||||
}
|
||||
|
||||
HashMap<OrderType, SortedSet<Order>> order_books = new HashMap();
|
||||
HashMap<OrderType, SortedSet<Order>> order_books;
|
||||
|
||||
IDGenerator order_id = new IDGenerator();
|
||||
|
||||
@ -224,21 +224,38 @@ public class Exchange {
|
||||
/**
|
||||
* Histrory of quotes
|
||||
*/
|
||||
public TreeSet<Quote> quoteHistory = new TreeSet<>();
|
||||
public TreeSet<Quote> quoteHistory; // = new TreeSet<>();
|
||||
|
||||
|
||||
final void initExchange(){
|
||||
timer = new Scheduler(); // timer = new Scheduler();
|
||||
random = new Random(12);
|
||||
quoteHistory = new TreeSet();
|
||||
accounts = new ConcurrentHashMap<>();
|
||||
|
||||
traders = new ArrayList();
|
||||
|
||||
num_trades=0;
|
||||
|
||||
|
||||
// Create order books
|
||||
order_books= new HashMap();
|
||||
for (OrderType type : OrderType.values()) {
|
||||
order_books.put(type, new TreeSet(new OrderComparator(type)));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public Exchange() {
|
||||
this.random = new java.util.Random(12);
|
||||
qrlist = (new CopyOnWriteArrayList<>());
|
||||
|
||||
initExchange();
|
||||
|
||||
|
||||
this.qrlist = (new CopyOnWriteArrayList<>());
|
||||
|
||||
// Create order books
|
||||
for (OrderType type : OrderType.values()) {
|
||||
//SortedSet b = new TreeSet(new OrderComparator(type));
|
||||
order_books.put(type, new TreeSet(new OrderComparator(type)));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -262,10 +279,26 @@ public class Exchange {
|
||||
|
||||
}
|
||||
|
||||
void start() {
|
||||
|
||||
|
||||
/**
|
||||
* Start the exchange
|
||||
*/
|
||||
public void start() {
|
||||
timer.start();
|
||||
}
|
||||
|
||||
public void reset(){
|
||||
initExchange();
|
||||
}
|
||||
|
||||
public void terminate() {
|
||||
timer.terminate();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
class BidBook extends TreeSet {
|
||||
|
||||
TreeSet t = new TreeSet();
|
||||
@ -275,6 +308,7 @@ public class Exchange {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
public SortedSet<Quote> getQuoteHistory(long start) {
|
||||
|
||||
@ -366,7 +400,7 @@ public class Exchange {
|
||||
}
|
||||
|
||||
// Here we store the list of quote receivers
|
||||
private final List<QuoteReceiver> qrlist;
|
||||
private List<QuoteReceiver> qrlist;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -455,7 +489,7 @@ public class Exchange {
|
||||
return ret;
|
||||
}
|
||||
|
||||
final Random random;
|
||||
Random random;
|
||||
|
||||
public int randNextInt() {
|
||||
System.out.printf("Next int: %d\n", random.nextInt());
|
||||
@ -463,7 +497,7 @@ public class Exchange {
|
||||
}
|
||||
|
||||
public int randNextInt(int bounds) {
|
||||
System.out.printf("Next doub: %f\n", random.nextDouble());
|
||||
|
||||
return random.nextInt(bounds);
|
||||
}
|
||||
|
||||
@ -493,6 +527,8 @@ public class Exchange {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
@ -25,7 +25,7 @@
|
||||
*/
|
||||
package sesim;
|
||||
|
||||
import static com.sun.org.apache.xalan.internal.lib.ExsltDatetime.date;
|
||||
//import static com.sun.org.apache.xalan.internal.lib.ExsltDatetime.date;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Comparator;
|
||||
@ -44,36 +44,49 @@ public class Scheduler extends Thread {
|
||||
|
||||
private double multiplier = 0.0;
|
||||
|
||||
public void setMultiply(double val){
|
||||
this.multiplier=val;
|
||||
public void setMultiply(double val) {
|
||||
|
||||
this.multiplier = val;
|
||||
synchronized(this){
|
||||
this.notify();
|
||||
}
|
||||
}
|
||||
|
||||
public double getMultiply(){
|
||||
public double getMultiply() {
|
||||
return this.multiplier;
|
||||
}
|
||||
|
||||
private final SortedMap<Long, SortedSet<TimerTask>> event_queue = new TreeMap<>();
|
||||
private boolean halt = false;
|
||||
|
||||
public interface TimerTask {
|
||||
|
||||
long timerTask();
|
||||
}
|
||||
|
||||
private boolean terminate = false;
|
||||
|
||||
/**
|
||||
* \
|
||||
*
|
||||
* Terminate the scheduler
|
||||
*/
|
||||
public void halt() {
|
||||
halt = true;
|
||||
public void terminate() {
|
||||
terminate = true;
|
||||
synchronized (event_queue) {
|
||||
event_queue.notifyAll();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
if (this.isAlive()) {
|
||||
return;
|
||||
}
|
||||
this.initScheduler();
|
||||
super.start();
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private class ObjectComparator implements Comparator<Object> {
|
||||
|
||||
@Override
|
||||
@ -100,8 +113,8 @@ public class Scheduler extends Thread {
|
||||
|
||||
}
|
||||
|
||||
public long currentTimeMillis(){
|
||||
return (long)this.current_time_millis;
|
||||
public long currentTimeMillis() {
|
||||
return (long) this.current_time_millis;
|
||||
}
|
||||
|
||||
static public String formatTimeMillis(long t) {
|
||||
@ -109,10 +122,10 @@ public class Scheduler extends Thread {
|
||||
DateFormat formatter = new SimpleDateFormat("HH:mm:ss");
|
||||
String dateFormatted = formatter.format(date);
|
||||
|
||||
long seconds = (t/1000) % 60;
|
||||
long minutes = (t/1000/60) % 60;
|
||||
long hours = (t/1000)/(60*60);
|
||||
return String.format("%02d:%02d:%02d",hours,minutes, seconds);
|
||||
long seconds = (t / 1000) % 60;
|
||||
long minutes = (t / 1000 / 60) % 60;
|
||||
long hours = (t / 1000) / (60 * 60);
|
||||
return String.format("%02d:%02d:%02d", hours, minutes, seconds);
|
||||
|
||||
}
|
||||
|
||||
@ -148,7 +161,6 @@ public class Scheduler extends Thread {
|
||||
private boolean addEvent(TimerTask e, long evtime) {
|
||||
|
||||
// long evtime = time + currentTimeMillis();
|
||||
|
||||
SortedSet<TimerTask> s = event_queue.get(evtime);
|
||||
if (s == null) {
|
||||
s = new TreeSet<>(new ObjectComparator());
|
||||
@ -167,9 +179,8 @@ public class Scheduler extends Thread {
|
||||
long ct = currentTimeMillis1();
|
||||
|
||||
//System.out.printf("Current CMP %d %d\n", ct, t);
|
||||
|
||||
if (t <= ct) {
|
||||
this.current_time_millis=t;
|
||||
this.current_time_millis = t;
|
||||
SortedSet s = event_queue.get(t);
|
||||
event_queue.remove(t);
|
||||
Iterator<TimerTask> it = s.iterator();
|
||||
@ -177,7 +188,7 @@ public class Scheduler extends Thread {
|
||||
TimerTask e = it.next();
|
||||
long next_t = this.fireEvent(e);
|
||||
|
||||
this.addEvent(e, next_t+t);
|
||||
this.addEvent(e, next_t + t);
|
||||
}
|
||||
return 0;
|
||||
|
||||
@ -189,10 +200,16 @@ public class Scheduler extends Thread {
|
||||
|
||||
}
|
||||
|
||||
void initScheduler() {
|
||||
current_time_millis = 0.0;
|
||||
terminate = false;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
// this.current_time_millis=0;
|
||||
while (!halt) {
|
||||
|
||||
while (!terminate) {
|
||||
|
||||
long wtime = runEvents();
|
||||
|
||||
@ -214,6 +231,8 @@ public class Scheduler extends Thread {
|
||||
}
|
||||
}
|
||||
|
||||
this.event_queue.clear();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -121,7 +121,7 @@ public class RandomTrader extends AutoTrader {
|
||||
return (max - min) * r + min;
|
||||
}
|
||||
|
||||
protected int getRandom(Integer[] minmax) {
|
||||
protected int getRandom(Long[] minmax) {
|
||||
return (int) Math.round(getRandom(minmax[0], minmax[1]));
|
||||
}
|
||||
|
||||
|
@ -44,13 +44,13 @@ public class RandomTraderConfig extends AutoTraderBase implements AutoTraderConf
|
||||
|
||||
public Float[] sell_volume = {100f, 100f};
|
||||
public Float[] sell_limit = {-0.1f, 0.10101f};
|
||||
public Integer[] sell_wait = {10000, 50000};
|
||||
public Integer[] wait_after_sell = {1000, 30000};
|
||||
public Long[] sell_wait = {10000L, 50000L};
|
||||
public Long[] wait_after_sell = {1000L, 30000L};
|
||||
|
||||
public Float[] buy_volume = {100f, 100f};
|
||||
public Float[] buy_limit = {-0.1f, 0.10101f};
|
||||
public Integer[] buy_wait = {10000, 50000};
|
||||
public Integer[] wait_after_buy = {10, 30};
|
||||
public Long[] buy_wait = {10000L, 50000L};
|
||||
public Long[] wait_after_buy = {10L, 30L};
|
||||
|
||||
@Override
|
||||
public AutoTrader createTrader(Exchange se, JSONObject cfg, double money, double shares) {
|
||||
@ -122,6 +122,17 @@ public class RandomTraderConfig extends AutoTraderBase implements AutoTraderConf
|
||||
|
||||
}
|
||||
|
||||
private Long[] to_long(JSONArray a) {
|
||||
Long[] ret = new Long[a.length()];
|
||||
for (int i = 0; i < a.length(); i++) {
|
||||
ret[i] = a.getLong(i);
|
||||
|
||||
}
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
|
||||
private Number[] to_arn(JSONArray a) {
|
||||
Number[] ret = new Number[a.length()];
|
||||
// Float x[] = new Float[2];
|
||||
@ -148,11 +159,11 @@ public class RandomTraderConfig extends AutoTraderBase implements AutoTraderConf
|
||||
buy_volume = to_float(cfg.getJSONArray(BUY_VOLUME));
|
||||
sell_limit = to_float(cfg.getJSONArray(SELL_LIMIT));
|
||||
buy_limit = to_float(cfg.getJSONArray(BUY_LIMIT));
|
||||
sell_wait = to_integer(cfg.getJSONArray(SELL_WAIT));
|
||||
buy_wait = to_integer(cfg.getJSONArray(BUY_WAIT));
|
||||
sell_wait = to_long(cfg.getJSONArray(SELL_WAIT));
|
||||
buy_wait = to_long(cfg.getJSONArray(BUY_WAIT));
|
||||
|
||||
wait_after_sell = to_integer(cfg.getJSONArray(WAIT_AFTER_SELL));
|
||||
wait_after_buy = to_integer(cfg.getJSONArray(WAIT_AFTER_BUY));
|
||||
wait_after_sell = to_long(cfg.getJSONArray(WAIT_AFTER_SELL));
|
||||
wait_after_buy = to_long(cfg.getJSONArray(WAIT_AFTER_BUY));
|
||||
|
||||
}
|
||||
|
||||
|
@ -220,28 +220,28 @@
|
||||
<Component class="javax.swing.JSpinner" name="buyWaitMin">
|
||||
<Properties>
|
||||
<Property name="model" type="javax.swing.SpinnerModel" editor="org.netbeans.modules.form.editors2.SpinnerModelEditor">
|
||||
<SpinnerModel initial="0" minimum="0" numberType="java.lang.Integer" stepSize="1000" type="number"/>
|
||||
<SpinnerModel initial="0" minimum="0" numberType="java.lang.Long" stepSize="1000" type="number"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component class="javax.swing.JSpinner" name="sellWaitMin">
|
||||
<Properties>
|
||||
<Property name="model" type="javax.swing.SpinnerModel" editor="org.netbeans.modules.form.editors2.SpinnerModelEditor">
|
||||
<SpinnerModel initial="0" minimum="0" numberType="java.lang.Integer" stepSize="1000" type="number"/>
|
||||
<SpinnerModel initial="0" minimum="0" numberType="java.lang.Long" stepSize="1000" type="number"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component class="javax.swing.JSpinner" name="sellWaitMax">
|
||||
<Properties>
|
||||
<Property name="model" type="javax.swing.SpinnerModel" editor="org.netbeans.modules.form.editors2.SpinnerModelEditor">
|
||||
<SpinnerModel initial="0" minimum="0" numberType="java.lang.Integer" stepSize="1000" type="number"/>
|
||||
<SpinnerModel initial="0" minimum="0" numberType="java.lang.Long" stepSize="1000" type="number"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component class="javax.swing.JSpinner" name="buyWaitMax">
|
||||
<Properties>
|
||||
<Property name="model" type="javax.swing.SpinnerModel" editor="org.netbeans.modules.form.editors2.SpinnerModelEditor">
|
||||
<SpinnerModel initial="0" minimum="0" numberType="java.lang.Integer" stepSize="1000" type="number"/>
|
||||
<SpinnerModel initial="0" minimum="0" numberType="java.lang.Long" stepSize="1000" type="number"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
</Component>
|
||||
|
@ -79,15 +79,15 @@ public class RandomTraderGui extends AutoTraderGui {
|
||||
cfg.buy_limit[1] = (Float) this.buyLimitMax.getValue();
|
||||
cfg.sell_limit[0] = (Float) this.sellLimitMin.getValue();
|
||||
cfg.sell_limit[1] = (Float) this.sellLimitMax.getValue();
|
||||
cfg.buy_wait[0] = (Integer) this.buyWaitMin.getValue();
|
||||
cfg.buy_wait[1] = (Integer) this.buyWaitMax.getValue();
|
||||
cfg.sell_wait[0] = (Integer) this.sellWaitMin.getValue();
|
||||
cfg.sell_wait[1] = (Integer) this.sellWaitMax.getValue();
|
||||
cfg.buy_wait[0] = (Long) this.buyWaitMin.getValue();
|
||||
cfg.buy_wait[1] = (Long) this.buyWaitMax.getValue();
|
||||
cfg.sell_wait[0] = (Long) this.sellWaitMin.getValue();
|
||||
cfg.sell_wait[1] = (Long) this.sellWaitMax.getValue();
|
||||
|
||||
cfg.wait_after_buy[0] = (Integer) this.waitAfterBuyMin.getValue();
|
||||
cfg.wait_after_buy[1] = (Integer) this.waitAfterBuyMax.getValue();
|
||||
cfg.wait_after_sell[0] = (Integer) this.waitAfterSellMin.getValue();
|
||||
cfg.wait_after_sell[1] = (Integer) this.waitAfterSellMax.getValue();
|
||||
cfg.wait_after_buy[0] = (Long) this.waitAfterBuyMin.getValue();
|
||||
cfg.wait_after_buy[1] = (Long) this.waitAfterBuyMax.getValue();
|
||||
cfg.wait_after_sell[0] = (Long) this.waitAfterSellMin.getValue();
|
||||
cfg.wait_after_sell[1] = (Long) this.waitAfterSellMax.getValue();
|
||||
|
||||
|
||||
// cfg.buy_volume[0] = Float.parseFloat(this.buyVolMin.getText());
|
||||
@ -153,13 +153,13 @@ public class RandomTraderGui extends AutoTraderGui {
|
||||
|
||||
setBorder(null);
|
||||
|
||||
buyWaitMin.setModel(new javax.swing.SpinnerNumberModel(0, 0, null, 1000));
|
||||
buyWaitMin.setModel(new javax.swing.SpinnerNumberModel(0L, 0L, null, 1000L));
|
||||
|
||||
sellWaitMin.setModel(new javax.swing.SpinnerNumberModel(0, 0, null, 1000));
|
||||
sellWaitMin.setModel(new javax.swing.SpinnerNumberModel(0L, 0L, null, 1000L));
|
||||
|
||||
sellWaitMax.setModel(new javax.swing.SpinnerNumberModel(0, 0, null, 1000));
|
||||
sellWaitMax.setModel(new javax.swing.SpinnerNumberModel(0L, 0L, null, 1000L));
|
||||
|
||||
buyWaitMax.setModel(new javax.swing.SpinnerNumberModel(0, 0, null, 1000));
|
||||
buyWaitMax.setModel(new javax.swing.SpinnerNumberModel(0L, 0L, null, 1000L));
|
||||
|
||||
buyLimitMin.setModel(new javax.swing.SpinnerNumberModel(0.0f, -100.0f, null, 1.0f));
|
||||
|
||||
|
@ -47,13 +47,13 @@ public class SwitchingTraderConfig extends RandomTraderConfig implements AutoTra
|
||||
|
||||
sell_volume = new Float[]{17f, 100f};
|
||||
sell_limit = new Float[]{-30f, 1f};
|
||||
sell_wait = new Integer[]{1, 5};
|
||||
wait_after_sell = new Integer[]{1, 5};
|
||||
sell_wait = new Long[]{1L, 5L};
|
||||
wait_after_sell = new Long[]{1L, 5L};
|
||||
|
||||
buy_volume = new Float[]{18f, 100f};
|
||||
buy_limit = new Float[]{-1f, 30f};
|
||||
buy_wait = new Integer[]{1, 5};
|
||||
wait_after_buy = new Integer[]{1, 5};
|
||||
buy_wait = new Long[]{1L, 5L};
|
||||
wait_after_buy = new Long[]{1L, 5L};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user