Some improvements

This commit is contained in:
7u83 2017-02-16 18:37:08 +01:00
parent e8b1c63768
commit 44b7c68d73
9 changed files with 432 additions and 33 deletions

View File

@ -1,6 +1,71 @@
<?xml version="1.0" encoding="UTF-8" ?> <?xml version="1.0" encoding="UTF-8" ?>
<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JPanelFormInfo"> <Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
<NonVisualComponents>
<Container class="javax.swing.JPopupMenu" name="ctxMenu">
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout">
<Property name="useNullLayout" type="boolean" value="true"/>
</Layout>
<SubComponents>
<Menu class="javax.swing.JMenu" name="jMenu1">
<Properties>
<Property name="text" type="java.lang.String" value="Compression"/>
</Properties>
<SubComponents>
<MenuItem class="javax.swing.JMenuItem" name="ctxMenuComp5s">
<Properties>
<Property name="text" type="java.lang.String" value="5 s"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="ctxMenuComp5sActionPerformed"/>
</Events>
</MenuItem>
<MenuItem class="javax.swing.JMenuItem" name="ctxMenuComp1m">
<Properties>
<Property name="text" type="java.lang.String" value="1 min"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="ctxMenuComp1mActionPerformed"/>
</Events>
</MenuItem>
<MenuItem class="javax.swing.JMenuItem" name="ctxMenuComp5min">
<Properties>
<Property name="text" type="java.lang.String" value="5 min"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="ctxMenuComp5minActionPerformed"/>
</Events>
</MenuItem>
<MenuItem class="javax.swing.JMenuItem" name="ctxMenuComp1h">
<Properties>
<Property name="text" type="java.lang.String" value="1 h"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="ctxMenuComp1hActionPerformed"/>
</Events>
</MenuItem>
<MenuItem class="javax.swing.JMenuItem" name="ctxMenuComp4h">
<Properties>
<Property name="text" type="java.lang.String" value="4 h"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="ctxMenuComp4hActionPerformed"/>
</Events>
</MenuItem>
<MenuItem class="javax.swing.JMenuItem" name="ctxMenuComp1d">
<Properties>
<Property name="text" type="java.lang.String" value="1 d"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="ctxMenuComp1dActionPerformed"/>
</Events>
</MenuItem>
</SubComponents>
</Menu>
</SubComponents>
</Container>
</NonVisualComponents>
<Properties> <Properties>
<Property name="background" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor"> <Property name="background" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="ff" green="ff" id="white" palette="1" red="ff" type="palette"/> <Color blue="ff" green="ff" id="white" palette="1" red="ff" type="palette"/>
@ -14,6 +79,9 @@
</Property> </Property>
<Property name="requestFocusEnabled" type="boolean" value="false"/> <Property name="requestFocusEnabled" type="boolean" value="false"/>
</Properties> </Properties>
<Events>
<EventHandler event="mousePressed" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="formMousePressed"/>
</Events>
<AuxValues> <AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/> <AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/> <AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>

View File

@ -38,11 +38,11 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver, Scrollab
protected Dimension gdim; protected Dimension gdim;
private int first_bar, last_bar; private int first_bar, last_bar;
public final void initChart() {
public final void initChart(){
// data = new OHLCData(60000*30); // data = new OHLCData(60000*30);
data = new OHLCData(60000*15); //data = new OHLCData(60000*30);
data = Globals.se.getOHLCdata(60000 * 30);
} }
/** /**
@ -51,6 +51,7 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver, Scrollab
public Chart() { public Chart() {
initComponents(); initComponents();
initChart(); initChart();
//setCompression(60000);
if (Globals.se == null) { if (Globals.se == null) {
return; return;
} }
@ -59,16 +60,13 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver, Scrollab
} }
OHLCData data; OHLCData data;
OHLCDataItem current = null; OHLCDataItem current = null;
//void drawCandle(Graphics2D g, OHLCData d, int x, int y) { //void drawCandle(Graphics2D g, OHLCData d, int x, int y) {
// //
// } // }
@Override @Override
public Dimension getPreferredScrollableViewportSize() { public Dimension getPreferredScrollableViewportSize() {
return this.getPreferredSize(); return this.getPreferredSize();
@ -105,7 +103,7 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver, Scrollab
} }
String getAt(int unit) { String getAt(int unit) {
Date date = new Date(/*sesim.Scheduler.timeStart*/ 0 + unit * 5000); Date date = new Date(/*sesim.Scheduler.timeStart*/0 + unit * 5000);
// DateFormat formatter = new SimpleDateFormat("HH:mm:ss:SSS"); // DateFormat formatter = new SimpleDateFormat("HH:mm:ss:SSS");
DateFormat formatter = new SimpleDateFormat("HH:mm:ss"); DateFormat formatter = new SimpleDateFormat("HH:mm:ss");
String dateFormatted = formatter.format(date); String dateFormatted = formatter.format(date);
@ -188,25 +186,19 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver, Scrollab
float getY(float y) { float getY(float y) {
if (logs) { if (logs) {
float m = c_mm.max/c_mm.min; float m = c_mm.max / c_mm.min;
//System.out.printf("Min: %f Max: %f M: %f\n",c_mm.min,c_mm.max,m); //System.out.printf("Min: %f Max: %f M: %f\n",c_mm.min,c_mm.max,m);
//float fac = (float) c_rect.height /(float) Math.log(c_mm.max * c_yscaling); //float fac = (float) c_rect.height /(float) Math.log(c_mm.max * c_yscaling);
float fac = (float) c_rect.height /(float)Math.log(m); float fac = (float) c_rect.height / (float) Math.log(m);
float fmin = c_rect.height - ((float) Math.log((y / c_mm.min)) * fac); float fmin = c_rect.height - ((float) Math.log((y / c_mm.min)) * fac);
//System.out.printf("Fac: %f fmin: %f\n", fac, fmin); //System.out.printf("Fac: %f fmin: %f\n", fac, fmin);
return fmin; return fmin;
//return c_rect.height - ((float) Math.log((y - c_mm.min) * c_yscaling) * fac); //return c_rect.height - ((float) Math.log((y - c_mm.min) * c_yscaling) * fac);
} }
return c_rect.height - ((y - c_mm.min) * c_yscaling); return c_rect.height - ((y - c_mm.min) * c_yscaling);
@ -294,14 +286,12 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver, Scrollab
int yw = (int) (this.y_legend_width * this.em_size); int yw = (int) (this.y_legend_width * this.em_size);
// System.out.printf("MinMax: %f %f\n", c_mm.min, c_mm.max); // System.out.printf("MinMax: %f %f\n", c_mm.min, c_mm.max);
g.drawLine(dim.width + dim.x - yw, 0, dim.width + dim.x - yw, dim.height); g.drawLine(dim.width + dim.x - yw, 0, dim.width + dim.x - yw, dim.height);
// float yscale = gdim.height / c_mm.getDiff(); // float yscale = gdim.height / c_mm.getDiff();
c_yscaling = c_rect.height / c_mm.getDiff(); c_yscaling = c_rect.height / c_mm.getDiff();
// System.out.printf("yscale %f\n", c_yscaling); // System.out.printf("yscale %f\n", c_yscaling);
for (float y = c_mm.min; y < c_mm.max; y += c_mm.getDiff() / 10.0) { for (float y = c_mm.min; y < c_mm.max; y += c_mm.getDiff() / 10.0) {
int my = (int) getY(y); //c_rect.height - (int) ((y - c_mm.min) * c_yscaling); int my = (int) getY(y); //c_rect.height - (int) ((y - c_mm.min) * c_yscaling);
@ -349,7 +339,7 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver, Scrollab
//this.getSize(); //this.getSize();
int pwidth = em_width * num_bars; int pwidth = em_width * num_bars;
int phight = 400; int phight = 400;
// phight=this.getVisibleRect().height; // phight=this.getVisibleRect().height;
this.setPreferredSize(new Dimension(pwidth, gdim.height)); this.setPreferredSize(new Dimension(pwidth, gdim.height));
this.revalidate(); this.revalidate();
@ -414,9 +404,7 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver, Scrollab
this.initEmSize(g); this.initEmSize(g);
this.gdim = this.getParent().getSize(gdim); this.gdim = this.getParent().getSize(gdim);
this.getParent().setPreferredSize(gdim); this.getParent().setPreferredSize(gdim);
this.clip_bounds = g.getClipBounds(this.clip_bounds); this.clip_bounds = g.getClipBounds(this.clip_bounds);
// System.out.printf("X:%d %d\n",gdim.width,gdim.height); // System.out.printf("X:%d %d\n",gdim.width,gdim.height);
@ -437,11 +425,77 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver, Scrollab
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() { private void initComponents() {
ctxMenu = new javax.swing.JPopupMenu();
jMenu1 = new javax.swing.JMenu();
ctxMenuComp5s = new javax.swing.JMenuItem();
ctxMenuComp1m = new javax.swing.JMenuItem();
ctxMenuComp5min = new javax.swing.JMenuItem();
ctxMenuComp1h = new javax.swing.JMenuItem();
ctxMenuComp4h = new javax.swing.JMenuItem();
ctxMenuComp1d = new javax.swing.JMenuItem();
jMenu1.setText("Compression");
ctxMenuComp5s.setText("5 s");
ctxMenuComp5s.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
ctxMenuComp5sActionPerformed(evt);
}
});
jMenu1.add(ctxMenuComp5s);
ctxMenuComp1m.setText("1 min");
ctxMenuComp1m.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
ctxMenuComp1mActionPerformed(evt);
}
});
jMenu1.add(ctxMenuComp1m);
ctxMenuComp5min.setText("5 min");
ctxMenuComp5min.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
ctxMenuComp5minActionPerformed(evt);
}
});
jMenu1.add(ctxMenuComp5min);
ctxMenuComp1h.setText("1 h");
ctxMenuComp1h.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
ctxMenuComp1hActionPerformed(evt);
}
});
jMenu1.add(ctxMenuComp1h);
ctxMenuComp4h.setText("4 h");
ctxMenuComp4h.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
ctxMenuComp4hActionPerformed(evt);
}
});
jMenu1.add(ctxMenuComp4h);
ctxMenuComp1d.setText("1 d");
ctxMenuComp1d.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
ctxMenuComp1dActionPerformed(evt);
}
});
jMenu1.add(ctxMenuComp1d);
ctxMenu.add(jMenu1);
setBackground(java.awt.Color.white); setBackground(java.awt.Color.white);
setBorder(null); setBorder(null);
setOpaque(false); setOpaque(false);
setPreferredSize(new java.awt.Dimension(300, 300)); setPreferredSize(new java.awt.Dimension(300, 300));
setRequestFocusEnabled(false); setRequestFocusEnabled(false);
addMouseListener(new java.awt.event.MouseAdapter() {
public void mousePressed(java.awt.event.MouseEvent evt) {
formMousePressed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout); this.setLayout(layout);
@ -455,17 +509,65 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver, Scrollab
); );
}// </editor-fold>//GEN-END:initComponents }// </editor-fold>//GEN-END:initComponents
private void formMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_formMousePressed
System.out.printf("Mouse ohlc was pressed\n");
if (!evt.isPopupTrigger()) {
return;
};
this.ctxMenu.show(this, evt.getX(), evt.getY());
}//GEN-LAST:event_formMousePressed
void setCompression(int timeFrame) {
data = Globals.se.getOHLCdata(timeFrame);
repaint();
}
private void ctxMenuComp1mActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ctxMenuComp1mActionPerformed
this.setCompression(60000);
}//GEN-LAST:event_ctxMenuComp1mActionPerformed
private void ctxMenuComp1hActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ctxMenuComp1hActionPerformed
this.setCompression(60000*60);
}//GEN-LAST:event_ctxMenuComp1hActionPerformed
private void ctxMenuComp4hActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ctxMenuComp4hActionPerformed
this.setCompression(60000*60*4);
}//GEN-LAST:event_ctxMenuComp4hActionPerformed
private void ctxMenuComp1dActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ctxMenuComp1dActionPerformed
this.setCompression(60000*60*24);
}//GEN-LAST:event_ctxMenuComp1dActionPerformed
private void ctxMenuComp5sActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ctxMenuComp5sActionPerformed
this.setCompression(1000*5);
}//GEN-LAST:event_ctxMenuComp5sActionPerformed
private void ctxMenuComp5minActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ctxMenuComp5minActionPerformed
this.setCompression(60*1000*5);
}//GEN-LAST:event_ctxMenuComp5minActionPerformed
@Override @Override
public void UpdateQuote(Quote q) { public void UpdateQuote(Quote q) {
// System.out.print("Quote Received\n"); // System.out.print("Quote Received\n");
// this.realTimeAdd(q.time, (float) q.price, (float)q.volume); // this.realTimeAdd(q.time, (float) q.price, (float)q.volume);
data.realTimeAdd(q.time, (float) q.price, (float) q.volume); // data.realTimeAdd(q.time, (float) q.price, (float) q.volume);
// this.invalidate(); // this.invalidate();
this.repaint(); this.repaint();
} }
// Variables declaration - do not modify//GEN-BEGIN:variables // Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JPopupMenu ctxMenu;
private javax.swing.JMenuItem ctxMenuComp1d;
private javax.swing.JMenuItem ctxMenuComp1h;
private javax.swing.JMenuItem ctxMenuComp1m;
private javax.swing.JMenuItem ctxMenuComp4h;
private javax.swing.JMenuItem ctxMenuComp5min;
private javax.swing.JMenuItem ctxMenuComp5s;
private javax.swing.JMenu jMenu1;
// End of variables declaration//GEN-END:variables // End of variables declaration//GEN-END:variables
} }

View File

@ -31,7 +31,7 @@ import org.json.JSONObject;
* *
* @author 7u83 <7u83@mail.ru> * @author 7u83 <7u83@mail.ru>
*/ */
public class EditExchangeDialog extends javax.swing.JDialog { public class EditExchangeDialog extends EscDialog /*javax.swing.JDialog*/ {
/** /**
* Creates new form EditExchnageDialog * Creates new form EditExchnageDialog
@ -40,9 +40,11 @@ public class EditExchangeDialog extends javax.swing.JDialog {
super(parent, modal); super(parent, modal);
initComponents(); initComponents();
this.setLocationRelativeTo(parent); this.setLocationRelativeTo(parent);
JSONObject jo = new JSONObject(Globals.prefs.get("Exchange", "{}")); JSONObject jo = new JSONObject(Globals.prefs.get("Exchange", Globals.DEFAULT_EXCHANGE_CFG));
this.moneyDecimalsSpinner.setValue(jo.getInt(Globals.se.CFG_MONEY_DECIMALS));
this.sharesDecimalsSpinner.setValue(jo.getInt(Globals.se.CFG_SHARES_DECIMALS)); this.moneyDecimalsSpinner.setValue(jo.getInt(Globals.se.CFG_MONEY_DECIMALS));
this.sharesDecimalsSpinner.setValue(jo.getInt(Globals.se.CFG_SHARES_DECIMALS));
this.setLocationRelativeTo(parent);
} }
int showdialog() { int showdialog() {

View File

@ -37,6 +37,13 @@ public class EscDialog extends javax.swing.JDialog {
public EscDialog(java.awt.Frame parent, boolean modal) { public EscDialog(java.awt.Frame parent, boolean modal) {
super(parent, modal); super(parent, modal);
initComponents(); initComponents();
System.out.printf("Adding Key Listener\n", "");
addKeyListener(new java.awt.event.KeyAdapter() {
public void keyReleased(java.awt.event.KeyEvent evt) {
formKeyReleased(evt);
}
});
this.setLocationRelativeTo(parent);
} }
/** /**

View File

@ -79,6 +79,13 @@ public class Globals {
public static final String GODMODE = "godmode"; public static final String GODMODE = "godmode";
} }
public static String DEFAULT_EXCHANGE_CFG =
"{"
+ " money_decimals: 2,"
+ " shares_decimals: 0"
+ "}";
//CfgStrings //CfgStrings

View File

@ -186,7 +186,7 @@ public class OrdersList extends javax.swing.JPanel {
}// </editor-fold>//GEN-END:initComponents }// </editor-fold>//GEN-END:initComponents
private void tableMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tableMousePressed private void tableMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tableMousePressed
System.out.printf("The mouse is here\n");
Point point = evt.getPoint(); Point point = evt.getPoint();
int currentRow = table.rowAtPoint(point); int currentRow = table.rowAtPoint(point);

View File

@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JDialogFormInfo">
<Properties>
<Property name="defaultCloseOperation" type="int" value="2"/>
</Properties>
<SyntheticProperties>
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
<SyntheticProperty name="generateCenter" type="boolean" value="false"/>
</SyntheticProperties>
<AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
</AuxValues>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="400" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="300" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
</Layout>
</Form>

111
src/main/java/gui/ZZZ.java Normal file
View File

@ -0,0 +1,111 @@
/*
* Copyright (c) 2017, tobias
* 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 gui;
/**
*
* @author tobias
*/
public class ZZZ extends EscDialog {
/**
* Creates new form ZZZ
*/
public ZZZ(java.awt.Frame parent, boolean modal) {
super(parent, modal);
initComponents();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 400, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 300, Short.MAX_VALUE)
);
pack();
}// </editor-fold>//GEN-END:initComponents
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(ZZZ.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(ZZZ.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(ZZZ.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(ZZZ.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the dialog */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
ZZZ dialog = new ZZZ(new javax.swing.JFrame(), true);
dialog.addWindowListener(new java.awt.event.WindowAdapter() {
@Override
public void windowClosing(java.awt.event.WindowEvent e) {
System.exit(0);
}
});
dialog.setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
// End of variables declaration//GEN-END:variables
}

View File

@ -68,6 +68,55 @@ public class Exchange {
public void accountUpdated(Account a, Order o); public void accountUpdated(Account a, Order o);
} }
HashMap<Integer, OHLCData> ohlc_data = new HashMap<>();
public OHLCData buildOHLCData(int timeFrame) {
OHLCData data = new OHLCData(timeFrame);
if (this.quoteHistory == null) {
return data;
}
Iterator<Quote> it = quoteHistory.iterator();
while (it.hasNext()) {
Quote q = it.next();
data.realTimeAdd(q.time, (float) q.price, (float) q.volume);
}
return data;
}
public OHLCData getOHLCdata(Integer timeFrame) {
OHLCData data; //=new OHLCData(timeFrame);
data = ohlc_data.get(timeFrame);
if (data == null){
// data = new OHLCData(timeFrame);
data = this.buildOHLCData(timeFrame);
ohlc_data.put(timeFrame, data);
}
return data;
/* try {
data = ohlc_data.get(timeFrame);
} catch (Exception e) {
data = null;
}
if (data == null) {
data = buildOHLCData(timeFrame);
}
*/
}
void updateOHLCData(Quote q) {
Iterator<OHLCData> it = ohlc_data.values().iterator();
while (it.hasNext()) {
OHLCData data = it.next();
data.realTimeAdd(q.time, (float) q.price, (float) q.volume);
}
}
/** /**
* Implements a trading account * Implements a trading account
*/ */
@ -279,6 +328,8 @@ public class Exchange {
traders = new ArrayList(); traders = new ArrayList();
num_trades = 0; num_trades = 0;
this.ohlc_data = new HashMap();
// Create order books // Create order books
order_books = new HashMap(); order_books = new HashMap();
@ -385,6 +436,10 @@ public class Exchange {
} }
tradelock.unlock(); tradelock.unlock();
if (lq == null && b == null && a == null) {
return null;
}
if (a != null && b != null) { if (a != null && b != null) {
Quote q = new Quote(); Quote q = new Quote();
if (lq == null) { if (lq == null) {
@ -399,11 +454,17 @@ public class Exchange {
q.price = a.limit; q.price = a.limit;
return q; return q;
} }
return lq;
} }
if (a != null) { if (a != null) {
Quote q = new Quote(); Quote q = new Quote();
if (lq == null) { if (lq == null) {
q.price = a.limit;
return q;
}
if (lq.price > a.limit) {
q.price = a.limit; q.price = a.limit;
return q; return q;
} }
@ -416,10 +477,15 @@ public class Exchange {
q.price = b.limit; q.price = b.limit;
return q; return q;
} }
if (lq.price < b.limit) {
q.price = b.limit;
return q;
}
return lq; return lq;
} }
return null; return lq;
} }
// Class to describe an executed order // Class to describe an executed order
@ -710,6 +776,7 @@ public class Exchange {
// System.out.print("There was a trade:"+q.price+"\n"); // System.out.print("There was a trade:"+q.price+"\n");
this.quoteHistory.add(q); this.quoteHistory.add(q);
this.updateOHLCData(q);
this.updateQuoteReceivers(q); this.updateQuoteReceivers(q);