Interface improved
This commit is contained in:
parent
192e4ecaa8
commit
ad854804fc
@ -9,6 +9,7 @@ import java.awt.*;
|
||||
import sesim.Exchange.*;
|
||||
import sesim.Quote;
|
||||
import gui.MainWin;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
|
||||
@ -41,11 +42,56 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver {
|
||||
|
||||
OHLCDataItem current = null;
|
||||
|
||||
long rasterTime(long time) {
|
||||
/* long rasterTime(long time) {
|
||||
|
||||
long rt = time / 5000;
|
||||
return rt * 5000;
|
||||
|
||||
}
|
||||
*/
|
||||
void drawXLegend(Graphics2D g) {
|
||||
int xl_height = 30;
|
||||
Dimension dim = this.getSize();
|
||||
|
||||
int sheight = g.getFontMetrics().getHeight();
|
||||
|
||||
int y = dim.height - sheight * 3;
|
||||
|
||||
g.drawLine(0, y, dim.width, y);
|
||||
|
||||
|
||||
|
||||
for (int i = 0; i < items; i ++) {
|
||||
int x = i * this.item_width;
|
||||
|
||||
if (i%5==0)
|
||||
g.drawLine(x, y, x, y + 6);
|
||||
else
|
||||
g.drawLine(x, y, x, y + 3);
|
||||
|
||||
OHLCDataItem d;
|
||||
try {
|
||||
d = data.data.get(i);
|
||||
} catch (Exception e) {
|
||||
d = null;
|
||||
}
|
||||
|
||||
String text;
|
||||
if (d != null) {
|
||||
text = " ";
|
||||
} else {
|
||||
text = " ";
|
||||
}
|
||||
|
||||
|
||||
|
||||
int swidth = g.getFontMetrics().stringWidth(text);
|
||||
|
||||
g.drawString(text, x - swidth / 2, y + sheight * 2);
|
||||
|
||||
}
|
||||
|
||||
//for(int x=0; x)
|
||||
}
|
||||
|
||||
private void realTimeAdd(long time, float price, float volume) {
|
||||
@ -58,7 +104,7 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver {
|
||||
|
||||
// System.out.print("new raster ----------------------------------\n");
|
||||
current = null;
|
||||
ntime = rasterTime(time) + 5000;
|
||||
// ntime = rasterTime(time) + 5000;
|
||||
// System.out.print(ntime+"\n");
|
||||
// System.out.print((time)+"\n");
|
||||
// System.exit(0);
|
||||
@ -93,6 +139,9 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver {
|
||||
}
|
||||
|
||||
private void draw(Graphics2D g) {
|
||||
|
||||
this.drawXLegend(g);
|
||||
|
||||
this.getSize();
|
||||
|
||||
int pwidth = item_width * items;
|
||||
@ -105,14 +154,14 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver {
|
||||
|
||||
g.setColor(Color.RED);
|
||||
|
||||
g.drawLine(0, 0, 100, 100);
|
||||
// g.drawLine(0, 0, 100, 100);
|
||||
|
||||
for (int i = 0; i < items; i++) {
|
||||
/* for (int i = 0; i < items; i++) {
|
||||
int x = i * this.item_width;
|
||||
g.drawLine(x, 0, x, 50);
|
||||
|
||||
}
|
||||
|
||||
*/
|
||||
// if (this.current == null) {
|
||||
// return;
|
||||
// }
|
||||
@ -122,12 +171,11 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver {
|
||||
g.setColor(Color.BLUE);
|
||||
g.setStroke(new BasicStroke(3));
|
||||
|
||||
|
||||
Iterator<OHLCDataItem> it = od.iterator();
|
||||
int myi = 0;
|
||||
|
||||
int lastx=0;
|
||||
int lasty=0;
|
||||
int lastx = 0;
|
||||
int lasty = 0;
|
||||
|
||||
while (it.hasNext()) {
|
||||
OHLCDataItem di = it.next();
|
||||
@ -136,8 +184,8 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver {
|
||||
float max = data.max;
|
||||
float min = data.min;
|
||||
|
||||
max = max/10.0f+max;
|
||||
min = min-min/10.0f;
|
||||
max = max / 10.0f + max;
|
||||
min = min - min / 10.0f;
|
||||
|
||||
if (min == max) {
|
||||
min = y / 2;
|
||||
@ -145,9 +193,8 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver {
|
||||
|
||||
}
|
||||
|
||||
// max = 5;
|
||||
// min = 0;
|
||||
|
||||
// max = 5;
|
||||
// min = 0;
|
||||
System.out.print("Fval: " + y + " " + min + "\n");
|
||||
y -= min;
|
||||
System.out.print("VAL New" + y + "\n");
|
||||
@ -155,16 +202,15 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver {
|
||||
//val/ ((data.max-data.min)/dim.height);
|
||||
System.out.print("MINMAX " + min + " " + max + " " + dim.height + "\n");
|
||||
|
||||
y = dim.height-(dim.height * y / (max - min));
|
||||
y = dim.height - (dim.height * y / (max - min));
|
||||
|
||||
int x = myi * this.item_width;
|
||||
myi++;
|
||||
|
||||
g.drawLine(lastx, lasty, x, (int) y);
|
||||
|
||||
lastx=x;
|
||||
lasty=(int)y;
|
||||
|
||||
lastx = x;
|
||||
lasty = (int) y;
|
||||
|
||||
System.out.print("Draw Line: " + x + " " + y + "\n");
|
||||
|
||||
|
@ -22,9 +22,12 @@
|
||||
<Component id="jToolBar1" max="32767" attributes="0"/>
|
||||
<Group type="102" attributes="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Component id="jScrollPane2" pref="245" max="32767" attributes="0"/>
|
||||
<Component id="jScrollPane2" pref="373" max="32767" attributes="0"/>
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<Component id="jCheckBox1" min="-2" max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Component id="jCheckBox1" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="jSplitPane1" alignment="1" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="jScrollPane3" pref="0" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
@ -56,10 +59,12 @@
|
||||
</Group>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Component id="jScrollPane1" alignment="0" pref="197" max="32767" attributes="0"/>
|
||||
<Component id="jScrollPane1" alignment="0" pref="311" max="32767" attributes="0"/>
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<Component id="jCheckBox1" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
|
||||
<EmptySpace max="32767" attributes="0"/>
|
||||
<Component id="jSplitPane1" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace min="-2" pref="43" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<Component id="jScrollPane3" alignment="0" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
@ -141,5 +146,9 @@
|
||||
</Component>
|
||||
</SubComponents>
|
||||
</Container>
|
||||
<Container class="javax.swing.JSplitPane" name="jSplitPane1">
|
||||
|
||||
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout"/>
|
||||
</Container>
|
||||
</SubComponents>
|
||||
</Form>
|
||||
|
@ -56,6 +56,7 @@ public class NewJPanel extends javax.swing.JPanel {
|
||||
jCheckBox1 = new javax.swing.JCheckBox();
|
||||
jScrollPane3 = new javax.swing.JScrollPane();
|
||||
jTextArea2 = new javax.swing.JTextArea();
|
||||
jSplitPane1 = new javax.swing.JSplitPane();
|
||||
|
||||
jToolBar1.setRollover(true);
|
||||
|
||||
@ -88,9 +89,11 @@ public class NewJPanel extends javax.swing.JPanel {
|
||||
.addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 245, Short.MAX_VALUE)
|
||||
.addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 373, Short.MAX_VALUE)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addComponent(jCheckBox1)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(jCheckBox1)
|
||||
.addComponent(jSplitPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
@ -112,10 +115,12 @@ public class NewJPanel extends javax.swing.JPanel {
|
||||
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE)))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 197, Short.MAX_VALUE)
|
||||
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 311, Short.MAX_VALUE)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addComponent(jCheckBox1)
|
||||
.addGap(0, 0, Short.MAX_VALUE))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addComponent(jSplitPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addGap(43, 43, 43))
|
||||
.addComponent(jScrollPane3))
|
||||
.addContainerGap())
|
||||
);
|
||||
@ -129,6 +134,7 @@ public class NewJPanel extends javax.swing.JPanel {
|
||||
private javax.swing.JScrollPane jScrollPane1;
|
||||
private javax.swing.JScrollPane jScrollPane2;
|
||||
private javax.swing.JScrollPane jScrollPane3;
|
||||
private javax.swing.JSplitPane jSplitPane1;
|
||||
private javax.swing.JTextArea jTextArea1;
|
||||
private javax.swing.JTextArea jTextArea2;
|
||||
private javax.swing.JToolBar jToolBar1;
|
||||
|
138
src/main/java/chart/NewMDIApplication.form
Normal file
138
src/main/java/chart/NewMDIApplication.form
Normal file
@ -0,0 +1,138 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
|
||||
<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
|
||||
<NonVisualComponents>
|
||||
<Menu class="javax.swing.JMenuBar" name="menuBar">
|
||||
<SubComponents>
|
||||
<Menu class="javax.swing.JMenu" name="fileMenu">
|
||||
<Properties>
|
||||
<Property name="mnemonic" type="int" value="102"/>
|
||||
<Property name="text" type="java.lang.String" value="File"/>
|
||||
</Properties>
|
||||
<SubComponents>
|
||||
<MenuItem class="javax.swing.JMenuItem" name="openMenuItem">
|
||||
<Properties>
|
||||
<Property name="mnemonic" type="int" value="111"/>
|
||||
<Property name="text" type="java.lang.String" value="Open"/>
|
||||
</Properties>
|
||||
</MenuItem>
|
||||
<MenuItem class="javax.swing.JMenuItem" name="saveMenuItem">
|
||||
<Properties>
|
||||
<Property name="mnemonic" type="int" value="115"/>
|
||||
<Property name="text" type="java.lang.String" value="Save"/>
|
||||
</Properties>
|
||||
</MenuItem>
|
||||
<MenuItem class="javax.swing.JMenuItem" name="saveAsMenuItem">
|
||||
<Properties>
|
||||
<Property name="mnemonic" type="int" value="97"/>
|
||||
<Property name="text" type="java.lang.String" value="Save As ..."/>
|
||||
<Property name="displayedMnemonicIndex" type="int" value="5"/>
|
||||
</Properties>
|
||||
</MenuItem>
|
||||
<MenuItem class="javax.swing.JMenuItem" name="exitMenuItem">
|
||||
<Properties>
|
||||
<Property name="mnemonic" type="int" value="120"/>
|
||||
<Property name="text" type="java.lang.String" value="Exit"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="exitMenuItemActionPerformed"/>
|
||||
</Events>
|
||||
</MenuItem>
|
||||
</SubComponents>
|
||||
</Menu>
|
||||
<Menu class="javax.swing.JMenu" name="editMenu">
|
||||
<Properties>
|
||||
<Property name="mnemonic" type="int" value="101"/>
|
||||
<Property name="text" type="java.lang.String" value="Edit"/>
|
||||
</Properties>
|
||||
<SubComponents>
|
||||
<MenuItem class="javax.swing.JMenuItem" name="cutMenuItem">
|
||||
<Properties>
|
||||
<Property name="mnemonic" type="int" value="116"/>
|
||||
<Property name="text" type="java.lang.String" value="Cut"/>
|
||||
</Properties>
|
||||
</MenuItem>
|
||||
<MenuItem class="javax.swing.JMenuItem" name="copyMenuItem">
|
||||
<Properties>
|
||||
<Property name="mnemonic" type="int" value="121"/>
|
||||
<Property name="text" type="java.lang.String" value="Copy"/>
|
||||
</Properties>
|
||||
</MenuItem>
|
||||
<MenuItem class="javax.swing.JMenuItem" name="pasteMenuItem">
|
||||
<Properties>
|
||||
<Property name="mnemonic" type="int" value="112"/>
|
||||
<Property name="text" type="java.lang.String" value="Paste"/>
|
||||
</Properties>
|
||||
</MenuItem>
|
||||
<MenuItem class="javax.swing.JMenuItem" name="deleteMenuItem">
|
||||
<Properties>
|
||||
<Property name="mnemonic" type="int" value="100"/>
|
||||
<Property name="text" type="java.lang.String" value="Delete"/>
|
||||
</Properties>
|
||||
</MenuItem>
|
||||
</SubComponents>
|
||||
</Menu>
|
||||
<Menu class="javax.swing.JMenu" name="helpMenu">
|
||||
<Properties>
|
||||
<Property name="mnemonic" type="int" value="104"/>
|
||||
<Property name="text" type="java.lang.String" value="Help"/>
|
||||
</Properties>
|
||||
<SubComponents>
|
||||
<MenuItem class="javax.swing.JMenuItem" name="contentMenuItem">
|
||||
<Properties>
|
||||
<Property name="mnemonic" type="int" value="99"/>
|
||||
<Property name="text" type="java.lang.String" value="Contents"/>
|
||||
</Properties>
|
||||
</MenuItem>
|
||||
<MenuItem class="javax.swing.JMenuItem" name="aboutMenuItem">
|
||||
<Properties>
|
||||
<Property name="mnemonic" type="int" value="97"/>
|
||||
<Property name="text" type="java.lang.String" value="About"/>
|
||||
</Properties>
|
||||
</MenuItem>
|
||||
</SubComponents>
|
||||
</Menu>
|
||||
</SubComponents>
|
||||
</Menu>
|
||||
</NonVisualComponents>
|
||||
<Properties>
|
||||
<Property name="defaultCloseOperation" type="int" value="3"/>
|
||||
</Properties>
|
||||
<SyntheticProperties>
|
||||
<SyntheticProperty name="menuBar" type="java.lang.String" value="menuBar"/>
|
||||
<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">
|
||||
<Component id="desktopPane" pref="400" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
<DimensionLayout dim="1">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Component id="desktopPane" pref="279" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
</Layout>
|
||||
<SubComponents>
|
||||
<Container class="javax.swing.JDesktopPane" name="desktopPane">
|
||||
|
||||
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout">
|
||||
<Property name="useNullLayout" type="boolean" value="true"/>
|
||||
</Layout>
|
||||
</Container>
|
||||
</SubComponents>
|
||||
</Form>
|
202
src/main/java/chart/NewMDIApplication.java
Normal file
202
src/main/java/chart/NewMDIApplication.java
Normal file
@ -0,0 +1,202 @@
|
||||
/*
|
||||
* Copyright (c) 2017, 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 chart;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author 7u83 <7u83@mail.ru>
|
||||
*/
|
||||
public class NewMDIApplication extends javax.swing.JFrame {
|
||||
|
||||
/**
|
||||
* Creates new form NewMDIApplication
|
||||
*/
|
||||
public NewMDIApplication() {
|
||||
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() {
|
||||
|
||||
desktopPane = new javax.swing.JDesktopPane();
|
||||
menuBar = new javax.swing.JMenuBar();
|
||||
fileMenu = new javax.swing.JMenu();
|
||||
openMenuItem = new javax.swing.JMenuItem();
|
||||
saveMenuItem = new javax.swing.JMenuItem();
|
||||
saveAsMenuItem = new javax.swing.JMenuItem();
|
||||
exitMenuItem = new javax.swing.JMenuItem();
|
||||
editMenu = new javax.swing.JMenu();
|
||||
cutMenuItem = new javax.swing.JMenuItem();
|
||||
copyMenuItem = new javax.swing.JMenuItem();
|
||||
pasteMenuItem = new javax.swing.JMenuItem();
|
||||
deleteMenuItem = new javax.swing.JMenuItem();
|
||||
helpMenu = new javax.swing.JMenu();
|
||||
contentMenuItem = new javax.swing.JMenuItem();
|
||||
aboutMenuItem = new javax.swing.JMenuItem();
|
||||
|
||||
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
|
||||
|
||||
fileMenu.setMnemonic('f');
|
||||
fileMenu.setText("File");
|
||||
|
||||
openMenuItem.setMnemonic('o');
|
||||
openMenuItem.setText("Open");
|
||||
fileMenu.add(openMenuItem);
|
||||
|
||||
saveMenuItem.setMnemonic('s');
|
||||
saveMenuItem.setText("Save");
|
||||
fileMenu.add(saveMenuItem);
|
||||
|
||||
saveAsMenuItem.setMnemonic('a');
|
||||
saveAsMenuItem.setText("Save As ...");
|
||||
saveAsMenuItem.setDisplayedMnemonicIndex(5);
|
||||
fileMenu.add(saveAsMenuItem);
|
||||
|
||||
exitMenuItem.setMnemonic('x');
|
||||
exitMenuItem.setText("Exit");
|
||||
exitMenuItem.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
exitMenuItemActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
fileMenu.add(exitMenuItem);
|
||||
|
||||
menuBar.add(fileMenu);
|
||||
|
||||
editMenu.setMnemonic('e');
|
||||
editMenu.setText("Edit");
|
||||
|
||||
cutMenuItem.setMnemonic('t');
|
||||
cutMenuItem.setText("Cut");
|
||||
editMenu.add(cutMenuItem);
|
||||
|
||||
copyMenuItem.setMnemonic('y');
|
||||
copyMenuItem.setText("Copy");
|
||||
editMenu.add(copyMenuItem);
|
||||
|
||||
pasteMenuItem.setMnemonic('p');
|
||||
pasteMenuItem.setText("Paste");
|
||||
editMenu.add(pasteMenuItem);
|
||||
|
||||
deleteMenuItem.setMnemonic('d');
|
||||
deleteMenuItem.setText("Delete");
|
||||
editMenu.add(deleteMenuItem);
|
||||
|
||||
menuBar.add(editMenu);
|
||||
|
||||
helpMenu.setMnemonic('h');
|
||||
helpMenu.setText("Help");
|
||||
|
||||
contentMenuItem.setMnemonic('c');
|
||||
contentMenuItem.setText("Contents");
|
||||
helpMenu.add(contentMenuItem);
|
||||
|
||||
aboutMenuItem.setMnemonic('a');
|
||||
aboutMenuItem.setText("About");
|
||||
helpMenu.add(aboutMenuItem);
|
||||
|
||||
menuBar.add(helpMenu);
|
||||
|
||||
setJMenuBar(menuBar);
|
||||
|
||||
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
|
||||
getContentPane().setLayout(layout);
|
||||
layout.setHorizontalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(desktopPane, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
|
||||
);
|
||||
layout.setVerticalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(desktopPane, javax.swing.GroupLayout.DEFAULT_SIZE, 279, Short.MAX_VALUE)
|
||||
);
|
||||
|
||||
pack();
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
|
||||
private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitMenuItemActionPerformed
|
||||
System.exit(0);
|
||||
}//GEN-LAST:event_exitMenuItemActionPerformed
|
||||
|
||||
/**
|
||||
* @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(NewMDIApplication.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||||
} catch (InstantiationException ex) {
|
||||
java.util.logging.Logger.getLogger(NewMDIApplication.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||||
} catch (IllegalAccessException ex) {
|
||||
java.util.logging.Logger.getLogger(NewMDIApplication.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||||
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
|
||||
java.util.logging.Logger.getLogger(NewMDIApplication.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||||
}
|
||||
//</editor-fold>
|
||||
|
||||
/* Create and display the form */
|
||||
java.awt.EventQueue.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
new NewMDIApplication().setVisible(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private javax.swing.JMenuItem aboutMenuItem;
|
||||
private javax.swing.JMenuItem contentMenuItem;
|
||||
private javax.swing.JMenuItem copyMenuItem;
|
||||
private javax.swing.JMenuItem cutMenuItem;
|
||||
private javax.swing.JMenuItem deleteMenuItem;
|
||||
private javax.swing.JDesktopPane desktopPane;
|
||||
private javax.swing.JMenu editMenu;
|
||||
private javax.swing.JMenuItem exitMenuItem;
|
||||
private javax.swing.JMenu fileMenu;
|
||||
private javax.swing.JMenu helpMenu;
|
||||
private javax.swing.JMenuBar menuBar;
|
||||
private javax.swing.JMenuItem openMenuItem;
|
||||
private javax.swing.JMenuItem pasteMenuItem;
|
||||
private javax.swing.JMenuItem saveAsMenuItem;
|
||||
private javax.swing.JMenuItem saveMenuItem;
|
||||
// End of variables declaration//GEN-END:variables
|
||||
|
||||
}
|
@ -36,7 +36,7 @@ public class OHLCData { //extends ArrayList <OHLCDataItem> {
|
||||
float max=0;
|
||||
float min=0;
|
||||
|
||||
int ras=20000;
|
||||
int ras=60000;
|
||||
|
||||
|
||||
long time_start;
|
||||
|
50
src/main/java/gui/AboutDialog.form
Normal file
50
src/main/java/gui/AboutDialog.form
Normal file
@ -0,0 +1,50 @@
|
||||
<?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">
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="jLabel1" pref="388" max="32767" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
<DimensionLayout dim="1">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="jLabel1" min="-2" pref="249" max="-2" attributes="0"/>
|
||||
<EmptySpace pref="45" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
</Layout>
|
||||
<SubComponents>
|
||||
<Component class="javax.swing.JLabel" name="jLabel1">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="jLabel1"/>
|
||||
</Properties>
|
||||
</Component>
|
||||
</SubComponents>
|
||||
</Form>
|
123
src/main/java/gui/AboutDialog.java
Normal file
123
src/main/java/gui/AboutDialog.java
Normal file
@ -0,0 +1,123 @@
|
||||
/*
|
||||
* Copyright (c) 2017, 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 gui;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author 7u83 <7u83@mail.ru>
|
||||
*/
|
||||
public class AboutDialog extends javax.swing.JDialog {
|
||||
|
||||
/**
|
||||
* Creates new form aboutDialog
|
||||
*/
|
||||
public AboutDialog(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() {
|
||||
|
||||
jLabel1 = new javax.swing.JLabel();
|
||||
|
||||
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
|
||||
|
||||
jLabel1.setText("jLabel1");
|
||||
|
||||
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
|
||||
getContentPane().setLayout(layout);
|
||||
layout.setHorizontalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addContainerGap()
|
||||
.addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 388, Short.MAX_VALUE)
|
||||
.addContainerGap())
|
||||
);
|
||||
layout.setVerticalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addContainerGap()
|
||||
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 249, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addContainerGap(45, 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(AboutDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||||
} catch (InstantiationException ex) {
|
||||
java.util.logging.Logger.getLogger(AboutDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||||
} catch (IllegalAccessException ex) {
|
||||
java.util.logging.Logger.getLogger(AboutDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||||
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
|
||||
java.util.logging.Logger.getLogger(AboutDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||||
}
|
||||
//</editor-fold>
|
||||
//</editor-fold>
|
||||
|
||||
/* Create and display the dialog */
|
||||
java.awt.EventQueue.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
AboutDialog dialog = new AboutDialog(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
|
||||
private javax.swing.JLabel jLabel1;
|
||||
// End of variables declaration//GEN-END:variables
|
||||
}
|
@ -51,16 +51,24 @@
|
||||
<Property name="text" type="java.lang.String" value="Edit"/>
|
||||
</Properties>
|
||||
</Menu>
|
||||
<Menu class="javax.swing.JMenu" name="jMenu1">
|
||||
<Menu class="javax.swing.JMenu" name="viewMenu">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="View"/>
|
||||
</Properties>
|
||||
</Menu>
|
||||
<Menu class="javax.swing.JMenu" name="helpMenu">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Help"/>
|
||||
</Properties>
|
||||
<SubComponents>
|
||||
<MenuItem class="javax.swing.JMenuItem" name="jMenuItem2">
|
||||
<MenuItem class="javax.swing.JMenuItem" name="helpAbout">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="About"/>
|
||||
<Property name="toolTipText" type="java.lang.String" value="About this Software"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="helpAboutActionPerformed"/>
|
||||
</Events>
|
||||
</MenuItem>
|
||||
</SubComponents>
|
||||
</Menu>
|
||||
|
@ -25,6 +25,8 @@
|
||||
*/
|
||||
package gui;
|
||||
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.UnsupportedLookAndFeelException;
|
||||
import sesim.AutoTrader;
|
||||
import sesim.Exchange;
|
||||
import traders.RandomTrader;
|
||||
@ -106,8 +108,9 @@ public class MainWin extends javax.swing.JFrame {
|
||||
FileNew = new javax.swing.JMenuItem();
|
||||
FileRun = new javax.swing.JMenuItem();
|
||||
jMenu2 = new javax.swing.JMenu();
|
||||
jMenu1 = new javax.swing.JMenu();
|
||||
jMenuItem2 = new javax.swing.JMenuItem();
|
||||
viewMenu = new javax.swing.JMenu();
|
||||
helpMenu = new javax.swing.JMenu();
|
||||
helpAbout = new javax.swing.JMenuItem();
|
||||
|
||||
jButton1.setText("jButton1");
|
||||
jButton1.addActionListener(new java.awt.event.ActionListener() {
|
||||
@ -149,13 +152,21 @@ public class MainWin extends javax.swing.JFrame {
|
||||
jMenu2.setText("Edit");
|
||||
MainMenu.add(jMenu2);
|
||||
|
||||
jMenu1.setText("Help");
|
||||
viewMenu.setText("View");
|
||||
MainMenu.add(viewMenu);
|
||||
|
||||
jMenuItem2.setText("About");
|
||||
jMenuItem2.setToolTipText("About this Software");
|
||||
jMenu1.add(jMenuItem2);
|
||||
helpMenu.setText("Help");
|
||||
|
||||
MainMenu.add(jMenu1);
|
||||
helpAbout.setText("About");
|
||||
helpAbout.setToolTipText("About this Software");
|
||||
helpAbout.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
helpAboutActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
helpMenu.add(helpAbout);
|
||||
|
||||
MainMenu.add(helpMenu);
|
||||
|
||||
setJMenuBar(MainMenu);
|
||||
|
||||
@ -175,6 +186,11 @@ public class MainWin extends javax.swing.JFrame {
|
||||
se.start();
|
||||
}//GEN-LAST:event_FileRunActionPerformed
|
||||
|
||||
private void helpAboutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_helpAboutActionPerformed
|
||||
AboutDialog d=new AboutDialog(this,true);
|
||||
d.show();
|
||||
}//GEN-LAST:event_helpAboutActionPerformed
|
||||
|
||||
/**
|
||||
* @param args the command line arguments
|
||||
*/
|
||||
@ -187,14 +203,17 @@ public class MainWin extends javax.swing.JFrame {
|
||||
//RandomTrader rt = rcfg.createTrader(se, 1000, 100);
|
||||
//rt.start();
|
||||
|
||||
SwitchingTraderConfig rcfg1 = new SwitchingTraderConfig();
|
||||
// SwitchingTraderConfig rcfg1 = new SwitchingTraderConfig();
|
||||
RandomTraderConfig rcfg1 = new RandomTraderConfig();
|
||||
AutoTrader rt1 = rcfg1.createTrader(se, 1000000, 0);
|
||||
rt1.start();
|
||||
AutoTrader rt2 = rcfg1.createTrader(se, 1, 100);
|
||||
rt2.start();
|
||||
|
||||
|
||||
RandomTraderConfig cfg = new RandomTraderConfig();
|
||||
for (int i=0; i<1000; i++){
|
||||
AutoTrader randt = cfg.createTrader(se, 100, 100);
|
||||
for (int i=0; i<10000; i++){
|
||||
AutoTrader randt = cfg.createTrader(se, 1, 100);
|
||||
randt.start();
|
||||
}
|
||||
|
||||
@ -224,7 +243,7 @@ public class MainWin extends javax.swing.JFrame {
|
||||
// at.add(10, rcfg, se, 1000000, 0);
|
||||
|
||||
|
||||
/* try {
|
||||
/* try {
|
||||
// Set cross-platform Java L&F (also called "Metal")
|
||||
UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
|
||||
} catch (UnsupportedLookAndFeelException | ClassNotFoundException |
|
||||
@ -270,11 +289,12 @@ public class MainWin extends javax.swing.JFrame {
|
||||
private javax.swing.JMenuBar MainMenu;
|
||||
private gui.ControlPanel controlPanel2;
|
||||
private chart.FullChart fullChart2;
|
||||
private javax.swing.JMenuItem helpAbout;
|
||||
private javax.swing.JMenu helpMenu;
|
||||
private javax.swing.JButton jButton1;
|
||||
private javax.swing.JMenu jMenu1;
|
||||
private javax.swing.JMenu jMenu2;
|
||||
private javax.swing.JMenuItem jMenuItem1;
|
||||
private javax.swing.JMenuItem jMenuItem2;
|
||||
private gui.OrderBookPanel orderBookPanel1;
|
||||
private javax.swing.JMenu viewMenu;
|
||||
// End of variables declaration//GEN-END:variables
|
||||
}
|
||||
|
@ -171,7 +171,7 @@ public class RandomTrader extends AutoTrader {
|
||||
double money = getRandomAmmount(ad.money, myconfig.buy_volume);
|
||||
|
||||
Quote q = se.getCurrentPrice();
|
||||
double lp = q == null ? 0.0 : q.price;
|
||||
double lp = q == null ? 0.0001 : q.price;
|
||||
|
||||
|
||||
|
||||
|
@ -37,12 +37,12 @@ public class RandomTraderConfig extends AutoTraderConfig {
|
||||
|
||||
public float[] sell_volume = {100, 100};
|
||||
public float[] sell_limit = {-1, 0};
|
||||
public int[] sell_order_wait = {15, 33};
|
||||
public int[] sell_order_wait = {1, 5};
|
||||
public int[] wait_after_sell = {10, 30};
|
||||
|
||||
public float[] buy_volume = {100, 100};
|
||||
public float[] buy_limit = {0, 1};
|
||||
public int[] buy_order_wait = {15, 33};
|
||||
public int[] buy_order_wait = {1, 5};
|
||||
public int[] wait_after_buy = {10, 30};
|
||||
|
||||
@Override
|
||||
|
@ -1,73 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 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 traders;
|
||||
|
||||
import sesim.Account_old;
|
||||
import sesim.TraderConfig_old;
|
||||
import sesim.Exchange;
|
||||
import sesim.AutoTrader_old;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author 7u83 <7u83@mail.ru>
|
||||
*/
|
||||
public class RandomTraderConfig_old extends TraderConfig_old {
|
||||
|
||||
//public long maxage = 1000 * 10 * 1;
|
||||
|
||||
|
||||
/*public long hold_shares_min = 10;
|
||||
|
||||
public long hold_shares_max = 30;
|
||||
|
||||
public float buy_volume_min = 10;
|
||||
*/
|
||||
|
||||
/**
|
||||
* If shares are selled, this specifies
|
||||
* the minimum and maximum volume to be selled
|
||||
*/
|
||||
public float[] sell_volume= {100,100};
|
||||
public float[] sell_limit = {-15,15};
|
||||
public int[] sell_order_wait = {15,33};
|
||||
public int[] wait_after_sell = {10,30};
|
||||
|
||||
|
||||
public float[] buy_volume={100,100};
|
||||
public float[] buy_limit = {-15,15};
|
||||
public int[] buy_order_wait = {15,33};
|
||||
public int[] wait_after_buy = {10,30};
|
||||
|
||||
|
||||
@Override
|
||||
public AutoTrader_old createTrader(Exchange se, long shares, double money) {
|
||||
Account_old a = new Account_old(se, shares, money);
|
||||
return new RandomTrader_old(a, this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -1,251 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 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 traders;
|
||||
|
||||
import sesim.Account_old;
|
||||
import sesim.Order_old;
|
||||
import java.util.Random;
|
||||
import sesim.AutoTrader_old;
|
||||
import sesim.TraderConfig_old;
|
||||
|
||||
public class RandomTrader_old extends AutoTrader_old {
|
||||
|
||||
protected enum Action {
|
||||
sell,buy
|
||||
}
|
||||
|
||||
// config for this trader
|
||||
final private RandomTraderConfig_old myconfig;
|
||||
|
||||
// object to generate random numbers
|
||||
final private Random rand = new Random();
|
||||
|
||||
public RandomTrader_old(Account_old account, TraderConfig_old config) {
|
||||
super(account, config);
|
||||
if (config == null) {
|
||||
config = new RandomTraderConfig_old();
|
||||
}
|
||||
myconfig = (RandomTraderConfig_old) config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a (long) random number between min an max
|
||||
*
|
||||
* @param min minimum value
|
||||
* @param max maximeum value
|
||||
* @return the number
|
||||
*/
|
||||
protected double getRandom(double min, double max) {
|
||||
double r = rand.nextDouble();
|
||||
return (max - min) * r + min;
|
||||
}
|
||||
|
||||
protected int getRandom(int[] minmax) {
|
||||
return (int) Math.round(getRandom(minmax[0], minmax[1]));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param val
|
||||
* @param minmax
|
||||
* @return
|
||||
*/
|
||||
protected double getRandomAmmount(double val, float[] minmax) {
|
||||
double min = val * minmax[0] / 100.0;
|
||||
double max = val * minmax[1] / 100.0;
|
||||
return getRandom(min, max);
|
||||
}
|
||||
|
||||
public boolean waitForOrder(long seconds) {
|
||||
|
||||
for (int i = 0; (i < seconds) && (0 != account.pending.size()); i++) {
|
||||
doSleep(1);
|
||||
}
|
||||
|
||||
if (account.pending.size() != 0) {
|
||||
Order_old o = account.pending.get(0);
|
||||
account.se.cancelOrder_old(o);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean doBuy() {
|
||||
|
||||
double money = getRandomAmmount(account.money, myconfig.sell_volume);
|
||||
|
||||
double lp = account.se.getlastprice();
|
||||
double limit;
|
||||
limit = lp + getRandomAmmount(lp, myconfig.buy_limit);
|
||||
|
||||
long volume = (int) (money / (limit * 1));
|
||||
if (volume <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
buy(volume, limit);
|
||||
return waitForOrder(getRandom(myconfig.buy_order_wait));
|
||||
|
||||
}
|
||||
|
||||
public boolean doSell() {
|
||||
|
||||
long volume;
|
||||
volume = (long) Math.round(getRandomAmmount(account.shares, myconfig.sell_volume));
|
||||
|
||||
double lp = account.se.getlastprice();
|
||||
double limit;
|
||||
limit = lp + getRandomAmmount(lp, myconfig.sell_limit);
|
||||
|
||||
sell(volume, limit);
|
||||
return waitForOrder(getRandom(myconfig.sell_order_wait));
|
||||
|
||||
}
|
||||
|
||||
/* private boolean monitorTrades() {
|
||||
|
||||
int numpending = account.pending.size();
|
||||
if (numpending == 0) {
|
||||
// System.out.print("RT: pending = 0 - return false\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
Order_old o = account.pending.get(0);
|
||||
long age = o.getAge();
|
||||
|
||||
// System.out.print("RT: age is: "+age+"\n");
|
||||
if (age > myconfig.maxage) {
|
||||
// System.out.print("MaxAge is"+myconfig.maxage+"\n");
|
||||
account.se.cancelOrder_old(o);
|
||||
// System.out.print("Age reached - canel return false\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
//System.out.print("RT: monitor return true\n");
|
||||
return true;
|
||||
}
|
||||
*/
|
||||
public void trade() {
|
||||
|
||||
float am[] = {-10, 200};
|
||||
|
||||
double x = Math.round(this.getRandomAmmount(1000, am));
|
||||
/* System.out.print(
|
||||
"Random:"
|
||||
+ x
|
||||
+ "\n"
|
||||
);
|
||||
|
||||
*/
|
||||
/*
|
||||
// System.out.print("RT: Now trading\n");
|
||||
if (monitorTrades()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// What next to do?
|
||||
int action = rand.nextInt(5);
|
||||
|
||||
if (account.money < 10 && account.shares < 5) {
|
||||
System.out.print("I'm almost ruined\n");
|
||||
}
|
||||
|
||||
if (action == 1) {
|
||||
doBuy();
|
||||
return;
|
||||
}
|
||||
|
||||
if (action == 2) {
|
||||
doSell();
|
||||
return;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
protected Action getAction() {
|
||||
if (rand.nextInt(2)==0){
|
||||
return Action.buy;
|
||||
}
|
||||
else{
|
||||
return Action.sell;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
System.out.print("Starting Random Trader\n");
|
||||
while (true) {
|
||||
|
||||
// What next to do?
|
||||
Action action = getAction();
|
||||
|
||||
if (account.isRuined()) {
|
||||
// System.out.print("I'm ruined\n");
|
||||
// System.exit(0);
|
||||
}
|
||||
boolean rc;
|
||||
// action=1;
|
||||
switch (action) {
|
||||
|
||||
case sell:
|
||||
if (account.shares <= 0) {
|
||||
// we have no shares
|
||||
continue;
|
||||
}
|
||||
// System.out.print("Sell\n");
|
||||
rc = doSell();
|
||||
if (!rc) {
|
||||
continue;
|
||||
}
|
||||
// System.out.print("Sold\n");
|
||||
doSleep(getRandom(myconfig.wait_after_sell));
|
||||
// System.out.print("Next\n");
|
||||
break;
|
||||
case buy:
|
||||
if (account.money <= 0) {
|
||||
// we have no money
|
||||
continue;
|
||||
}
|
||||
// System.out.print("Sell\n");
|
||||
rc = doBuy();
|
||||
if (!rc) {
|
||||
continue;
|
||||
}
|
||||
// System.out.print("Bought\n");
|
||||
doSleep(getRandom(myconfig.wait_after_buy));
|
||||
// System.out.print("Next\n");
|
||||
break;
|
||||
|
||||
}
|
||||
// doSleep(1);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user