Better charts

This commit is contained in:
7u83 2017-01-23 18:56:09 +01:00
parent 2d4d0cf939
commit 3d5aa227d4
15 changed files with 973 additions and 180 deletions

View File

@ -17,12 +17,27 @@ import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import javax.swing.Scrollable;
import sesim.MinMax;
/**
*
* @author 7u83 <7u83@mail.ru>
*/
public class Chart extends javax.swing.JPanel implements QuoteReceiver {
public class Chart extends javax.swing.JPanel implements QuoteReceiver, Scrollable {
protected int em_size = 1;
protected float bar_width = 0.8f;
protected float bar_width_em = 1;
protected float y_legend_width = 8;
protected int num_bars = 4000;
protected Rectangle clip_bounds = new Rectangle();
protected Dimension dim;
protected int first_bar, last_bar;
/**
* Creates new form Chart
@ -35,29 +50,44 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver {
Globals.se.addQuoteReceiver(this);
//Graphics g = this.getGraphics();
//g.drawString("Hello world", 0, 0);
}
int item_width = 10;
int items = 350;
long ntime = 0;
OHLCData data = new OHLCData(2000);
// int item_width = 10;
//int items = 350;
//long ntime = 0;
OHLCData data = new OHLCData(6000);
OHLCDataItem current = null;
// int min;
// int max;
int getY(float Y) {
return 0;
}
void drawCandle(Graphics2D g, OHLCData d, int x, int y) {
}
@Override
public Dimension getPreferredScrollableViewportSize() {
return this.getPreferredSize();
}
@Override
public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction) {
return 1;
}
@Override
public int getScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction) {
return 100;
}
@Override
public boolean getScrollableTracksViewportWidth() {
return false;
}
@Override
public boolean getScrollableTracksViewportHeight() {
return false;
}
class XLegendDef {
double unit_width = 1;
@ -141,26 +171,53 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver {
Graphics2D g;
float iwidth;
float getY(float y) {
return rect.height - ((y - min) * scaling);
float getYc(float y) {
return getY(y);
//return rect.height - ((y - min) * scaling);
}
}
float getY(float y, float min, float s, Rectangle r) {
boolean logs = true;
return r.height - ((y - min) * s);
float getY(float y) {
if (logs) {
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);
//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 fmin = c_rect.height - ((float) Math.log((y / c_mm.min)) * fac);
System.out.printf("Fac: %f fmin: %f\n", fac, fmin);
return fmin;
//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);
}
private void old_drawItem(Graphics2D g, Rectangle r, int prevx, int x, OHLCDataItem prev, OHLCDataItem item, float s, float min) {
/* private void old_drawItem(Graphics2D g, Rectangle r, int prevx, int x, OHLCDataItem prev, OHLCDataItem item, float s, float min) {
if (prev == null) {
prev = item;
}
g.drawLine(prevx, (int) getY(prev.close, min, s, r), x, (int) getY(item.close, min, s, r));
g.drawLine(prevx, (int) getYc(prev.close, min, s, r), x, (int) getYc(item.close, min, s, r));
g.drawLine(r.x, r.height + r.y, r.x + r.width, r.height + r.y);
}
*/
private void drawItem_l(RenderCtx ctx, int prevx, int x, OHLCDataItem prev, OHLCDataItem item) {
if (prev == null) {
@ -169,7 +226,7 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver {
Graphics2D g = ctx.g;
Rectangle r = ctx.rect;
g.drawLine(prevx, (int) ctx.getY(prev.close), x, (int) ctx.getY(item.close));
g.drawLine(prevx, (int) ctx.getYc(prev.close), x, (int) ctx.getYc(item.close));
g.drawLine(r.x, r.height + r.y, r.x + r.width, r.height + r.y);
}
@ -181,49 +238,101 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver {
Graphics2D g = ctx.g;
Rectangle r = ctx.rect;
// g.drawLine(prevx, (int) ctx.getY(prev.close), x, (int) ctx.getY(item.close));
// g.drawLine(prevx, (int) ctx.getYc(prev.close), x, (int) ctx.getYc(item.close));
// g.drawLine(x,(int)ctx.getY(i.high),x,(int)ctx.getY(i.low));
// g.drawLine(x,(int)ctx.getYc(i.high),x,(int)ctx.getYc(i.low));
if (i.open < i.close) {
int xl = (int) (x + ctx.iwidth / 2);
g.setColor(Color.BLACK);
g.drawLine(x, (int) ctx.getY(i.close), x, (int) ctx.getY(i.high));
g.drawLine(x, (int) ctx.getY(i.low), x, (int) ctx.getY(i.open));
g.drawLine(xl, (int) ctx.getYc(i.close), xl, (int) ctx.getYc(i.high));
g.drawLine(xl, (int) ctx.getYc(i.low), xl, (int) ctx.getYc(i.open));
float w = ctx.iwidth;
float h = (int) (ctx.getY(i.open) - ctx.getY(i.close));
float h = (int) (ctx.getYc(i.open) - ctx.getYc(i.close));
// System.out.printf("CLO: %f %f \n", w, h);
// System.out.printf("CLO: %f %f \n", w, h);
g.setColor(Color.GREEN);
g.fillRect((int) (x - w / 2), (int) ctx.getY(i.close), (int) w, (int) h);
g.fillRect((int) (x), (int) ctx.getYc(i.close), (int) w, (int) h);
g.setColor(Color.BLACK);
g.drawRect((int) (x - w / 2), (int) ctx.getY(i.close), (int) w, (int) h);
g.drawRect((int) (x), (int) ctx.getYc(i.close), (int) w, (int) h);
} else {
int xl = (int) (x + ctx.iwidth / 2);
g.setColor(Color.RED);
g.drawLine(x, (int) ctx.getY(i.high), x, (int) ctx.getY(i.close));
g.drawLine(x, (int) ctx.getY(i.open), x, (int) ctx.getY(i.low));
g.drawLine(xl, (int) ctx.getYc(i.high), xl, (int) ctx.getYc(i.close));
g.drawLine(xl, (int) ctx.getYc(i.open), xl, (int) ctx.getYc(i.low));
float w = ctx.iwidth;
float h = (int) (ctx.getY(i.close) - ctx.getY(i.open));
float h = (int) (ctx.getYc(i.close) - ctx.getYc(i.open));
g.fillRect((int) (x - w / 2), (int) ctx.getY(i.open), (int) w, (int) h);
g.fillRect((int) (x), (int) ctx.getYc(i.open), (int) w, (int) h);
g.setColor(Color.BLACK);
g.drawRect((int) (x - w / 2), (int) ctx.getY(i.open), (int) w, (int) h);
g.drawRect((int) (x), (int) ctx.getYc(i.open), (int) w, (int) h);
}
g.drawLine(r.x, r.height + r.y, r.x + r.width, r.height + r.y);
// g.drawLine(r.x, r.height + r.y, r.x + r.width, r.height + r.y);
}
// float getYc(float y) {
// return c_rect.height - ((y - c_mm.min) * scaling);
// }
float c_yscaling;
private void drawYLegend(Graphics2D g) {
Dimension dim0 = this.getSize();
Rectangle dim = g.getClipBounds();
int yw = (int) (this.y_legend_width * this.em_size);
// 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);
// float yscale = dim.height / c_mm.getDiff();
c_yscaling = c_rect.height / c_mm.getDiff();
// System.out.printf("yscale %f\n", c_yscaling);
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);
g.drawLine(dim.width + dim.x - yw, my, dim.width + dim.x - yw + em_size, my);
g.drawString(String.format("%.2f", y), dim.width + dim.x - yw + em_size * 1.5f, my + c_font_height / 3);
}
// g.setColor(Color.red);
// g.drawLine(0,(int)getYc(c_mm.min), 1000, (int)getYc(c_mm.min));
//g.setColor(Color.green);
//g.drawRect(c_rect.x, c_rect.y, c_rect.width, c_rect.height);
// System.out.printf("Size: %d %d\n",dim.width,dim.height);
// System.exit(0);
}
private MinMax c_mm = null;
private Rectangle c_rect;
private void draw(Graphics2D g) {
if (data == null )
if (data == null) {
return;
if (data.size()==0)
}
if (data.size() == 0) {
return;
}
c_mm = data.getMinMax(first_bar, last_bar);
if (c_mm == null) {
return;
}
c_mm.min /= 1.5; //-= c_mm.min/ 2.0f;
c_mm.max *= 1.2; //+= c_mm.max / 10.0f;
OHLCDataItem di0 = data.get(0);
XLegendDef xld = new XLegendDef();
this.drawXLegend(g, xld);
@ -231,30 +340,46 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver {
int em_height = g.getFontMetrics().getHeight();
int em_width = g.getFontMetrics().stringWidth("M");
this.getSize();
int pwidth = em_width * items;
//this.getSize();
int pwidth = em_width * num_bars;
int phight = 400;
this.setPreferredSize(new Dimension(pwidth, phight));
this.setPreferredSize(new Dimension(pwidth, dim.height));
this.revalidate();
Dimension dim = this.getSize();
Rectangle r = new Rectangle(0, 0, pwidth, dim.height - 6 * em_width);
c_rect = r;
this.drawYLegend(g);
Iterator<OHLCDataItem> it = data.iterator();
// Dimension dim = this.getSize();
// Iterator<OHLCDataItem> it = data.iterator();
OHLCDataItem prev = null;
int myi = 0;
// int myi = 0;
RenderCtx ctx = new RenderCtx();
Rectangle r = new Rectangle(0, 2 * em_width, pwidth, dim.height - 6 *em_width );
ctx.rect = r;
ctx.scaling = (float) r.height / (data.getMax() - data.getMin());
ctx.min = data.getMin();
// MinMax mm = data.getMinMax(first_bar, last_bar);
// if(mm==null)
// return ;
ctx.rect = c_rect;
ctx.scaling = (float) r.height / (c_mm.getMax() - c_mm.getMin());
ctx.min = c_mm.getMin();
ctx.g = g;
ctx.iwidth = em_width - em_width / 5f;
ctx.iwidth = (bar_width * em_size) * 0.9f; // em_width - em_width / 5f;
//g.setClip(clip_bounds.x, clip_bounds.y, (int)(clip_bounds.width-this.y_legend_width*this.em_size), clip_bounds.height);
for (int i = first_bar; i < last_bar && i < data.size(); i++) {
OHLCDataItem di = data.get(i);
int x = (int) (i * em_size * bar_width); //em_width;
this.drawItem(ctx, x - em_width, x, prev, di); //, ctx.scaling, data.getMin());
// myi++;
prev = di;
}
//System.out.printf("Scaling: %f %f %f %f %f\n",diff,(float)r.height,data.getMin(),data.getMax(),yscaling);
while (it.hasNext()) {
/* while (it.hasNext()) {
OHLCDataItem di = it.next();
int x = myi * em_width;
@ -264,32 +389,32 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver {
prev = di;
}
*/
}
protected void initEmSize(Graphics g) {
em_size = g.getFontMetrics().stringWidth("M");
}
private float c_font_height;
@Override
public void paintComponent(Graphics go) {
super.paintComponent(go);
public final void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g = (Graphics2D) go;
this.initEmSize(g);
this.dim = this.getSize(dim);
this.clip_bounds = g.getClipBounds(this.clip_bounds);
g.setColor(Color.GRAY);
// System.out.printf("X:%d %d\n",dim.width,dim.height);
first_bar = (int) (clip_bounds.x / (this.bar_width * this.em_size));
last_bar = 1 + (int) ((clip_bounds.x + clip_bounds.width - (this.y_legend_width * em_size)) / (this.bar_width * this.em_size));
g.setBackground(Color.BLACK);
// g.get
c_font_height = g.getFontMetrics().getHeight();
Rectangle bounds = g.getDeviceConfiguration().getBounds();
// System.out.print(bounds.width + "\n");
//g.fillRect(0, 0, 100, 100);
Dimension d = this.getSize();
//g.drawString("Hello world", 810, 10);
//g.drawLine(0, 0, d.width, d.height);
//this.setPreferredSize(new Dimension(2000,4000));
draw(g);
draw((Graphics2D) g);
}
/**

View File

@ -25,17 +25,397 @@
*/
package chart;
import gui.Globals;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Iterator;
import javax.swing.Scrollable;
import sesim.Exchange;
import sesim.OHLCData;
import sesim.OHLCDataItem;
import sesim.Quote;
/**
*
* @author 7u83 <7u83@mail.ru>
*/
public class FullChart extends javax.swing.JPanel {
public class Chart extends javax.swing.JPanel implements Exchange.QuoteReceiver, Scrollable {
/**
* Creates new form Chart
*/
public Chart() {
initComponentsChart();
if (Globals.se == null) {
return;
}
Globals.se.addQuoteReceiver(this);
//Graphics g = this.getGraphics();
//g.drawString("Hello world", 0, 0);
}
int item_width = 10;
int items = 350;
long ntime = 0;
OHLCData data = new OHLCData(2000);
OHLCDataItem current = null;
// int min;
// int max;
int getY(float Y) {
return 0;
}
void drawCandle(Graphics2D g, OHLCData d, int x, int y) {
}
@Override
public Dimension getPreferredScrollableViewportSize() {
return this.getPreferredSize();
}
@Override
public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction) {
return 100;
}
@Override
public int getScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction) {
return 100;
}
@Override
public boolean getScrollableTracksViewportWidth() {
return false;
}
@Override
public boolean getScrollableTracksViewportHeight() {
return false;
}
class XLegendDef {
double unit_width = 1;
int big_tick = 10;
long start;
XLegendDef() {
}
String getAt(int unit) {
Date date = new Date(sesim.Scheduler.timeStart + unit * 5000);
// DateFormat formatter = new SimpleDateFormat("HH:mm:ss:SSS");
DateFormat formatter = new SimpleDateFormat("HH:mm:ss");
String dateFormatted = formatter.format(date);
return dateFormatted;
}
}
void drawOHLC(Graphics2D g, int x, OHLCDataItem di) {
}
void drawXLegend(Graphics2D g, XLegendDef xld) {
//XLegendDef xld = new XLegendDef();
g = (Graphics2D) g.create();
int xl_height = 30;
Dimension dim = this.getSize();
int em_height = g.getFontMetrics().getHeight();
int em_width = g.getFontMetrics().stringWidth("M");
int y = dim.height - em_height * 3;
g.drawLine(0, y, dim.width, y);
int n;
double x;
for (n = 0, x = 0; x < dim.width; x += em_width * xld.unit_width) {
if (n % xld.big_tick == 0) {
g.drawLine((int) x, y, (int) x, y + em_height);
} else {
g.drawLine((int) x, y, (int) x, y + em_height / 2);
}
if (n % xld.big_tick == 0) {
String text = "Hello";
text = xld.getAt(n);
int swidth = g.getFontMetrics().stringWidth(text);
g.drawString(text, (int) x - swidth / 2, y + em_height * 2);
}
OHLCDataItem d;
try {
d = data.data.get(n);
} catch (Exception e) {
d = null;
}
n++;
}
}
private void getData() {
}
class RenderCtx {
Rectangle rect;
float scaling;
float min;
Graphics2D g;
float iwidth;
float getY(float y) {
return rect.height - ((y - min) * scaling);
}
}
float getY(float y, float min, float s, Rectangle r) {
return r.height - ((y - min) * s);
}
private void old_drawItem(Graphics2D g, Rectangle r, int prevx, int x, OHLCDataItem prev, OHLCDataItem item, float s, float min) {
if (prev == null) {
prev = item;
}
g.drawLine(prevx, (int) getY(prev.close, min, s, r), x, (int) getY(item.close, min, s, r));
g.drawLine(r.x, r.height + r.y, r.x + r.width, r.height + r.y);
}
private void drawItem_l(RenderCtx ctx, int prevx, int x, OHLCDataItem prev, OHLCDataItem item) {
if (prev == null) {
prev = item;
}
Graphics2D g = ctx.g;
Rectangle r = ctx.rect;
g.drawLine(prevx, (int) ctx.getY(prev.close), x, (int) ctx.getY(item.close));
g.drawLine(r.x, r.height + r.y, r.x + r.width, r.height + r.y);
}
private void drawItem(RenderCtx ctx, int prevx, int x, OHLCDataItem prev, OHLCDataItem i) {
if (prev == null) {
prev = i;
}
Graphics2D g = ctx.g;
Rectangle r = ctx.rect;
// g.drawLine(prevx, (int) ctx.getY(prev.close), x, (int) ctx.getY(item.close));
// g.drawLine(x,(int)ctx.getY(i.high),x,(int)ctx.getY(i.low));
if (i.open < i.close) {
g.setColor(Color.BLACK);
g.drawLine(x, (int) ctx.getY(i.close), x, (int) ctx.getY(i.high));
g.drawLine(x, (int) ctx.getY(i.low), x, (int) ctx.getY(i.open));
float w = ctx.iwidth;
float h = (int) (ctx.getY(i.open) - ctx.getY(i.close));
// System.out.printf("CLO: %f %f \n", w, h);
g.setColor(Color.GREEN);
g.fillRect((int) (x - w / 2), (int) ctx.getY(i.close), (int) w, (int) h);
g.setColor(Color.BLACK);
g.drawRect((int) (x - w / 2), (int) ctx.getY(i.close), (int) w, (int) h);
} else {
g.setColor(Color.RED);
g.drawLine(x, (int) ctx.getY(i.high), x, (int) ctx.getY(i.close));
g.drawLine(x, (int) ctx.getY(i.open), x, (int) ctx.getY(i.low));
float w = ctx.iwidth;
float h = (int) (ctx.getY(i.close) - ctx.getY(i.open));
g.fillRect((int) (x - w / 2), (int) ctx.getY(i.open), (int) w, (int) h);
g.setColor(Color.BLACK);
g.drawRect((int) (x - w / 2), (int) ctx.getY(i.open), (int) w, (int) h);
}
g.drawLine(r.x, r.height + r.y, r.x + r.width, r.height + r.y);
}
private void drawYLegend(Graphics2D g) {
// Dimension dim = jScrollPane1.
//Dimension dim = new Dimension();
Rectangle dim = g.getClipBounds();
//dim.height = 300;
System.out.printf("GetX %d %d\n", dim.x,dim.width);
Dimension dim0 = this.getSize();
//Rectangle dim = this.getVisibleRect();
g.drawLine(dim.width+dim.x - 50, 0, dim.x+dim.width - 50, dim.height);
// System.out.printf("Size: %d %d\n",dim.width,dim.height);
// System.exit(0);
}
private void draw(Graphics2D g) {
if (data == null) {
return;
}
if (data.size() == 0) {
return;
}
OHLCDataItem di0 = data.get(0);
XLegendDef xld = new XLegendDef();
this.drawXLegend(g, xld);
this.drawYLegend(g);
int em_height = g.getFontMetrics().getHeight();
int em_width = g.getFontMetrics().stringWidth("M");
this.getSize();
int pwidth = em_width * items;
int phight = 400;
this.setPreferredSize(new Dimension(pwidth, phight));
this.revalidate();
Dimension dim = this.getSize();
Iterator<OHLCDataItem> it = data.iterator();
OHLCDataItem prev = null;
int myi = 0;
RenderCtx ctx = new RenderCtx();
Rectangle r = new Rectangle(0, 2 * em_width, pwidth, dim.height - 6 * em_width);
ctx.rect = r;
ctx.scaling = (float) r.height / (data.getMax() - data.getMin());
ctx.min = data.getMin();
ctx.g = g;
ctx.iwidth = em_width - em_width / 5f;
//System.out.printf("Scaling: %f %f %f %f %f\n",diff,(float)r.height,data.getMin(),data.getMax(),yscaling);
while (it.hasNext()) {
OHLCDataItem di = it.next();
int x = myi * em_width;
this.drawItem(ctx, x - em_width, x, prev, di); //, ctx.scaling, data.getMin());
myi++;
prev = di;
}
}
@Override
public void paintComponent(Graphics go) {
super.paintComponent(go);
Graphics2D g = (Graphics2D) go;
g.setColor(Color.GRAY);
g.setBackground(Color.BLACK);
// g.get
Rectangle bounds = g.getDeviceConfiguration().getBounds();
// System.out.print(bounds.width + "\n");
//g.fillRect(0, 0, 100, 100);
Dimension d = this.getSize();
//g.drawString("Hello world", 810, 10);
//g.drawLine(0, 0, d.width, d.height);
//this.setPreferredSize(new Dimension(2000,4000));
draw(g);
}
/**
* 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">
private void initComponentsChart() {
setBackground(java.awt.Color.white);
setBorder(null);
setOpaque(false);
setPreferredSize(new java.awt.Dimension(300, 300));
setRequestFocusEnabled(false);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 300, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 300, Short.MAX_VALUE)
);
}// </editor-fold>
@Override
public void UpdateQuote(Quote q) {
// System.out.print("Quote Received\n");
// this.realTimeAdd(q.time, (float) q.price, (float)q.volume);
data.realTimeAdd(q.time, (float) q.price, (float) q.volume);
// this.invalidate();
this.repaint();
}
// Variables declaration - do not modify
// End of variables declaration
}
/**
* Creates new form FullChart
*/
public FullChart() {
initComponents();
Chart chart = new Chart();
this.jScrollPane1.setViewportView(chart);
// this.jScrollPane1.setRowHeaderView(chart);
// this.jScrollPane1.setCorner(JScrollPane., chart);
}
/**

View File

@ -0,0 +1,95 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JInternalFrameFormInfo">
<SyntheticProperties>
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
</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" attributes="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="-2" pref="133" max="-2" attributes="0"/>
<Component id="jButton1" min="-2" max="-2" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="-2" pref="41" max="-2" attributes="0"/>
<Component id="jCheckBox1" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Component id="jTabbedPane1" pref="168" 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 min="-2" pref="27" max="-2" attributes="0"/>
<Component id="jButton1" min="-2" max="-2" attributes="0"/>
<EmptySpace type="separate" max="-2" attributes="0"/>
<Component id="jCheckBox1" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="184" max="32767" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<Component id="jTabbedPane1" pref="0" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="javax.swing.JButton" name="jButton1">
<Properties>
<Property name="text" type="java.lang.String" value="jButton1"/>
</Properties>
</Component>
<Component class="javax.swing.JCheckBox" name="jCheckBox1">
<Properties>
<Property name="text" type="java.lang.String" value="jCheckBox1"/>
</Properties>
</Component>
<Container class="javax.swing.JTabbedPane" name="jTabbedPane1">
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JTabbedPaneSupportLayout"/>
<SubComponents>
<Container class="chart.Chart" name="chart1">
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.support.JTabbedPaneSupportLayout" value="org.netbeans.modules.form.compat2.layouts.support.JTabbedPaneSupportLayout$JTabbedPaneConstraintsDescription">
<JTabbedPaneConstraints tabName="tab1">
<Property name="tabTitle" type="java.lang.String" value="tab1"/>
</JTabbedPaneConstraints>
</Constraint>
</Constraints>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="168" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="239" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
</Layout>
</Container>
</SubComponents>
</Container>
</SubComponents>
</Form>

View File

@ -0,0 +1,111 @@
/*
* 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 NewJInternalFrame extends javax.swing.JInternalFrame {
/**
* Creates new form NewJInternalFrame
*/
public NewJInternalFrame() {
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() {
jButton1 = new javax.swing.JButton();
jCheckBox1 = new javax.swing.JCheckBox();
jTabbedPane1 = new javax.swing.JTabbedPane();
chart1 = new chart.Chart();
jButton1.setText("jButton1");
jCheckBox1.setText("jCheckBox1");
javax.swing.GroupLayout chart1Layout = new javax.swing.GroupLayout(chart1);
chart1.setLayout(chart1Layout);
chart1Layout.setHorizontalGroup(
chart1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 168, Short.MAX_VALUE)
);
chart1Layout.setVerticalGroup(
chart1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 239, Short.MAX_VALUE)
);
jTabbedPane1.addTab("tab1", chart1);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(133, 133, 133)
.addComponent(jButton1))
.addGroup(layout.createSequentialGroup()
.addGap(41, 41, 41)
.addComponent(jCheckBox1)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 168, Short.MAX_VALUE)
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(27, 27, 27)
.addComponent(jButton1)
.addGap(18, 18, 18)
.addComponent(jCheckBox1)
.addContainerGap(184, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
.addContainerGap())
);
pack();
}// </editor-fold>//GEN-END:initComponents
// Variables declaration - do not modify//GEN-BEGIN:variables
private chart.Chart chart1;
private javax.swing.JButton jButton1;
private javax.swing.JCheckBox jCheckBox1;
private javax.swing.JTabbedPane jTabbedPane1;
// End of variables declaration//GEN-END:variables
}

View File

@ -18,7 +18,7 @@
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="jToolBar2" pref="516" max="32767" attributes="0"/>
<Component id="jTabbedPane1" pref="516" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
@ -27,52 +27,39 @@
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="jToolBar2" pref="437" max="32767" attributes="0"/>
<Component id="jTabbedPane1" pref="437" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Container class="javax.swing.JToolBar" name="jToolBar2">
<Properties>
<Property name="rollover" type="boolean" value="true"/>
</Properties>
<Container class="javax.swing.JTabbedPane" name="jTabbedPane1">
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignBoxLayout"/>
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JTabbedPaneSupportLayout"/>
<SubComponents>
<Component class="javax.swing.JButton" name="jButton3">
<Properties>
<Property name="text" type="java.lang.String" value="jButton3"/>
<Property name="focusable" type="boolean" value="false"/>
<Property name="horizontalTextPosition" type="int" value="0"/>
<Property name="verticalTextPosition" type="int" value="3"/>
</Properties>
</Component>
<Component class="javax.swing.JButton" name="jButton4">
<Properties>
<Property name="text" type="java.lang.String" value="jButton4"/>
<Property name="focusable" type="boolean" value="false"/>
<Property name="horizontalTextPosition" type="int" value="0"/>
<Property name="verticalTextPosition" type="int" value="3"/>
</Properties>
</Component>
<Component class="javax.swing.JButton" name="jButton5">
<Properties>
<Property name="text" type="java.lang.String" value="jButton5"/>
<Property name="focusable" type="boolean" value="false"/>
<Property name="horizontalTextPosition" type="int" value="0"/>
<Property name="verticalTextPosition" type="int" value="3"/>
</Properties>
</Component>
<Component class="javax.swing.JButton" name="jButton6">
<Properties>
<Property name="text" type="java.lang.String" value="jButton6"/>
<Property name="focusable" type="boolean" value="false"/>
<Property name="horizontalTextPosition" type="int" value="0"/>
<Property name="verticalTextPosition" type="int" value="3"/>
</Properties>
</Component>
<Container class="chart.Chart" name="chart1">
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.support.JTabbedPaneSupportLayout" value="org.netbeans.modules.form.compat2.layouts.support.JTabbedPaneSupportLayout$JTabbedPaneConstraintsDescription">
<JTabbedPaneConstraints tabName="tab1">
<Property name="tabTitle" type="java.lang.String" value="tab1"/>
</JTabbedPaneConstraints>
</Constraint>
</Constraints>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="516" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="408" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
</Layout>
</Container>
</SubComponents>
</Container>
</SubComponents>

View File

@ -47,37 +47,21 @@ public class NewJPanel extends javax.swing.JPanel {
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jToolBar2 = new javax.swing.JToolBar();
jButton3 = new javax.swing.JButton();
jButton4 = new javax.swing.JButton();
jButton5 = new javax.swing.JButton();
jButton6 = new javax.swing.JButton();
jTabbedPane1 = new javax.swing.JTabbedPane();
chart1 = new chart.Chart();
jToolBar2.setRollover(true);
javax.swing.GroupLayout chart1Layout = new javax.swing.GroupLayout(chart1);
chart1.setLayout(chart1Layout);
chart1Layout.setHorizontalGroup(
chart1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 516, Short.MAX_VALUE)
);
chart1Layout.setVerticalGroup(
chart1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 408, Short.MAX_VALUE)
);
jButton3.setText("jButton3");
jButton3.setFocusable(false);
jButton3.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
jButton3.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
jToolBar2.add(jButton3);
jButton4.setText("jButton4");
jButton4.setFocusable(false);
jButton4.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
jButton4.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
jToolBar2.add(jButton4);
jButton5.setText("jButton5");
jButton5.setFocusable(false);
jButton5.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
jButton5.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
jToolBar2.add(jButton5);
jButton6.setText("jButton6");
jButton6.setFocusable(false);
jButton6.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
jButton6.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
jToolBar2.add(jButton6);
jTabbedPane1.addTab("tab1", chart1);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
@ -85,24 +69,21 @@ public class NewJPanel extends javax.swing.JPanel {
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jToolBar2, javax.swing.GroupLayout.DEFAULT_SIZE, 516, Short.MAX_VALUE)
.addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 516, Short.MAX_VALUE)
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jToolBar2, javax.swing.GroupLayout.DEFAULT_SIZE, 437, Short.MAX_VALUE)
.addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 437, Short.MAX_VALUE)
.addContainerGap())
);
}// </editor-fold>//GEN-END:initComponents
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton jButton3;
private javax.swing.JButton jButton4;
private javax.swing.JButton jButton5;
private javax.swing.JButton jButton6;
private javax.swing.JToolBar jToolBar2;
private chart.Chart chart1;
private javax.swing.JTabbedPane jTabbedPane1;
// End of variables declaration//GEN-END:variables
}

View File

@ -0,0 +1,35 @@
/*
* 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 OHLCChart extends Chart{
}

View File

@ -160,12 +160,12 @@
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jToolBar1" alignment="0" pref="913" max="32767" attributes="0"/>
<Group type="102" alignment="0" attributes="0">
<Component id="jToolBar1" max="32767" attributes="0"/>
<Group type="102" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="orderBookPanel1" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="jScrollPane1" max="32767" attributes="0"/>
<Component id="jScrollPane1" pref="729" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
@ -224,16 +224,18 @@
</Component>
</SubComponents>
</Container>
<Component class="gui.OrderBookPanel" name="orderBookPanel1">
</Component>
<Container class="javax.swing.JScrollPane" name="jScrollPane1">
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
<SubComponents>
<Container class="chart.Chart" name="chart2">
<Container class="chart.Chart" name="chart1">
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="669" max="32767" attributes="0"/>
<EmptySpace min="0" pref="723" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
@ -245,7 +247,5 @@
</Container>
</SubComponents>
</Container>
<Component class="gui.OrderBookPanel" name="orderBookPanel1">
</Component>
</SubComponents>
</Form>

View File

@ -49,7 +49,7 @@ public class NewMDIApplication extends javax.swing.JFrame {
public void startTraders() {
AutoTraderConfig cfg1 = new RandomTraderConfig();
AutoTrader rt1 = cfg1.createTrader(Globals.se, 1000000, 1000000);
AutoTrader rt1 = cfg1.createTrader(Globals.se, 100000, 100000);
Globals.se.traders.add(rt1);
rt1.setName("Alice");
rt1.start();
@ -57,7 +57,7 @@ public class NewMDIApplication extends javax.swing.JFrame {
AutoTraderConfig cfg2 = new RandomTraderConfig();
for (int i = 0; i < 30; i++) {
AutoTrader randt = cfg2.createTrader(Globals.se, 100000, 100000);
AutoTrader randt = cfg2.createTrader(Globals.se, 1000, 1000);
Globals.se.traders.add(randt);
randt.setName("Bob");
@ -78,9 +78,9 @@ public class NewMDIApplication extends javax.swing.JFrame {
jToolBar1 = new javax.swing.JToolBar();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
chart2 = new chart.Chart();
orderBookPanel1 = new gui.OrderBookPanel();
jScrollPane1 = new javax.swing.JScrollPane();
chart1 = new chart.Chart();
menuBar = new javax.swing.JMenuBar();
fileMenu = new javax.swing.JMenu();
openMenuItem = new javax.swing.JMenuItem();
@ -132,18 +132,18 @@ public class NewMDIApplication extends javax.swing.JFrame {
});
jToolBar1.add(jButton2);
javax.swing.GroupLayout chart2Layout = new javax.swing.GroupLayout(chart2);
chart2.setLayout(chart2Layout);
chart2Layout.setHorizontalGroup(
chart2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 669, Short.MAX_VALUE)
javax.swing.GroupLayout chart1Layout = new javax.swing.GroupLayout(chart1);
chart1.setLayout(chart1Layout);
chart1Layout.setHorizontalGroup(
chart1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 723, Short.MAX_VALUE)
);
chart2Layout.setVerticalGroup(
chart2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
chart1Layout.setVerticalGroup(
chart1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 460, Short.MAX_VALUE)
);
jScrollPane1.setViewportView(chart2);
jScrollPane1.setViewportView(chart1);
fileMenu.setMnemonic('f');
fileMenu.setText("File");
@ -247,12 +247,12 @@ public class NewMDIApplication extends javax.swing.JFrame {
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, 913, Short.MAX_VALUE)
.addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(orderBookPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane1)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 729, Short.MAX_VALUE)
.addContainerGap())
);
layout.setVerticalGroup(
@ -294,7 +294,7 @@ public class NewMDIApplication extends javax.swing.JFrame {
}//GEN-LAST:event_jMenuItem1ActionPerformed
private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
TraderListDialog d = new TraderListDialog(this,false);
TraderListDialog d = new TraderListDialog(this, false);
d.setVisible(rootPaneCheckingEnabled);
}//GEN-LAST:event_jMenuItem2ActionPerformed
@ -318,7 +318,7 @@ public class NewMDIApplication extends javax.swing.JFrame {
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JMenuItem aboutMenuItem;
private chart.Chart chart2;
private chart.Chart chart1;
private javax.swing.JMenuItem contentMenuItem;
private javax.swing.JMenuItem copyMenuItem;
private javax.swing.JMenuItem cutMenuItem;

View File

@ -0,0 +1,53 @@
/*
* 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 sesim;
/**
*
* @author 7u83 <7u83@mail.ru>
*/
public class MinMax {
public float min;
public float max;
MinMax(float min, float max) {
this.min = min;
this.max = max;
}
public float getDiff() {
return max - min;
}
public float getMin() {
return min;
}
public float getMax() {
return max;
}
}

View File

@ -69,7 +69,25 @@ public class OHLCData { //extends ArrayList <OHLCDataItem> {
return this.frame_size;
}
public MinMax getMinMax(int first, int last){
if (first>=data.size())
return null;
OHLCDataItem di = data.get(first);
MinMax minmax=new MinMax(di.low,di.high);
for (int i=first+1; i<last && i<data.size(); i++){
di = data.get(i);
if (di.low<minmax.min){
minmax.min=di.low;
}
if (di.high>minmax.max){
minmax.max=di.high;
}
}
return minmax;
}
long getFrameStart(long time) {

View File

@ -161,11 +161,8 @@ public class Scheduler extends Thread {
synchronized (this) {
try {
if (pause){
wtime=-1;
}
if (wtime != -1) {
if (wtime != -1 && !pause) {
wait(wtime);
} else {
wait();

View File

@ -167,12 +167,18 @@ public class RandomTrader extends AutoTrader {
double limit;
limit = lp + getRandomAmmount(lp, myconfig.buy_limit);
long volume = (long) (money / (limit * 1));
if (volume <= 0) {
return 0;
}
// double volume = (money / (limit * 1));
if (volume <= 0) {
return 0;
}
se.createOrder(account_id, type, volume, limit);
return getRandom(myconfig.buy_order_wait);
@ -186,7 +192,7 @@ public class RandomTrader extends AutoTrader {
OrderType type = OrderType.ASK;
// how much money we ant to envest?
double volume = (long) getRandomAmmount(ad.shares, myconfig.sell_volume);
double volume = (long)getRandomAmmount(ad.shares, myconfig.sell_volume);
// double lp = 100.0; //se.getBestLimit(type);
Quote q = se.getCurrentPrice();

View File

@ -36,13 +36,13 @@ import sesim.Exchange;
public class RandomTraderConfig extends AutoTraderConfig {
public float[] sell_volume = {100, 100};
public float[] sell_limit = {-1.5f, 1.5f};
public int[] sell_order_wait = {1000, 5000};
public float[] sell_limit = {-1f, 1.0101f};
public int[] sell_order_wait = {1000, 50000};
public int[] wait_after_sell = {10, 30};
public float[] buy_volume = {100, 100};
public float[] buy_limit = {-1.0f, 1.5f};
public int[] buy_order_wait = {1000, 5000};
public float[] buy_limit = {-1f, 1.0101f};
public int[] buy_order_wait = {1000, 50000};
public int[] wait_after_buy = {10, 30};
@Override

View File

@ -62,6 +62,11 @@ public class Test {
* @param args the command line arguments
*/
public static void main(String[] args) throws InterruptedException {
System.out.printf("FFF %f\n",Math.log(1));
System.exit(0);
OHLCData od = new OHLCData(1000);