Search in sources :

Example 76 with Quote

use of com.questdb.model.Quote in project questdb by bluestreak01.

the class QueryTest method testAllBySymbolValuesOverInterval.

@Test
public void testAllBySymbolValuesOverInterval() throws Exception {
    ResultSet<Quote> rs = q.all().withKeys().slice(new Interval(ts2, ts1)).asResultSet();
    Assert.assertEquals(0, rs.size());
    String expected = "2013-04-29T01:40:00.000Z\tWTB.L\t0.154905273744959\t0.3463641298845208\t1190004376\t548681062\tFast trading\tSK\n" + "2013-04-29T07:13:20.000Z\tWTB.L\t0.94782183700974\t0.6385933398879912\t507408673\t477022979\tFast trading\tSK\n" + "2013-04-29T12:46:40.000Z\tBT-A.L\t0.3542490655977256\t0.19109723285077962\t1111156559\t746276626\tFast trading\tSK\n" + "2013-04-30T04:03:20.000Z\tWTB.L\t0.47797848524672126\t0.6430092838094059\t1405625919\t753070187\tFast trading\tLXE\n" + "2013-04-30T11:00:00.000Z\tBT-A.L\t0.7630002744048395\t0.5655301296325983\t170034893\t555018287\tFast trading\tGR\n" + "2013-04-30T22:06:40.000Z\tBT-A.L\t0.7147870329232192\t0.5047251666299352\t1632653036\t1459199712\tFast trading\tGR\n" + "2013-05-01T10:36:40.000Z\tBT-A.L\t0.6561113751342125\t0.47910748281262994\t514913551\t831670347\tFast trading\tLXE\n" + "2013-05-01T14:46:40.000Z\tWTB.L\t0.9460194923216076\t0.09048831254437362\t1231092052\t1026180063\tFast trading\tLXE\n" + "2013-05-02T07:26:40.000Z\tBT-A.L\t0.9029266635624776\t0.4400626920975901\t188866311\t1663084154\tFast trading\tSK\n" + "2013-05-02T13:00:00.000Z\tBT-A.L\t0.4129219991106413\t0.5025269563465262\t944280080\t148476167\tFast trading\tLXE\n" + "2013-05-02T14:23:20.000Z\tWTB.L\t0.7858327043313086\t0.7679013186397453\t150870909\t427886371\tFast trading\tGR\n" + "2013-05-02T18:33:20.000Z\tBT-A.L\t0.9296374772157955\t0.19088899950218174\t980203892\t1476326981\tFast trading\tLXE\n" + "2013-05-02T22:43:20.000Z\tBT-A.L\t0.12282110119740142\t0.822933043281861\t997442403\t430556502\tFast trading\tSK\n" + "2013-05-03T01:30:00.000Z\tWTB.L\t0.6696457609278927\t0.7177695674107006\t1859909396\t1567568718\tFast trading\tSK\n" + "2013-05-03T07:03:20.000Z\tBT-A.L\t0.008144226019699663\t0.8149620429664706\t1492076657\t2143247261\tFast trading\tLXE\n";
    rs = q.all().withKeys("WTB.L", "BT-A.L").slice(new Interval(ts2, ts1)).asResultSet();
    TestUtils.assertEquals(expected, rs.sort());
}
Also used : Quote(com.questdb.model.Quote) Interval(com.questdb.std.time.Interval) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Example 77 with Quote

use of com.questdb.model.Quote in project questdb by bluestreak01.

the class QueryTest method testFindWithSearchSymbols.

@Test
public void testFindWithSearchSymbols() throws JournalException {
    final long millis = System.currentTimeMillis();
    Quote q1 = new Quote().setSym("S1").setEx("EX1").setTimestamp(millis);
    Quote q2 = new Quote().setSym("S2").setEx("EX1").setTimestamp(millis);
    Quote q3 = new Quote().setSym("S3").setEx("EX1").setTimestamp(millis);
    Quote q4 = new Quote().setSym("S4").setEx("EX3").setTimestamp(millis);
    w.append(q1, q2, q3, q4);
    // Unfiltered
    QueryAllBuilder<Quote> builder = q.all().withSymValues("ex", "EX1");
    Assert.assertEquals(3, builder.asResultSet().size());
    // Filtered
    builder.filter("sym", q1.getSym()).filter("sym", q2.getSym());
    Assert.assertEquals(2, builder.asResultSet().size());
    // Non-existent
    builder.resetFilter();
    try {
        builder.filter("sym", "S7");
        Assert.fail("Expect exception here");
    } catch (Exception e) {
    // ok
    }
    // Filtered - 2 existing and 1 from a different exchange
    builder.resetFilter();
    builder.filter("sym", q1.getSym()).filter("sym", q2.getSym()).filter("sym", q4.getSym());
    Assert.assertEquals(2, builder.asResultSet().size());
}
Also used : Quote(com.questdb.model.Quote) JournalException(com.questdb.std.ex.JournalException) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Example 78 with Quote

use of com.questdb.model.Quote in project questdb by bluestreak01.

the class TxLogTest method testTxLogIterator.

@Test
public void testTxLogIterator() throws Exception {
    try (JournalWriter<Quote> w = getFactory().writer(Quote.class)) {
        for (int i = 0; i < 10; i++) {
            TestUtils.generateQuoteData(w, 100, w.getMaxTimestamp());
            w.commit();
        }
        final String expected = "10\t0\t1000\n" + "9\t0\t900\n" + "8\t0\t800\n" + "7\t0\t700\n" + "6\t0\t600\n" + "5\t0\t500\n" + "4\t0\t400\n" + "3\t0\t300\n" + "2\t0\t200\n" + "1\t0\t100\n" + "0\t0\t0\n";
        DelimitedCharSink sink = new DelimitedCharSink(new StringSink(), '\t', "\n");
        for (Tx tx : w.transactions()) {
            sink.put(tx.txn);
            sink.put(tx.journalMaxRowID == -1 ? 0 : Rows.toPartitionIndex(tx.journalMaxRowID));
            sink.put(tx.journalMaxRowID == -1 ? 0 : Rows.toLocalRowID(tx.journalMaxRowID));
            sink.eol();
        }
        sink.flush();
        Assert.assertEquals(expected, sink.toString());
    }
}
Also used : Quote(com.questdb.model.Quote) DelimitedCharSink(com.questdb.std.str.DelimitedCharSink) StringSink(com.questdb.std.str.StringSink) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Example 79 with Quote

use of com.questdb.model.Quote in project questdb by bluestreak01.

the class TestUtils method generateQuoteData.

public static void generateQuoteData(JournalWriter<Quote> w, int count, long timestamp, long increment) throws JournalException {
    String[] symbols = { "AGK.L", "BP.L", "TLW.L", "ABF.L", "LLOY.L", "BT-A.L", "WTB.L", "RRS.L", "ADM.L", "GKN.L", "HSBA.L" };
    Quote q = new Quote();
    Rnd r = new Rnd();
    for (int i = 0; i < count; i++) {
        q.clear();
        q.setSym(symbols[Math.abs(r.nextInt() % (symbols.length - 1))]);
        q.setAsk(Math.abs(r.nextDouble()));
        q.setBid(Math.abs(r.nextDouble()));
        q.setAskSize(Math.abs(r.nextInt()));
        q.setBidSize(Math.abs(r.nextInt()));
        q.setEx("LXE");
        q.setMode("Fast trading");
        q.setTimestamp(timestamp);
        timestamp += increment;
        w.append(q);
    }
}
Also used : Quote(com.questdb.model.Quote)

Example 80 with Quote

use of com.questdb.model.Quote in project questdb by bluestreak01.

the class TestUtils method generateQuoteData.

public static void generateQuoteData(JournalWriter<Quote> w, int count) throws JournalException, NumericException {
    String[] symbols = { "AGK.L", "BP.L", "TLW.L", "ABF.L", "LLOY.L", "BT-A.L", "WTB.L", "RRS.L", "ADM.L", "GKN.L", "HSBA.L" };
    long[] timestamps = { DateFormatUtils.parseDateTime("2013-09-04T10:00:00.000Z"), DateFormatUtils.parseDateTime("2013-10-04T10:00:00.000Z"), DateFormatUtils.parseDateTime("2013-11-04T10:00:00.000Z") };
    Quote q = new Quote();
    Rnd r = new Rnd();
    for (int i = 0; i < count; i++) {
        q.clear();
        q.setSym(symbols[Math.abs(r.nextInt() % (symbols.length))]);
        q.setAsk(Math.abs(r.nextDouble()));
        q.setBid(Math.abs(r.nextDouble()));
        q.setAskSize(Math.abs(r.nextInt()));
        q.setBidSize(Math.abs(r.nextInt()));
        q.setEx("LXE");
        q.setMode("Fast trading");
        q.setTimestamp(timestamps[i * timestamps.length / count]);
        w.append(q);
    }
    w.commit();
}
Also used : Quote(com.questdb.model.Quote)

Aggregations

Quote (com.questdb.model.Quote)80 Test (org.junit.Test)64 AbstractTest (com.questdb.test.tools.AbstractTest)63 ClientConfig (com.questdb.net.ha.config.ClientConfig)20 CountDownLatch (java.util.concurrent.CountDownLatch)19 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)13 JournalException (com.questdb.std.ex.JournalException)11 ServerConfig (com.questdb.net.ha.config.ServerConfig)10 ArrayList (java.util.ArrayList)9 Interval (com.questdb.std.time.Interval)8 InputStream (java.io.InputStream)6 JournalConfigurationBuilder (com.questdb.store.factory.configuration.JournalConfigurationBuilder)5 File (java.io.File)5 JournalListener (com.questdb.store.JournalListener)4 ServerNode (com.questdb.net.ha.config.ServerNode)3 RecordSource (com.questdb.ql.RecordSource)3 Rnd (com.questdb.std.Rnd)3 StringSink (com.questdb.std.str.StringSink)3 Ignore (org.junit.Ignore)3 NumericException (com.questdb.common.NumericException)2