Package com.collective2.signalEntry

Examples of com.collective2.signalEntry.C2ServiceException


            case 'Q'://Q use most recent quote at session open which is dataProvider.openingPrice() - its the best we have
                return currentPriceData.openingPrice(symbol).add(relativeLimit.value());

            case 'O'://O use day open price, use open price if market was open else use end price..
                if (null == dayOpenData) {
                    throw new C2ServiceException("Relative price based on open price failure. No open price data.",false);
                }
                return dayOpenData.openingPrice(symbol).add(relativeLimit.value());

            case 'T'://T fill price of the open buy/sell  portfolio.position(symbol).openPrice();
                Position pos = portfolio.position(symbol);
                if (null == pos) {
                    throw new C2ServiceException("No position found for symbol "+symbol,false);
                }
                if (pos.quantity()==0) {
                    return BigDecimal.ZERO;
                }

                if (null == pos.openPrice()) {
                    throw new C2ServiceException("No open price found for position "+symbol,false);
                }
                return pos.openPrice().add(relativeLimit.value());

            default:
                return relativeLimit.value();
View Full Code Here


        //If you attempt to add a new order and make it conditional on an order
        // that has already been filled or canceled, this will not be permitted.
        // The parent order must still be pending.
        if (conditionalUpon!=null && !conditionalUpon.isPending()) {
            throw new C2ServiceException("Can not be conditional on an order that is not pending.",false);
        }
    }
View Full Code Here

    }

    public boolean isPending() {
        if (processed) {
            if (tradeQuantity()<=0) {
                throw new C2ServiceException("bad quantity for processed "+tradeQuantity(),false);
            }
            if (tradePrice().compareTo(BigDecimal.ZERO)<=0) {
                throw new C2ServiceException("bad price for processed "+tradePrice(),false);
            }
            return false;
        }

        //not filled, cancelled or expired
View Full Code Here

    public IterableXMLEventReader getXMLEventReader() {
        try {
            return futureEventReader.get();
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            throw new C2ServiceException(e,false);
        } catch (ExecutionException e) {
            throw new C2ServiceException(e,false);
        }
    }
View Full Code Here

        while (reader.hasNext()) {
            XMLEvent event = null;
            try {
                event = reader.nextEvent();
            } catch (XMLStreamException e) {
                throw new C2ServiceException("Unable to read xml",e,false);
            }
            if (event != null) {
                if (event.isStartElement()) {

                    name = event.asStartElement().getName().getLocalPart();
View Full Code Here

    public static Request parseURL(String url) {

        String[] split = url.split("\\?|&");
        if (split.length<=0 || !split[0].endsWith("signal.mpl")) {
            throw new C2ServiceException("Can not parse url base "+url,false);
        }
        //pull out the command from index 1
        Command command = null;
        if (split[1].startsWith("cmd=")) {
            command = (Command)Parameter.SignalEntryCommand.parse(split[1].substring(4));
         } else {
            throw new C2ServiceException("Can not parse out command "+url,false);
        }


        //all the fields start at 2
        Request request = new Request(command);
View Full Code Here

                        urlFileQuery.append(encode(activeMap.get(p)));
                    } catch (UnsupportedEncodingException e) {
                        // should never happen
                        String msg = "UTF-8 is not supported on this platform?";
                        logger.error(msg, e);
                        throw new C2ServiceException(msg, e, false);
                    }
                } else {
                    urlFileQuery.append(activeMap.get(p));
                }
            }
        }

        try {
            return new URL(urlProtocol, urlHost, urlPort, urlFileQuery.toString(), null);
        } catch (MalformedURLException e) {
            throw new C2ServiceException(e, false);
        }
    }
View Full Code Here

            //if executor has gotten down to this one then everything else is done
            executor.submit(placeHolder).get(seconds,TimeUnit.SECONDS);
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
        } catch (ExecutionException e) {
            throw new C2ServiceException("awaitPending",e.getCause(),false);
        }
    }
View Full Code Here

            //if executor has gotten down to this one then everything else is done
            executor.submit(placeHolder).get();
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
        } catch (ExecutionException e) {
            throw new C2ServiceException("awaitPending",e.getCause(),false);
        }
    }
View Full Code Here

    private Callable<IterableXMLEventReader> callable(final Request request, final Request journalInstance) {

        return new Callable<IterableXMLEventReader>() {

            C2ServiceException optionalStackTrace = showDeepStacks ?
                                                    new C2ServiceException("Originating Call Stack",false) :
                                                    null;

            @Override
            public IterableXMLEventReader call() throws Exception {

                try {
                    if (!journalInstance.isApprovalKnown() && journalInstance.command().approvalRequired()) {
                        //must get approval for these!
                        assert(journal.pending().next().equals(journalInstance));
                        approvalRequestable.waitForApproval(journal.pending());
                    }

                    if (!journalInstance.isApproved()) {
                       journal.markRejected(journalInstance);
                       return new IterableXMLEventReader("<rejected>not approved</rejected>");
                    };

                    //was validated upon construction but assert it was not changed in the meantime
                    assert(request.validate());
                    //all down stream requests must see the same halting exception until its reset.
                    if (haltingException != null ) {
                        throw haltingException;
                    }

                    boolean  tryAgain = false;
                    do {
                        try {
                            //exceptions thrown here are because
                            // * the network is down and we should try later
                            // * the response was not readable - must stop all

                            //transmit to the adapter
                            IterableXMLEventReader eventReader = adapter.transmit(request);
                            synchronized (ResponseManager.this) {
                                //exceptions thrown here are because
                                // * database was unable to change flag on request to sent - must stop all
                                journal.markSent(journalInstance);
                            }
                            return eventReader;

                        } catch (C2ServiceException e) {
                            tryAgain = e.tryAgain();//if true wait for configured delay and try again.
                            if (tryAgain) {

                                if (null != request.get(Parameter.CancelsAtRelative)) {
                                    //cant try again or delay because the request is time dependent relative to submission time
                                    haltingException = new C2ServiceException("Can not retry request which makes use of CancelsAtRelative feature",false);
                                    throw haltingException;
                                }

                                try {
                                    Thread.sleep(networkDownRetryDelay);
                                } catch (InterruptedException ie) {
                                    throw e; //this is not a halting exception
                                }
                            } else {
                                haltingException = e;
                                throw haltingException;
                            }
                        } catch (Exception ex) {
                            haltingException = new C2ServiceException(request.toString(),ex,false);
                            throw haltingException;
                        }
                    } while (tryAgain);
                    throw new C2ServiceException("Unable to execute.",true);

                } catch (RuntimeException e) {
                    if (optionalStackTrace!=null) {
                        optionalStackTrace.overrideCause(e);
                        throw optionalStackTrace;
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.