Now woth candle sticks
This commit is contained in:
parent
ba557179c7
commit
a5ebd72c76
@ -5,6 +5,8 @@
|
|||||||
*/
|
*/
|
||||||
package chart;
|
package chart;
|
||||||
|
|
||||||
|
import sesim.OHLCDataItem;
|
||||||
|
import sesim.OHLCData;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import sesim.Exchange.*;
|
import sesim.Exchange.*;
|
||||||
import sesim.Quote;
|
import sesim.Quote;
|
||||||
@ -41,13 +43,12 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver {
|
|||||||
int items = 350;
|
int items = 350;
|
||||||
long ntime = 0;
|
long ntime = 0;
|
||||||
|
|
||||||
OHLCData data = new OHLCData();
|
OHLCData data = new OHLCData(2000);
|
||||||
|
|
||||||
OHLCDataItem current = null;
|
OHLCDataItem current = null;
|
||||||
|
|
||||||
int min;
|
// int min;
|
||||||
int max;
|
// int max;
|
||||||
|
|
||||||
int getY(float Y) {
|
int getY(float Y) {
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -62,25 +63,28 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver {
|
|||||||
double unit_width = 1;
|
double unit_width = 1;
|
||||||
int big_tick = 10;
|
int big_tick = 10;
|
||||||
long start;
|
long start;
|
||||||
|
|
||||||
|
XLegendDef() {
|
||||||
XLegendDef(){
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String getAt(int unit){
|
String getAt(int unit) {
|
||||||
Date date = new Date(start);
|
Date date = new Date(sesim.Scheduler.timeStart + unit * 5000);
|
||||||
DateFormat formatter = new SimpleDateFormat("HH:mm:ss:SSS");
|
// DateFormat formatter = new SimpleDateFormat("HH:mm:ss:SSS");
|
||||||
|
DateFormat formatter = new SimpleDateFormat("HH:mm:ss");
|
||||||
String dateFormatted = formatter.format(date);
|
String dateFormatted = formatter.format(date);
|
||||||
return dateFormatted;
|
return dateFormatted;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawXLegend(Graphics2D g,XLegendDef xld) {
|
void drawOHLC(Graphics2D g, int x, OHLCDataItem di) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void drawXLegend(Graphics2D g, XLegendDef xld) {
|
||||||
|
|
||||||
//XLegendDef xld = new XLegendDef();
|
//XLegendDef xld = new XLegendDef();
|
||||||
|
|
||||||
g = (Graphics2D) g.create();
|
g = (Graphics2D) g.create();
|
||||||
|
|
||||||
int xl_height = 30;
|
int xl_height = 30;
|
||||||
@ -93,122 +97,176 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver {
|
|||||||
|
|
||||||
g.drawLine(0, y, dim.width, y);
|
g.drawLine(0, y, dim.width, y);
|
||||||
|
|
||||||
int n = 0;
|
int n;
|
||||||
for (double x = 0; x < dim.width; x += em_width * xld.unit_width) {
|
double x;
|
||||||
|
|
||||||
|
for (n = 0, x = 0; x < dim.width; x += em_width * xld.unit_width) {
|
||||||
|
|
||||||
if (n % xld.big_tick == 0) {
|
if (n % xld.big_tick == 0) {
|
||||||
g.drawLine((int) x, y, (int) x, y + em_height);
|
g.drawLine((int) x, y, (int) x, y + em_height);
|
||||||
} else {
|
} else {
|
||||||
g.drawLine((int) x, y, (int) x, y + em_height / 2);
|
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);
|
|
||||||
|
|
||||||
|
|
||||||
|
if (n % xld.big_tick == 0) {
|
||||||
g.drawString(text, (int)x - swidth / 2, y + em_height * 2);
|
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;
|
OHLCDataItem d;
|
||||||
try {
|
try {
|
||||||
d = data.data.get(n);
|
d = data.data.get(n);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
d = null;
|
d = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
n++;
|
n++;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
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 = "A";
|
|
||||||
} else {
|
|
||||||
text = "x";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int swidth = g.getFontMetrics().stringWidth(text);
|
|
||||||
|
|
||||||
g.drawString(text, x - swidth / 2, y + em_height * 2);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
//for(int x=0; x)
|
|
||||||
}
|
|
||||||
|
|
||||||
private void realTimeAdd(long time, float price, float volume) {
|
|
||||||
|
|
||||||
/*System.out.print("Diff:"
|
|
||||||
+(ntime-time)
|
|
||||||
+"\n"
|
|
||||||
);*/
|
|
||||||
if (time > ntime) {
|
|
||||||
|
|
||||||
// System.out.print("new raster ----------------------------------\n");
|
|
||||||
current = null;
|
|
||||||
// ntime = rasterTime(time) + 5000;
|
|
||||||
// System.out.print(ntime+"\n");
|
|
||||||
// System.out.print((time)+"\n");
|
|
||||||
// System.exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (current == null) {
|
|
||||||
current = new OHLCDataItem(price, price, price, price, volume);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean rc = current.update(price, volume);
|
|
||||||
|
|
||||||
if (rc) {
|
|
||||||
System.out.print("Updated -"
|
|
||||||
+ " High:"
|
|
||||||
+ current.high
|
|
||||||
+ " Low:"
|
|
||||||
+ current.low
|
|
||||||
+ " Volume"
|
|
||||||
+ current.volume
|
|
||||||
+ "("
|
|
||||||
+ time
|
|
||||||
+ ")"
|
|
||||||
+ "\n"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getData() {
|
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 draw(Graphics2D g) {
|
private void draw(Graphics2D g) {
|
||||||
|
|
||||||
|
OHLCDataItem di0 = data.get(0);
|
||||||
|
XLegendDef xld = new XLegendDef();
|
||||||
|
this.drawXLegend(g, xld);
|
||||||
|
|
||||||
|
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));
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void draw_old(Graphics2D g) {
|
||||||
|
|
||||||
OHLCDataItem di0 = data.data.get(0);
|
OHLCDataItem di0 = data.data.get(0);
|
||||||
XLegendDef xld= new XLegendDef();
|
XLegendDef xld = new XLegendDef();
|
||||||
//xld.start=di.
|
this.drawXLegend(g, xld);
|
||||||
this.drawXLegend(g,xld);
|
|
||||||
|
|
||||||
this.getSize();
|
this.getSize();
|
||||||
|
|
||||||
@ -222,21 +280,8 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver {
|
|||||||
|
|
||||||
g.setColor(Color.RED);
|
g.setColor(Color.RED);
|
||||||
|
|
||||||
// g.drawLine(0, 0, 100, 100);
|
|
||||||
|
|
||||||
/* for (int i = 0; i < items; i++) {
|
|
||||||
int x = i * this.item_width;
|
|
||||||
g.drawLine(x, 0, x, 50);
|
|
||||||
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
// if (this.current == null) {
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
ArrayList<OHLCDataItem> od = data.data;
|
ArrayList<OHLCDataItem> od = data.data;
|
||||||
|
|
||||||
|
|
||||||
// System.out.print("OD S: " + od.size() + "\n");
|
|
||||||
g.setColor(Color.BLUE);
|
g.setColor(Color.BLUE);
|
||||||
g.setStroke(new BasicStroke(3));
|
g.setStroke(new BasicStroke(3));
|
||||||
|
|
||||||
@ -250,8 +295,8 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver {
|
|||||||
OHLCDataItem di = it.next();
|
OHLCDataItem di = it.next();
|
||||||
|
|
||||||
float y = di.close;
|
float y = di.close;
|
||||||
float max = data.max;
|
float max = data.getMax();
|
||||||
float min = data.min;
|
float min = data.getMin();
|
||||||
|
|
||||||
max = max / 10.0f + max;
|
max = max / 10.0f + max;
|
||||||
min = min - min / 10.0f;
|
min = min - min / 10.0f;
|
||||||
@ -262,14 +307,7 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// max = 5;
|
|
||||||
// min = 0;
|
|
||||||
// System.out.print("Fval: " + y + " " + min + "\n");
|
|
||||||
y -= min;
|
y -= min;
|
||||||
// System.out.print("VAL New" + y + "\n");
|
|
||||||
|
|
||||||
//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;
|
int x = myi * this.item_width;
|
||||||
@ -280,10 +318,8 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver {
|
|||||||
lastx = x;
|
lastx = x;
|
||||||
lasty = (int) y;
|
lasty = (int) y;
|
||||||
|
|
||||||
// System.out.print("Draw Line: " + x + " " + y + "\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// g.drawLine(0, 0, 100, (int) ((this.current.close-80.0)*80.0));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -240,7 +240,7 @@ public class MainWin extends javax.swing.JFrame {
|
|||||||
// SwitchingTraderConfig cfg = new SwitchingTraderConfig();
|
// SwitchingTraderConfig cfg = new SwitchingTraderConfig();
|
||||||
RandomTraderConfig cfg= new RandomTraderConfig();
|
RandomTraderConfig cfg= new RandomTraderConfig();
|
||||||
|
|
||||||
for (int i=0; i<100; i++){
|
for (int i=0; i<30; i++){
|
||||||
AutoTrader randt = cfg.createTrader(se, 100000, 100000);
|
AutoTrader randt = cfg.createTrader(se, 100000, 100000);
|
||||||
|
|
||||||
se.traders.add(randt);
|
se.traders.add(randt);
|
||||||
|
@ -183,6 +183,8 @@ public class Exchange { //extends Thread {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*public interface TimerEvent {
|
/*public interface TimerEvent {
|
||||||
|
|
||||||
long timerEvent();
|
long timerEvent();
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
* POSSIBILITY OF SUCH DAMAGE.
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
package chart;
|
package sesim;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@ -33,29 +33,56 @@ import java.util.*;
|
|||||||
*/
|
*/
|
||||||
public class OHLCData { //extends ArrayList <OHLCDataItem> {
|
public class OHLCData { //extends ArrayList <OHLCDataItem> {
|
||||||
|
|
||||||
float max=0;
|
private float max=0;
|
||||||
float min=0;
|
private float min=0;
|
||||||
|
|
||||||
int ras=20000/10;
|
private int frame_size=60000;
|
||||||
|
int max_size=100;
|
||||||
|
|
||||||
|
|
||||||
|
public OHLCData(){
|
||||||
|
|
||||||
long time_start;
|
}
|
||||||
long time_step;
|
|
||||||
|
public OHLCData(int frame_size){
|
||||||
|
|
||||||
|
this.frame_size=frame_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
// long time_start;
|
||||||
|
// long time_step;
|
||||||
|
|
||||||
public float getMax() {
|
public float getMax() {
|
||||||
return max;
|
return max;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public float getMin(){
|
||||||
|
return min;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int size(){
|
||||||
|
return data.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public int getFrameSize(){
|
||||||
|
return this.frame_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
long rasterTime(long time) {
|
long getFrameStart(long time) {
|
||||||
|
|
||||||
long rt = time / ras;
|
long rt = time / frame_size;
|
||||||
return rt * ras;
|
return rt * frame_size;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrayList<OHLCDataItem> data = new ArrayList<>();
|
public ArrayList<OHLCDataItem> data = new ArrayList<>();
|
||||||
|
|
||||||
|
public OHLCDataItem get(int n){
|
||||||
|
return data.get(n);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private void updateMinMax(float price){
|
private void updateMinMax(float price){
|
||||||
@ -68,27 +95,42 @@ public class OHLCData { //extends ArrayList <OHLCDataItem> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Iterator <OHLCDataItem> iterator(){
|
||||||
|
return data.iterator();
|
||||||
|
}
|
||||||
|
|
||||||
private long ntime = 0;
|
// Start and end of current frame
|
||||||
|
private long current_frame_end = 0;
|
||||||
|
private long current_frame_start =0;
|
||||||
|
|
||||||
boolean realTimeAdd(long time, float price, float volume) {
|
public boolean realTimeAdd(long time, float price, float volume) {
|
||||||
|
|
||||||
|
|
||||||
if (time > ntime) {
|
if (time >= current_frame_end) {
|
||||||
if (ntime==0){
|
if (current_frame_end==0){
|
||||||
System.out.print ("Setting ntimt was zero\n");
|
|
||||||
this.min=price;
|
this.min=price;
|
||||||
this.max=price;
|
this.max=price;
|
||||||
}
|
}
|
||||||
|
|
||||||
ntime = rasterTime(time) + ras;
|
long last_frame_start=current_frame_start;
|
||||||
data.add(new OHLCDataItem(price, price, price, price, volume));
|
current_frame_start = getFrameStart(time);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
current_frame_end = current_frame_start + frame_size;
|
||||||
|
|
||||||
|
System.out.printf("TA %d TE %d\n",this.current_frame_start,this.current_frame_end);
|
||||||
|
|
||||||
|
data.add(new OHLCDataItem(this.current_frame_start, price, volume));
|
||||||
this.updateMinMax(price);
|
this.updateMinMax(price);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
OHLCDataItem d = data.get(data.size() - 1);
|
|
||||||
this.updateMinMax(price);
|
this.updateMinMax(price);
|
||||||
|
|
||||||
|
OHLCDataItem d = data.get(data.size() - 1);
|
||||||
boolean rc = d.update(price, volume);
|
boolean rc = d.update(price, volume);
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
@ -23,7 +23,7 @@
|
|||||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
* POSSIBILITY OF SUCH DAMAGE.
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
package chart;
|
package sesim;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -36,17 +36,13 @@ public class OHLCDataItem {
|
|||||||
public float low;
|
public float low;
|
||||||
public float close;
|
public float close;
|
||||||
public float volume;
|
public float volume;
|
||||||
|
public long time;
|
||||||
public OHLCDataItem(float open, float high, float low, float close, float volume) {
|
|
||||||
this.open = open;
|
|
||||||
this.high = high;
|
public OHLCDataItem(long time,float price, float volume){
|
||||||
this.low = low;
|
this.time=time;
|
||||||
this.close = close;
|
open=low=high=close=price;
|
||||||
this.volume = volume;
|
this.volume=volume;
|
||||||
}
|
|
||||||
|
|
||||||
public OHLCDataItem() {
|
|
||||||
this(0, 0, 0, 0, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean update(float price, float volume) {
|
public boolean update(float price, float volume) {
|
@ -36,3 +36,4 @@ public class OrderData {
|
|||||||
public double executed;
|
public double executed;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,10 +69,18 @@ public class Scheduler extends Thread {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public long currentTimeMillis() {
|
/**
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static long currentTimeMillis() {
|
||||||
return System.currentTimeMillis();
|
return System.currentTimeMillis();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static long timeStart=Scheduler.currentTimeMillis();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -80,7 +88,7 @@ public class Scheduler extends Thread {
|
|||||||
* @param time
|
* @param time
|
||||||
*/
|
*/
|
||||||
public void startTimerEvent(TimerTask e, long time) {
|
public void startTimerEvent(TimerTask e, long time) {
|
||||||
long evtime = time + this.currentTimeMillis();
|
long evtime = time + currentTimeMillis();
|
||||||
synchronized (event_queue) {
|
synchronized (event_queue) {
|
||||||
this.addEvent(e, time);
|
this.addEvent(e, time);
|
||||||
}
|
}
|
||||||
@ -95,7 +103,7 @@ public class Scheduler extends Thread {
|
|||||||
|
|
||||||
private boolean addEvent(TimerTask e, long time) {
|
private boolean addEvent(TimerTask e, long time) {
|
||||||
|
|
||||||
long evtime = time + this.currentTimeMillis();
|
long evtime = time + currentTimeMillis();
|
||||||
|
|
||||||
SortedSet<TimerTask> s = event_queue.get(evtime);
|
SortedSet<TimerTask> s = event_queue.get(evtime);
|
||||||
if (s == null) {
|
if (s == null) {
|
||||||
@ -112,7 +120,7 @@ public class Scheduler extends Thread {
|
|||||||
}
|
}
|
||||||
|
|
||||||
long t = event_queue.firstKey();
|
long t = event_queue.firstKey();
|
||||||
if (t <= this.currentTimeMillis()) {
|
if (t <= currentTimeMillis()) {
|
||||||
SortedSet s = event_queue.get(t);
|
SortedSet s = event_queue.get(t);
|
||||||
event_queue.remove(t);
|
event_queue.remove(t);
|
||||||
Iterator<TimerTask> it = s.iterator();
|
Iterator<TimerTask> it = s.iterator();
|
||||||
@ -124,7 +132,7 @@ public class Scheduler extends Thread {
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
return t - this.currentTimeMillis();
|
return t - currentTimeMillis();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ public class RandomTrader extends AutoTrader {
|
|||||||
|
|
||||||
sesim.Exchange.Account a = se.getAccount(account_id);
|
sesim.Exchange.Account a = se.getAccount(account_id);
|
||||||
long rc = this.doTrade();
|
long rc = this.doTrade();
|
||||||
return rc / 600;
|
return rc ;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,7 +66,7 @@ public class RandomTrader extends AutoTrader {
|
|||||||
public long timerTask() {
|
public long timerTask() {
|
||||||
sesim.Exchange.Account a = se.getAccount(account_id);
|
sesim.Exchange.Account a = se.getAccount(account_id);
|
||||||
long rc = this.doTrade();
|
long rc = this.doTrade();
|
||||||
return rc / 28;
|
return rc / 80;
|
||||||
|
|
||||||
// return this.event();
|
// return this.event();
|
||||||
}
|
}
|
||||||
|
@ -36,13 +36,13 @@ import sesim.Exchange;
|
|||||||
public class RandomTraderConfig extends AutoTraderConfig {
|
public class RandomTraderConfig extends AutoTraderConfig {
|
||||||
|
|
||||||
public float[] sell_volume = {100, 100};
|
public float[] sell_volume = {100, 100};
|
||||||
public float[] sell_limit = {-3, 3};
|
public float[] sell_limit = {-1.5f, 1.5f};
|
||||||
public int[] sell_order_wait = {500, 1500};
|
public int[] sell_order_wait = {1000, 5000};
|
||||||
public int[] wait_after_sell = {10, 30};
|
public int[] wait_after_sell = {10, 30};
|
||||||
|
|
||||||
public float[] buy_volume = {100, 100};
|
public float[] buy_volume = {100, 100};
|
||||||
public float[] buy_limit = {-1, 3};
|
public float[] buy_limit = {-1.0f, 1.5f};
|
||||||
public int[] buy_order_wait = {500, 1500};
|
public int[] buy_order_wait = {1000, 5000};
|
||||||
public int[] wait_after_buy = {10, 30};
|
public int[] wait_after_buy = {10, 30};
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -28,27 +28,23 @@ package sesim;
|
|||||||
import java.util.SortedMap;
|
import java.util.SortedMap;
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author tobias
|
* @author tobias
|
||||||
*/
|
*/
|
||||||
public class Test {
|
public class Test {
|
||||||
|
|
||||||
static void tube(){
|
static void tube() {
|
||||||
try{
|
try {
|
||||||
System.out.printf("Hello %s\n", "args");
|
System.out.printf("Hello %s\n", "args");
|
||||||
if (0==0)
|
if (0 == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
finally {
|
} finally {
|
||||||
System.out.printf("Always %s\n", "the end");
|
System.out.printf("Always %s\n", "the end");
|
||||||
}
|
}
|
||||||
System.out.print("haha\n");
|
System.out.print("haha\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void print_account(AccountData ad) {
|
static void print_account(AccountData ad) {
|
||||||
System.out.print(
|
System.out.print(
|
||||||
@ -66,56 +62,66 @@ public class Test {
|
|||||||
* @param args the command line arguments
|
* @param args the command line arguments
|
||||||
*/
|
*/
|
||||||
public static void main(String[] args) throws InterruptedException {
|
public static void main(String[] args) throws InterruptedException {
|
||||||
|
|
||||||
|
OHLCData od = new OHLCData(1000);
|
||||||
|
|
||||||
|
od.realTimeAdd(12, 100, 10);
|
||||||
|
|
||||||
|
od.realTimeAdd(5000, 100, 10);
|
||||||
|
//od.realTimeAdd(12, 100, 10);
|
||||||
|
|
||||||
|
System.out.printf("Size: %d\n", od.size());
|
||||||
|
|
||||||
|
OHLCDataItem di;
|
||||||
|
|
||||||
|
di = od.get(2);
|
||||||
|
|
||||||
|
System.exit(0);
|
||||||
|
|
||||||
Scheduler s = new Scheduler();
|
Scheduler s = new Scheduler();
|
||||||
s.start();
|
s.start();
|
||||||
|
|
||||||
class Ev implements Scheduler.TimerTask{
|
|
||||||
|
|
||||||
@Override
|
class Ev implements Scheduler.TimerTask {
|
||||||
public long timerTask() {
|
|
||||||
System.out.printf("Timer Event Occured %s\n",name);
|
@Override
|
||||||
if ("Ev1".equals(this.name))
|
public long timerTask() {
|
||||||
|
System.out.printf("Timer Event Occured %s\n", name);
|
||||||
|
if ("Ev1".equals(this.name)) {
|
||||||
return 2000;
|
return 2000;
|
||||||
else
|
} else {
|
||||||
return 4000;
|
return 4000;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
String name;
|
|
||||||
Ev(String name){
|
String name;
|
||||||
this.name=name;
|
|
||||||
}
|
Ev(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ev e1 = new Ev("Ev1");
|
Ev e1 = new Ev("Ev1");
|
||||||
Ev e2 = new Ev("Eb2");
|
Ev e2 = new Ev("Eb2");
|
||||||
|
|
||||||
|
|
||||||
s.startTimerEvent(e1, 0);
|
|
||||||
s.startTimerEvent(e2, 0);
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Thread.sleep(90000);
|
|
||||||
}
|
|
||||||
catch(Exception e) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
s.halt();
|
|
||||||
while (s.isAlive()){
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
System.out.print("All isstopped\n");
|
|
||||||
|
|
||||||
// s.startTimerEvent(e2, 100);
|
s.startTimerEvent(e1, 0);
|
||||||
|
s.startTimerEvent(e2, 0);
|
||||||
|
|
||||||
|
try {
|
||||||
|
Thread.sleep(90000);
|
||||||
/* long starttime=System.currentTimeMillis();
|
} catch (Exception e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
s.halt();
|
||||||
|
while (s.isAlive()) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.print("All isstopped\n");
|
||||||
|
|
||||||
|
// s.startTimerEvent(e2, 100);
|
||||||
|
/* long starttime=System.currentTimeMillis();
|
||||||
while (s.isAlive()){
|
while (s.isAlive()){
|
||||||
if (System.currentTimeMillis()>starttime+6650){
|
if (System.currentTimeMillis()>starttime+6650){
|
||||||
s.stop();
|
s.stop();
|
||||||
@ -128,9 +134,7 @@ public class Test {
|
|||||||
}
|
}
|
||||||
|
|
||||||
System.out.print("All isstopped\n");
|
System.out.print("All isstopped\n");
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user