Package com.collective2.signalEntry.journal

Examples of com.collective2.signalEntry.journal.C2EntryServiceJournal


    @Test
    public void transmitTest() {

        Collective2Adapter adapter = new Collective2Adapter();
        //mock request that does not return actual URL to collective2
        Request mockRequest = new Request(Command.Cancel) {
            @Override
            public URL buildURL() {
                return getClass().getClassLoader().getResource("staticResponse.xml");
            };
        };
View Full Code Here


        int id = 42;
        long time = stop;
        Instrument instrument = Instrument.Forex;
        String symbol = "GG";
        SignalAction action = SignalAction.BTO;
        Integer quantity = 10;
        QuantityComputable quantityComputable = new QuantityComputableFixed(quantity);
        long cancelAtMs = Long.MAX_VALUE;
        Duration timeInForce = Duration.GoodTilCancel;
View Full Code Here

        assertEquals(Integer.valueOf(-quantity),portfolio.position("GG").quantity());
        assertEquals(new BigDecimal("-60"),portfolio.equity(dataProvider));

        //Buy to cover this short position

        SignalAction action = SignalAction.BTC;
        OrderProcessorStop buyProcessor = new OrderProcessorStop(time,symbol,buyBelow);
        order = new Order(null, id,instrument,symbol,action,quantityComputable,cancelAtMs,timeInForce,buyProcessor,null);

        processed = buyProcessor.process(dataProvider, portfolio, commission, order, action, quantityComputable, null);
        expectedCash = expectedCash.subtract(expectedBuy.multiply(new BigDecimal(quantity))).subtract(commission);
View Full Code Here

        int id = 42;
        long time = stop;
        Instrument instrument = Instrument.Forex;
        String symbol = "GG";
        SignalAction action = SignalAction.BTO;
        Integer quantity = 10;
        QuantityComputable quantityComputable = new QuantityComputableFixed(quantity);
        long cancelAtMs = Long.MAX_VALUE;
        Duration timeInForce = Duration.GoodTilCancel;
        OrderProcessorMarket processor = new OrderProcessorMarket(time, symbol);
View Full Code Here

        assertEquals(Integer.valueOf(-quantity),portfolio.position("GG").quantity());
        assertEquals(new BigDecimal("-60"),portfolio.equity(dataProvider));

        //Buy to cover this short position

        SignalAction action = SignalAction.BTC;
        order = new Order(null, id,instrument,symbol,action,quantityComputable,cancelAtMs,timeInForce,processor, null);

        processed = processor.process(dataProvider, portfolio, commission, order, action, quantityComputable, null);

        assertTrue(processed);
View Full Code Here

        int id = 42;
        long time = stop;
        Instrument instrument = Instrument.Forex;
        String symbol = "GG";
        SignalAction action = SignalAction.BTO;
        Integer quantity = 10;
        QuantityComputable quantityComputable = new QuantityComputableFixed(quantity);
        long cancelAtMs = Long.MAX_VALUE;
        Duration timeInForce = Duration.GoodTilCancel;
        OrderProcessorMarket processor = new OrderProcessorMarket(time, symbol);
View Full Code Here

        int id = 42;
        long time = stop;
        Instrument instrument = Instrument.Forex;
        String symbol = "GG";
        SignalAction action = SignalAction.BTO;
        Integer quantity = 10;
        QuantityComputable quantityComputable = new QuantityComputableFixed(quantity);
        long cancelAtMs = Long.MAX_VALUE;
        Duration timeInForce = Duration.GoodTilCancel;
View Full Code Here

        assertEquals(Integer.valueOf(-quantity),portfolio.position("GG").quantity());
        assertEquals(new BigDecimal("-60"),portfolio.equity(dataProvider));

        //Buy to cover this short position

        SignalAction action = SignalAction.BTC;
        OrderProcessorLimit buyProcessor = new OrderProcessorLimit(time,symbol,buyBelow);
        order = new Order(null, id,instrument,symbol,action,quantityComputable,cancelAtMs,timeInForce,buyProcessor,null);

        processed = buyProcessor.process(dataProvider, portfolio, commission, order, action, quantityComputable,null);
        expectedCash = expectedCash.subtract(expectedBuy.multiply(new BigDecimal(quantity))).subtract(commission);
View Full Code Here

        // journal connection to collective2.com
        // saves the requests to disk in case of unexpected shutdown while
        // retrying to transmit.
        try {
            C2EntryServiceJournal journal = new C2EntryServiceLogFileJournal(file, rollingLogLimit);

            C2EntryServiceAdapter liveAdapter = new Collective2Adapter();
            C2ServiceFactory factory = new C2ServiceFactory(liveAdapter, journal);
            C2EntryService entryService = factory.signalEntryService(password,systemId);
            assertNotNull(entryService);
View Full Code Here

                    throw new C2ServiceException("simulated timeout, the internet is down.",true);
               }
            }
        };

        C2EntryServiceJournal journal = new C2EntryServiceMemoryJournal() {

            @Override
            public Iterator<Request> pending() {
                return super.pending();
            }

            @Override
            public void append(Request request) {
                assertEquals("*****",request.get(Parameter.Password));

                super.append(request);
            }

            @Override
            public void markSent(Request request) {

                Request oldest = super.pending().next();
                assertEquals("\n"+request+"\n"+oldest ,
                                  request,     oldest);

                super.markSent(request);
            }

            @Override
            public Request[] dropPending() {
                return super.dropPending();
            }
        };

        C2ServiceFactory factory = new C2ServiceFactory(simulationAdapter, journal);

        String password = "PA55WORD";
        Integer systemId = 99999999;
        String eMail = "someone@somewhere.com";
        C2EntryService sentryService = factory.signalEntryService(password, systemId, eMail);

        lock.lock(); //prevent transmit

        ImplResponse allSys = (ImplResponse)sentryService.sendAllSystemsRequest();
        ImplResponse allSig = (ImplResponse)sentryService.sendAllSignalsRequest();

        //check that everything got saved
        Iterator<Request> pending = journal.pending();
        assertTrue(pending.hasNext());
        assertEquals(allSys.secureRequest(),pending.next());
        assertTrue(pending.hasNext());
        assertEquals(allSig.secureRequest().secureClone(), pending.next());
        assertFalse(pending.hasNext());

        //Now dump and rebuild factory from scratch so its forced to build response list.
        //sentryService.awaitPending();//.shutdown();//must stop old daemon before starting new one

        lock.unlock();


        factory = new C2ServiceFactory(simulationAdapter, journal);
        sentryService = factory.signalEntryService(password, systemId, eMail);

        sentryService.awaitPending();

        assertFalse(journal.pending().hasNext());
    }
View Full Code Here

TOP

Related Classes of com.collective2.signalEntry.journal.C2EntryServiceJournal

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.