All Downloads are FREE. Search and download functionalities are using the official Maven repository.

bench.Receiver Maven / Gradle / Ivy

There is a newer version: 4.2.73
Show newest version
/**
 * Copyright (C) 2011-2012 Barchart, Inc. 
 *
 * All rights reserved. Licensed under the OSI BSD License.
 *
 * http://www.opensource.org/licenses/bsd-license.php
 */
package bench;

import com.barchart.feed.api.Agent;
import com.barchart.feed.api.Marketplace;
import com.barchart.feed.api.MarketObserver;
import com.barchart.feed.api.model.data.Book.Entry;
import com.barchart.feed.api.model.data.Book.Top;
import com.barchart.feed.api.model.data.Market;
import com.barchart.feed.client.provider.BarchartMarketplace;

/**
 * 
 * you can invoke this utility from command line:
 * 
 * 
 * java - jar barchart-feed-ddf-client-X.Y.Z.jar bench.Receiver TCP 7500 IBM
 * 
* * arguments = { TCP / UDP , port, instrument1, instrument2, ...} * */ public class Receiver { // TODO /** * * @param args * @throws Exception */ public static void main(final String... args) throws Exception { if (args == null || args.length < 3) { throw new RuntimeException("Bad arguments passed to main"); } final Marketplace feed = new BarchartMarketplace(args[0], args[1]); final MarketObserver observer = new MarketObserver() { @Override public void onNext(Market value) { final StringBuilder sb = new StringBuilder(value.instrument().marketGUID()) .append(" ") .append(" EventTime=") .append(value.updated()); final Top top = value.book().top(); Entry entry = top.ask(); if (!entry.isNull()) { sb.append(" ASK TOP").append(" price=") .append(entry.price().asDouble()) .append(" qty=").append(entry.size().asDouble()); } entry = top.bid(); if (!entry.isNull()) { sb.append(" BID TOP").append(" price=") .append(entry.price().asDouble()) .append(" qty=").append(entry.size().asDouble()); } System.out.println(sb.toString()); } }; feed.startup(); final Agent myAgent = feed.newAgent(Market.class, observer); for(int i = 2; i < args.length; i++) { myAgent.include(args[i]); } System.in.read(); feed.shutdown(); System.exit(0); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy