Added some stuff.

This commit is contained in:
7u83 2017-01-20 17:03:50 +01:00
parent 563e902613
commit ba557179c7
5 changed files with 100 additions and 39 deletions

View File

@ -10,7 +10,10 @@ import sesim.Exchange.*;
import sesim.Quote; import sesim.Quote;
import gui.MainWin; import gui.MainWin;
import java.awt.geom.Rectangle2D; import java.awt.geom.Rectangle2D;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator; import java.util.Iterator;
/** /**
@ -44,32 +47,84 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver {
int min; int min;
int max; int max;
int getY(float Y) { int getY(float Y) {
return 0; return 0;
} }
void drawCandle(Graphics2D g, OHLCData d, int x, int y) { void drawCandle(Graphics2D g, OHLCData d, int x, int y) {
} }
class XLegendDef {
void drawXLegend(Graphics2D g) { double unit_width = 1;
int big_tick = 10;
long start;
XLegendDef(){
}
String getAt(int unit){
Date date = new Date(start);
DateFormat formatter = new SimpleDateFormat("HH:mm:ss:SSS");
String dateFormatted = formatter.format(date);
return dateFormatted;
}
}
void drawXLegend(Graphics2D g,XLegendDef xld) {
//XLegendDef xld = new XLegendDef();
g = (Graphics2D) g.create(); g = (Graphics2D) g.create();
int xl_height = 30; int xl_height = 30;
Dimension dim = this.getSize(); Dimension dim = this.getSize();
int sheight = g.getFontMetrics().getHeight(); int em_height = g.getFontMetrics().getHeight();
int em_width = g.getFontMetrics().stringWidth("M");
int y = dim.height - sheight * 3; int y = dim.height - em_height * 3;
g.drawLine(0, y, dim.width, y); g.drawLine(0, y, dim.width, y);
int n = 0;
for (double 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++;
}
/*
for (int i = 0; i < items; i ++) { for (int i = 0; i < items; i ++) {
int x = i * this.item_width; int x = i * this.item_width;
@ -87,19 +142,20 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver {
String text; String text;
if (d != null) { if (d != null) {
text = " "; text = "A";
} else { } else {
text = " "; text = "x";
} }
int swidth = g.getFontMetrics().stringWidth(text); int swidth = g.getFontMetrics().stringWidth(text);
g.drawString(text, x - swidth / 2, y + sheight * 2); g.drawString(text, x - swidth / 2, y + em_height * 2);
} }
*/
//for(int x=0; x) //for(int x=0; x)
} }
@ -149,7 +205,10 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver {
private void draw(Graphics2D g) { private void draw(Graphics2D g) {
this.drawXLegend(g); OHLCDataItem di0 = data.data.get(0);
XLegendDef xld= new XLegendDef();
//xld.start=di.
this.drawXLegend(g,xld);
this.getSize(); this.getSize();
@ -176,6 +235,7 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver {
// } // }
ArrayList<OHLCDataItem> od = data.data; ArrayList<OHLCDataItem> od = data.data;
// System.out.print("OD S: " + od.size() + "\n"); // 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));
@ -210,7 +270,6 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver {
//val/ ((data.max-data.min)/dim.height); //val/ ((data.max-data.min)/dim.height);
// System.out.print("MINMAX " + min + " " + max + " " + dim.height + "\n"); // 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;
@ -222,7 +281,6 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver {
lasty = (int) y; lasty = (int) y;
// System.out.print("Draw Line: " + x + " " + y + "\n"); // System.out.print("Draw Line: " + x + " " + y + "\n");
} }
// g.drawLine(0, 0, 100, (int) ((this.current.close-80.0)*80.0)); // g.drawLine(0, 0, 100, (int) ((this.current.close-80.0)*80.0));

View File

@ -36,7 +36,7 @@ public class OHLCData { //extends ArrayList <OHLCDataItem> {
float max=0; float max=0;
float min=0; float min=0;
int ras=60000/10; int ras=20000/10;
long time_start; long time_start;

View File

@ -224,9 +224,12 @@ public class MainWin extends javax.swing.JFrame {
// SwitchingTraderConfig rcfg1 = new SwitchingTraderConfig(); // SwitchingTraderConfig rcfg1 = new SwitchingTraderConfig();
// SwitchingTraderConfig rcfg1 = new SwitchingTraderConfig(); // SwitchingTraderConfig rcfg1 = new SwitchingTraderConfig();
RandomTraderConfig rcfg1 = new RandomTraderConfig(); RandomTraderConfig rcfg1 = new RandomTraderConfig();
AutoTrader rt1 = rcfg1.createTrader(se, 1000, 1000); // rcfg1.sell_limit[0]=-1;
// rcfg1.sell_limit[1]=1;
AutoTrader rt1 = rcfg1.createTrader(se, 1000000, 1000000);
se.traders.add(rt1); se.traders.add(rt1);
rt1.setName("Bob"); rt1.setName("Alice");
rt1.start(); rt1.start();
@ -237,11 +240,11 @@ 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<530; i++){ for (int i=0; i<100; i++){
AutoTrader randt = cfg.createTrader(se, 100, 100); AutoTrader randt = cfg.createTrader(se, 100000, 100000);
se.traders.add(randt); se.traders.add(randt);
randt.setName("Alice"); randt.setName("Bob");
randt.start(); randt.start();
} }

View File

@ -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 / 3; return rc / 600;
} }
@ -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 / 33; return rc / 28;
// return this.event(); // return this.event();
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2017, tobias * Copyright (c) 2017, 7u83
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -31,18 +31,18 @@ import sesim.Exchange;
/** /**
* *
* @author tobias * @author 7u83
*/ */
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 = {-1f, 1f}; public float[] sell_limit = {-3, 3};
public int[] sell_order_wait = {1000, 5000}; public int[] sell_order_wait = {500, 1500};
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, 1f}; public float[] buy_limit = {-1, 3};
public int[] buy_order_wait = {1000, 5000}; public int[] buy_order_wait = {500, 1500};
public int[] wait_after_buy = {10, 30}; public int[] wait_after_buy = {10, 30};
@Override @Override