Package com.collective2.signalEntry

Examples of com.collective2.signalEntry.C2ServiceException


                        return new IterableXMLEventReader(new String(buffer,0,readOff));

                    } catch (XMLStreamException e) {
                        String msg = "Unable to parse XML response from Collective2. Sent:"+request+" Received:"+new String(buffer,0,readOff+count);
                        logger.error(msg, e);
                        throw new C2ServiceException(msg, e, false); //do not send again
                    } catch (IOException e) {
                        String msg = "Unable to transmit request to Collective2. Attempted:"+request;
                        logger.error(msg, e);
                        throw new C2ServiceException(msg, e, true); //caller should try again later
                    } finally {
                        if (is!=null) {
                            try {
                                is.close();
                            } catch (IOException e) {
View Full Code Here


    @Override
    public void markRejected(Request request) {
        Request oldPending = list.remove(0);
        if (!request.equals(oldPending)) {
            throw new C2ServiceException("Expected to finish "+oldPending+" but instead was rejected "+request,false);
        }
    }
View Full Code Here

    @Override
    public void markSent(Request request) {
        Request oldPending = list.remove(0);
        if (!request.equals(oldPending)) {
            throw new C2ServiceException("Expected to finish "+oldPending+" but instead was sent "+request,false);
        }
    }
View Full Code Here

                                //when loading pending requests if any are time dependent must throw failure
                                //can not be done upon write because this is used as a journal and if its never used
                                //as a source of recovery then there is no failure.
                                if (null != request.get(Parameter.CancelsAtRelative)) {
                                    //cant try again or delay because the request is time dependent relative to submission time
                                    throw new C2ServiceException("Can not retry request which makes use of CancelsAtRelative feature", false);
                                }

                                requests.add(request);
                            }
                        }
                        bytePos++;
                    }
                    buf.clear();
                }
            } catch (IOException e) {
                throwError("Unable to initialize journal.", e, false);
            }

            final String localName = file.getName();
            File directory = file.getParentFile();
            if (directory==null) {
                throw new C2ServiceException("Log file must not been in the root of file system.",false);
            }
            File[] oldLogs = directory.listFiles(new FilenameFilter() {
                @Override
                public boolean accept(File dir, String name) {
                    return name.startsWith(localName+".");
View Full Code Here

    private void mark(Request request, ByteBuffer mark) {

        //remove from in memory list
        Request oldPending = requests.remove(0);
        if (!request.equals(oldPending)) {
            throw new C2ServiceException("Expected to finish "+oldPending+" but instead was sent "+request,false);
        }
        long pendingPosition = positions.remove(0);
        try {
            //mark oldest pending as sent with a timestamp of now
            randomChannel.write(mark, pendingPosition);
View Full Code Here

    }

    private void throwError(String message, IOException e, boolean tryAgain) {
        logger.error(message, e);
        throw new C2ServiceException(message, e, tryAgain);
    }
View Full Code Here

    public SystemManager(Portfolio portfolio, Integer systemId, String systemName, String password, BigDecimal commission, boolean marginAccount) {
        this.portfolio = portfolio;
        this.systemId = systemId;
        if (systemId>=(1<<BITS_FOR_SYSTEM_ID)) {
            throw new C2ServiceException("Too many systems defined, limit is "+(1<<BITS_FOR_SYSTEM_ID),false);
        }
        this.systemName = systemName;
        this.password = password;
        this.ocaCounter = new AtomicInteger();
        this.archive = new ArrayList<Order>();
View Full Code Here

            Order conditionalUponOrder = (conditionalUponId==null? null : archive.get(conditionalUponId>>BITS_FOR_SYSTEM_ID));

            int signalIdOnly = archive.size();

            if (signalIdOnly > (1<<(32-(1+BITS_FOR_SYSTEM_ID)))  ) {
                throw new C2ServiceException("Too many signals, limit is:"+(1<<(32-(1+BITS_FOR_SYSTEM_ID))),false);
            }

            int id = (signalIdOnly << BITS_FOR_SYSTEM_ID)+systemId;

            String symbol = (String)request.get(Parameter.Symbol);
            SignalAction action = null;
            Order order = null;

            //reverse works like a macro. it does not do the processing but rather builds two
            //signal requests to reverse the order and calls schedule signal on each.
            if (request.command()== Command.Reverse) {

                Integer existingQuantity = portfolio.position(symbol).quantity();

                Request requestToClose = buildBaseRequest(request,existingQuantity,symbol);

                if (existingQuantity>0)  {
                    //STC
                    requestToClose.put(Parameter.Action, SignalAction.STC);
                else {
                    //BTC
                    requestToClose.put(Parameter.Action, SignalAction.BTC);
                }

                //schedule the closing request
                int[] parentId = scheduleSignal(timeToExecute,requestToClose);

                //previous closed now reverse
                //only fields needed for building all-in-one dependent signals
                Request requestToOpen = buildBaseRequest(request,existingQuantity,symbol);

                if (existingQuantity>0)  {
                    //STO
                    requestToClose.put(Parameter.Action, SignalAction.STO);
                else {
                    //BTO
                    requestToClose.put(Parameter.Action, SignalAction.BTO);
                }

                //schedule the opening request
                return scheduleSignal(timeToExecute,requestToClose);
            } else {

                //use to compute quantity
                QuantityComputable quantityComputable = quantityFactory.computable(request,this);

                //GTC or Day
                Duration timeInForce = (Duration)request.get(Parameter.TimeInForce);

                //cancel at this fixed time
                long cancelAtMs = Long.MAX_VALUE;
                Number cancelAt = (Number)request.get(Parameter.CancelsAt);
                if (cancelAt != null) {
                    cancelAtMs = 1000l * cancelAt.intValue();
                }
                Number cancelAtRelative = (Number)request.get(Parameter.CancelsAtRelative);
                if (cancelAtRelative != null) {
                    cancelAtMs = timeToExecute + (1000l * cancelAtRelative.intValue());
                }

                assert(request.command() == Command.Signal);

                Instrument instrument = (Instrument)request.get(Parameter.Instrument);
                action = (SignalAction)request.get(Parameter.Action);

                Integer xReplace = (Integer)request.get(XReplace);
                if (xReplace!=null) {
                    if (xReplace<0 || (xReplace>>BITS_FOR_SYSTEM_ID)>=archive.size()) {
                        throw new C2ServiceException("Invalid signalId "+xReplace+" not found.",false);
                    }
                    Order oldOrder = archive.get(xReplace>>BITS_FOR_SYSTEM_ID);
                    oldOrder.cancelOrder(timeToExecute);//cancel old order to be replaced
                    conditionalUponOrder = oldOrder.conditionalUpon();
                    assert(conditionalUponOrder!=null);
View Full Code Here

        }
    }

    private void validateDataProvider(DataProvider dataProvider) {
        if (dataProvider.endingTime()<= dataProvider.startingTime()) {
            throw new C2ServiceException("DataProvider must not have same starting and ending times.",false);
        }
        if (dataProvider.endingTime()<dataProvider.startingTime()) {
            throw new C2ServiceException("DataProvider startingTime must be before endingTime.",false);
        }
        if (null != lastDataProvider) {
            if (lastDataProvider == dataProvider) { //checking for same instance not equivalence
                throw new C2ServiceException("DataProvider instances are held for simulation so instances must be immutable and never reused. ",false);
            }
            if (dataProvider.startingTime()<lastDataProvider.endingTime()) {
                throw new C2ServiceException("DataProviders must not overlap times.",false);
            }

        }
        lastDataProvider = dataProvider;
    }
View Full Code Here

        Integer condUpon = (Integer)request.get(Parameter.ConditionalUpon);
        if (condUpon != null) {
            return new QuantityComputableEntry(systemManager.lookupOrder(condUpon));
        }

        throw new C2ServiceException("Unable to determine how to calculate quantity. "+request,false);

    }
View Full Code Here

TOP

Related Classes of com.collective2.signalEntry.C2ServiceException

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.