Skip to main content

Strategy Agent

In this post I would like explain you how create your custom strategy and runs it in debug mode from your preferite IDE.




public static void main(String[] args) {
String cmds = "MarketData.txt";
StrategyAgent.main(new String[]{cmds});
} catch (Exception e) {
e.printStackTrace();
}
MarketData.java


import org.marketcetera.strategy.java.Strategy;
import org.marketcetera.event.AskEvent;
import org.marketcetera.event.BidEvent;
import org.marketcetera.event.TradeEvent;
import org.marketcetera.marketdata.MarketDataRequest;
import static org.marketcetera.marketdata.MarketDataRequest.*;

/* $License$ */
/**
 * Strategy that receives market data
 *
 * @author anshul@marketcetera.com
 * @version $Id$
 * @since $Release$
 */
public class MarketData extends Strategy {
    private static final String SYMBOLS = "AMZN,JAVA"; //Depends on MD - can be other symbols
    private static final String MARKET_DATA_PROVIDER = "bogus"; // Can be activ, bogus, marketcetera
    /**
     * Executed when the strategy is started.
     * Use this method to set up data flows
     * and other initialization tasks.
     */
    @Override
    public void onStart() {
      System.out.println("onStart");
        requestMarketData(MarketDataRequest.newRequest().
                withSymbols(SYMBOLS).
                fromProvider(MARKET_DATA_PROVIDER).
                withContent(Content.LATEST_TICK, Content.TOP_OF_BOOK));
               
       
    }

    /**
     * Executed when the strategy receives an ask event.
     *
     * @param inAsk the ask event.
     */
    @Override
    public void onAsk(AskEvent inAsk) {
        warn("Ask " + inAsk);
        System.out.println(inAsk.toString());
    }

    /**
     * Executed when the strategy receives a bid event.
     *
     * @param inBid the bid event.
     */
    @Override
    public void onBid(BidEvent inBid) {
        warn("Bid " + inBid);
        System.out.println(inBid.toString());
    }

    /**
     * Executed when the strategy receives a trade event.
     *
     * @param inTrade the ask event.
     */
    @Override
    public void onTrade(TradeEvent inTrade) {
        warn("Trade " + inTrade);
        System.out.println(inTrade.toString());
    }

}

Comments

Popular posts from this blog

Open source libraries and trading systems review

In this post I reviewed some of the most important trading systems and financial librarys on the net. SFL Java Trading System Enviroment http://sourceforge.net/projects/sfljtse http://www.sflweb.org/index.php?blog=sfljtse The SFL Java Trading System Enviroment is a java application built on KISS principle (Keep It Simple,Stupid) and its aim is to provide a fast and platform indipendent infrastructure to develop and execute trading Systems. EclipseTrade http://sourceforge.net/projects/eclipsetrader/ http://eclipsetrader.sourceforge.net/ Stock exchange analysis system, featuring shares pricing watch, intraday and history charts with technical analysis indicators, level II/market depth view, news watching, automated trading systems, integrated trading. Based on Eclipse RCP framework. JsystemTrader http://code.google.com/p/jsystemtrader/ JSystemTrader is a fully automated trading system (ATS) that can trade various types of market securities during the trading day without user mo

Lucid desktop

Lucid desktop , A web operating system (WebOS) software that allow you setup own web desktop OS online. This open source WebOS is built with PHP and uses a SQL database for storing data. Plus more, Lucid Desktop WebOS is a multi-user application , which is very modular with the support for installable applications. With Lucid desktop WebOS, you can access your media, office documents, and other files anywhere. Meanwhile, user can stay up to date with Twitter, RSS feeds, and what’s happening on the web. Plus more, Lucid Desktop already comes with lots of applications like text editor, calculator, image viewer, simple games, web browser, feed reader, music player and more. With the help of a file manager, you can add-edit-delete files and folders (a context menu makes these steps easier), change the appearance of the desktop with theme support and auto-update the OS to the latest version. Lucid Desktop Main Features: Extremely customizable: Lucid allows you to pick you

Best chart libraries

Charts are an indispensable part of any data visualization work. People can grok visual representation of data easily than a textual variety. Today there are a huge number of free chart libraries available to display visualizations on websites. Below is a small list of  some of the libraries available for displaying charts using php. pChart - a PHP class to build charts pChart is a PHP class oriented framework designed to create aliased charts. Most of todays chart libraries have a cost, our project is intended to be free. Data can be retrieved from SQL queries, CSV files, or manually provided. This project is still under development and new features or fix are made every week. Focus has been put on rendering quality introducing an aliasing algorithm to draw eye candy graphics. Rendering speed has been dramatically enhanced since the first version, we'll still continue optimising the code!  JpGraph   JpGraph is an Object-Oriented Graph creating library for PHP >= 5.1