• Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!

Streaming data records

Pumbaa

Nervous Newbie
Joined
Aug 20, 2010
Messages
4
Likes received
0
Thanks received
0
Please advise right code to put in Java Listener class to send all incoming steaming quotes to MySQL database.
When I put :
conn.insert(sql);
sql = "INSERT INTO MarketData (`No`, `Symbol`, `BidPx`, `OfferPx`, `TimeStamp`) VALUES ('"+ incomingQuote.getQuoteID() + "','" + incomingQuote.getInstrument().getSymbol() + "','" + incomingQuote.getAskOpen() + "','" + incomingQuote.getBidOpen() + "','" + incomingQuote.getOpenTimestamp() + "')";
Java send to DB only one record for each pair and after stops sending. Means I can see quotes on terminal display but they are not collecting in database.
When I stop JM and restart I have another one set of quotes.
 
Please advise right code to put in Java Listener class to send all incoming steaming quotes to MySQL database.
When I put :
conn.insert(sql);
sql = "INSERT INTO MarketData (`No`, `Symbol`, `BidPx`, `OfferPx`, `TimeStamp`) VALUES ('"+ incomingQuote.getQuoteID() + "','" + incomingQuote.getInstrument().getSymbol() + "','" + incomingQuote.getAskOpen() + "','" + incomingQuote.getBidOpen() + "','" + incomingQuote.getOpenTimestamp() + "')";
Java send to DB only one record for each pair and after stops sending. Means I can see quotes on terminal display but they are not collecting in database.
When I stop JM and restart I have another one set of quotes.

In order for anybody to help you, you will need to provide a lot more information than you have done.

I don't think you realise how much that snippet of code reveals about the code quality in the system that you are working on. If that is the type of code that you are putting into a production system, I suggest you give up programming now.
 
Streaming data

Streaming data

I'm not in a hurry, so I have time to study, just if you know, give me idea from where to start to search, because in available sources about Java and MySQL I can't find any information about recording of streaming data. I believe that everything very simple and logical, but very important to find proper point of start.
 
sounds like you just need an infinite loop with break clauses
 
OK then,

What methods and events have you got on your IncomingQuotes class?
 
PHP:
public class ClientTester {

    private static List accounts = new ArrayList();
    private static String accountMassID;
    private static String openOrderMassID;
    private static String openPositionMassID;
    private static String closedPositionMassID;
    private static String tradingSessionStatusID;
    private static TradingSessionStatus tradingSessionStatus;
    private static boolean printMarketData = false;

    public static void main(final String[] args) {
        System.out.println("startctc");
        // step 1: get an instance of IGateway from the GatewayFactory
        final IGateway fxcmGateway = GatewayFactory.createGateway();

        /*
        step 2: register a generic message listener with the gateway, this
        listener in particular gets all messages that are related to the trading
        platform MarketDataSnapshot,OrderSingle,ExecutionReport, etc...
         */
        fxcmGateway.registerGenericMessageListener(new IGenericMessageListener() {

            public void messageArrived(ITransportable message) {
                if (message instanceof MarketDataSnapshot) {
                    MarketDataSnapshot incomingQuote = (MarketDataSnapshot) message;
                    if (printMarketData || incomingQuote.getMDReqID() != null) {
                        try {

                            ConnectDB conn = new ConnectDB();
                            String sql = null;
                            conn.insert(sql);
                            sql = "INSERT INTO Sample5 (`QuoteID`, `Symbol`, `BidPx`, `OfferPx`, `TimeStamp`) VALUES ('" + incomingQuote.getQuoteID() + "','" + incomingQuote.getInstrument().getSymbol() + "','" + incomingQuote.getAskOpen() + "','" + incomingQuote.getBidOpen() + "','" + incomingQuote.getOpenTimestamp() + "')";

this is standard connection procedure for FXCM streaming server with supplied code and all quotes comes perfect, means we have source of data. I'm only add from ConnectDB conn = new ConnectDB;
But for me it's crazy that in all books (even in Horstmann & Cornell Core Java Advanced Features) and Internet described only how to work with database, but nowhere how to feed it with streaming data. And only the command which I found to put new data is INSERT. All other only for work with existing data. Sorry for expression, but I'm trying to find solution from Monday.
 
Have you worked with SQL databases before?

Perhaps you should take a look at hibernate or JPA?
 
No, this is my first experience. But I've already studied most basic commands of MySQL and logic how to use them. Unfortunately all courses oriented for extracting and comparing data, but no one for feeding. But to start any analytical research I have to collect data.
 
But for me it's crazy that in all books (even in Horstmann & Cornell Core Java Advanced Features) and Internet described only how to work with database, but nowhere how to feed it with streaming data. And only the command which I found to put new data is INSERT. All other only for work with existing data. Sorry for expression, but I'm trying to find solution from Monday.

So essentially, you want to insert a row in to a table whenever a message is received and you need a book or the internet for that?

There's a painfully obvious error in the code you've pasted in here, I guess you may be losing exceptions because it's probably running in a different thread.
 
So essentially, you want to insert a row in to a table whenever a message is received and you need a book or the internet for that?

There's a painfully obvious error in the code you've pasted in here, I guess you may be losing exceptions because it's probably running in a different thread.

I think even I have spotted it :eek:

I know very little about Java.
 

Advertisers

Back
Top