Introduced Globals object
This commit is contained in:
parent
d9c7dac38f
commit
ea4795967a
@ -10,7 +10,7 @@ import sesim.OHLCData;
|
||||
import java.awt.*;
|
||||
import sesim.Exchange.*;
|
||||
import sesim.Quote;
|
||||
import gui.MainWin;
|
||||
import gui.Globals;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
@ -29,11 +29,11 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver {
|
||||
*/
|
||||
public Chart() {
|
||||
initComponents();
|
||||
if (MainWin.se == null) {
|
||||
if (Globals.se == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
MainWin.se.addQuoteReceiver(this);
|
||||
Globals.se.addQuoteReceiver(this);
|
||||
|
||||
//Graphics g = this.getGraphics();
|
||||
//g.drawString("Hello world", 0, 0);
|
||||
|
@ -36,7 +36,7 @@ public class AskBook extends OrderBook {
|
||||
|
||||
@Override
|
||||
ArrayList <Order> getOrderBook() {
|
||||
return MainWin.se.getOrderBook(OrderType.ASK,40);
|
||||
return Globals.se.getOrderBook(OrderType.ASK,40);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -45,10 +45,10 @@ public class AskBook extends OrderBook {
|
||||
}
|
||||
|
||||
public AskBook(){
|
||||
if (MainWin.se == null) {
|
||||
if (Globals.se == null) {
|
||||
return;
|
||||
}
|
||||
MainWin.se.addBookReceiver(OrderType.ASK, this);
|
||||
Globals.se.addBookReceiver(OrderType.ASK, this);
|
||||
|
||||
}
|
||||
|
||||
|
@ -35,14 +35,14 @@ import sesim.Exchange.*;
|
||||
public class BidBook extends OrderBook {
|
||||
|
||||
@Override
|
||||
ArrayList <Order> getOrderBook() {
|
||||
return MainWin.se.getOrderBook(OrderType.BID, 40);
|
||||
ArrayList<Order> getOrderBook() {
|
||||
return Globals.se.getOrderBook(OrderType.BID, 40);
|
||||
}
|
||||
|
||||
public BidBook() {
|
||||
if (MainWin.se == null) {
|
||||
if (Globals.se == null) {
|
||||
return;
|
||||
}
|
||||
MainWin.se.addBookReceiver(OrderType.BID, this);
|
||||
Globals.se.addBookReceiver(OrderType.BID, this);
|
||||
}
|
||||
}
|
||||
|
@ -188,7 +188,7 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver {
|
||||
long start = (ct - 60)/step*step;
|
||||
|
||||
|
||||
SortedSet<Quote> h = MainWin.se.getQuoteHistory(start);
|
||||
SortedSet<Quote> h = Globals.se.getQuoteHistory(start);
|
||||
|
||||
for (long i = start * 1000; i < ct * 1000; i += step * 1000) {
|
||||
OHLCDataItem d = getOhlcData(i, i + step * 1000, h);
|
||||
@ -293,7 +293,7 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver {
|
||||
);
|
||||
|
||||
long start = (ct - 60)/5*5;
|
||||
SortedSet<Quote> h = MainWin.se.getQuoteHistory(start);
|
||||
SortedSet<Quote> h = Globals.se.getQuoteHistory(start);
|
||||
|
||||
System.out.print("Number of quotes" + start + ":" + ct + "\n");
|
||||
System.out.print("Number of quotes:" + h.size() + "\n");
|
||||
|
36
src/main/java/gui/Globals.java
Normal file
36
src/main/java/gui/Globals.java
Normal file
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* 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 Globals {
|
||||
|
||||
static public sesim.Exchange se;
|
||||
|
||||
}
|
@ -39,7 +39,7 @@ import traders.*;
|
||||
public class MainWin extends javax.swing.JFrame {
|
||||
|
||||
static MainWin instance;
|
||||
static public sesim.Exchange se;
|
||||
//static public sesim.Exchange se;
|
||||
//static sesim.Account_old myAccount;
|
||||
|
||||
|
||||
@ -52,8 +52,8 @@ public class MainWin extends javax.swing.JFrame {
|
||||
this.setLocationRelativeTo(this);
|
||||
|
||||
|
||||
double aid1 = se.createAccount(100, 100);
|
||||
double aid2 = se.createAccount(1000, 100);
|
||||
double aid1 = Globals.se.createAccount(100, 100);
|
||||
double aid2 = Globals.se.createAccount(1000, 100);
|
||||
|
||||
/* AccountData a1 = se.getAccountData(aid1);
|
||||
AccountData a2 = se.getAccountData(aid2);
|
||||
@ -209,7 +209,7 @@ public class MainWin extends javax.swing.JFrame {
|
||||
}//GEN-LAST:event_jButton1ActionPerformed
|
||||
|
||||
private void FileRunActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_FileRunActionPerformed
|
||||
se.timer.start();
|
||||
Globals.se.timer.start();
|
||||
}//GEN-LAST:event_FileRunActionPerformed
|
||||
|
||||
private void helpAboutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_helpAboutActionPerformed
|
||||
@ -232,7 +232,7 @@ public class MainWin extends javax.swing.JFrame {
|
||||
*/
|
||||
public static void main(String args[]) {
|
||||
|
||||
se = new Exchange();
|
||||
Globals.se = new Exchange();
|
||||
//se.timer.start();
|
||||
|
||||
|
||||
@ -246,8 +246,8 @@ public class MainWin extends javax.swing.JFrame {
|
||||
// rcfg1.sell_limit[0]=-1;
|
||||
// rcfg1.sell_limit[1]=1;
|
||||
|
||||
AutoTrader rt1 = rcfg1.createTrader(se, 1000000, 1000000);
|
||||
se.traders.add(rt1);
|
||||
AutoTrader rt1 = rcfg1.createTrader(Globals.se, 1000000, 1000000);
|
||||
Globals.se.traders.add(rt1);
|
||||
rt1.setName("Alice");
|
||||
rt1.start();
|
||||
|
||||
@ -260,9 +260,9 @@ public class MainWin extends javax.swing.JFrame {
|
||||
RandomTraderConfig cfg= new RandomTraderConfig();
|
||||
|
||||
for (int i=0; i<30; i++){
|
||||
AutoTrader randt = cfg.createTrader(se, 100000, 100000);
|
||||
AutoTrader randt = cfg.createTrader(Globals.se, 100000, 100000);
|
||||
|
||||
se.traders.add(randt);
|
||||
Globals.se.traders.add(randt);
|
||||
randt.setName("Bob");
|
||||
randt.start();
|
||||
}
|
||||
|
@ -118,39 +118,13 @@
|
||||
<Layout>
|
||||
<DimensionLayout dim="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="1" attributes="0">
|
||||
<Component id="orderBookPanel1" pref="226" max="32767" attributes="0"/>
|
||||
<EmptySpace type="unrelated" max="-2" attributes="0"/>
|
||||
<Component id="bidBook1" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<Component id="desktopPane" alignment="0" max="32767" attributes="0"/>
|
||||
<EmptySpace min="0" pref="913" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
<DimensionLayout dim="1">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" attributes="0">
|
||||
<Component id="desktopPane" min="-2" pref="108" max="-2" attributes="0"/>
|
||||
<EmptySpace pref="48" max="32767" attributes="0"/>
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Component id="orderBookPanel1" min="-2" pref="310" max="-2" attributes="0"/>
|
||||
<Component id="bidBook1" min="-2" pref="218" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace min="0" pref="554" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
</Layout>
|
||||
<SubComponents>
|
||||
<Component class="gui.BidBook" name="bidBook1">
|
||||
</Component>
|
||||
<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>
|
||||
<Component class="gui.OrderBookPanel" name="orderBookPanel1">
|
||||
</Component>
|
||||
</SubComponents>
|
||||
</Form>
|
||||
|
@ -47,9 +47,6 @@ public class NewMDIApplication extends javax.swing.JFrame {
|
||||
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
||||
private void initComponents() {
|
||||
|
||||
bidBook1 = new gui.BidBook();
|
||||
desktopPane = new javax.swing.JDesktopPane();
|
||||
orderBookPanel1 = new gui.OrderBookPanel();
|
||||
menuBar = new javax.swing.JMenuBar();
|
||||
fileMenu = new javax.swing.JMenu();
|
||||
openMenuItem = new javax.swing.JMenuItem();
|
||||
@ -134,22 +131,11 @@ public class NewMDIApplication extends javax.swing.JFrame {
|
||||
getContentPane().setLayout(layout);
|
||||
layout.setHorizontalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
|
||||
.addComponent(orderBookPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 226, Short.MAX_VALUE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
|
||||
.addComponent(bidBook1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addContainerGap())
|
||||
.addComponent(desktopPane)
|
||||
.addGap(0, 913, Short.MAX_VALUE)
|
||||
);
|
||||
layout.setVerticalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addComponent(desktopPane, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 48, Short.MAX_VALUE)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(orderBookPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 310, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(bidBook1, javax.swing.GroupLayout.PREFERRED_SIZE, 218, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addContainerGap())
|
||||
.addGap(0, 554, Short.MAX_VALUE)
|
||||
);
|
||||
|
||||
pack();
|
||||
@ -196,19 +182,16 @@ public class NewMDIApplication extends javax.swing.JFrame {
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private javax.swing.JMenuItem aboutMenuItem;
|
||||
private gui.BidBook bidBook1;
|
||||
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 gui.OrderBookPanel orderBookPanel1;
|
||||
private javax.swing.JMenuItem pasteMenuItem;
|
||||
private javax.swing.JMenuItem saveAsMenuItem;
|
||||
private javax.swing.JMenuItem saveMenuItem;
|
||||
|
@ -180,7 +180,7 @@ public abstract class OrderBook extends javax.swing.JPanel implements Exchange.B
|
||||
this.setBorder(BorderFactory.createEmptyBorder());
|
||||
this.orderBookScroller.setBorder(BorderFactory.createBevelBorder(0));
|
||||
|
||||
if (MainWin.se == null) {
|
||||
if (Globals.se == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -42,7 +42,7 @@ public class OrderBookPanel extends javax.swing.JPanel {
|
||||
sesim.Exchange se;
|
||||
|
||||
public OrderBookPanel() {
|
||||
this.se = MainWin.se;
|
||||
this.se = Globals.se;
|
||||
|
||||
initComponents();
|
||||
|
||||
|
@ -41,9 +41,9 @@ public class QuotePanel extends javax.swing.JPanel implements sesim.Exchange.Quo
|
||||
*/
|
||||
public QuotePanel() {
|
||||
initComponents();
|
||||
if (MainWin.se==null)
|
||||
if (Globals.se==null)
|
||||
return;
|
||||
MainWin.se.addQuoteReceiver(this);
|
||||
Globals.se.addQuoteReceiver(this);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -57,7 +57,7 @@ public class TraderListPanel extends javax.swing.JPanel
|
||||
this.setBorder(BorderFactory.createEmptyBorder());
|
||||
// this.orderBookScroller.setBorder(BorderFactory.createBevelBorder(0));
|
||||
|
||||
if (MainWin.se == null) {
|
||||
if (Globals.se == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -70,8 +70,8 @@ public class TraderListPanel extends javax.swing.JPanel
|
||||
// h.setBackground(Color.BLUE);
|
||||
// h.setForeground(Color.green);
|
||||
|
||||
if (MainWin.se != null) {
|
||||
this.se = MainWin.se;
|
||||
if (Globals.se != null) {
|
||||
this.se = Globals.se;
|
||||
this.list = this.getTraderList();
|
||||
se.timer.startTimerEvent(this, 1000);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user