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

Manage Vtiger Menu

How Manage and customize Vtiger Menu You need to modify the function getAppMenuList in the file modules/Vtiger/models/MenuStructure.php 'JS_YEARS' => 'anni', 'JS_TODAY' => 'oggi', 'JS_TOMORROW' => 'domani', 'JS_YESTERDAY' => 'ieri', 'JS_CREATE_TASK' => 'Creare Attività', Add the new Item voice public static function getAppMenuList(){ return array('MARKETING','SALES','INVENTORY','SUPPORT','PROJECT', ' YOUR_APP_MENU_NAME ' ); } public static function getAppIcons() { $appImageIcons = array( 'MARKETING' => 'fa-users', 'SALES' => 'fa-dot-circle-o', 'SUPPORT' => 'fa-life-ring', 'INVENTORY' => 'vicon-inventory', 'PROJECT' => 'fa-briefcase', 'TOOLS' => 'fa-wrench