com.paritytrading.foundation.ASCII Java Examples
The following examples show how to use
com.paritytrading.foundation.ASCII.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Open.java From parity-extras with Apache License 2.0 | 6 votes |
public Open(OrderEntry orderEntry, long instrument, long bidPrice, long bidSize, long askPrice, long askSize) { super(orderEntry); this.enterBuyOrder = new POE.EnterOrder(); ASCII.putLeft(this.enterBuyOrder.orderId, orderId.next()); this.enterBuyOrder.side = POE.BUY; this.enterBuyOrder.instrument = instrument; this.enterBuyOrder.quantity = bidSize; this.enterBuyOrder.price = bidPrice; this.enterSellOrder = new POE.EnterOrder(); ASCII.putLeft(this.enterSellOrder.orderId, orderId.next()); this.enterSellOrder.side = POE.SELL; this.enterSellOrder.instrument = instrument; this.enterSellOrder.quantity = askSize; this.enterSellOrder.price = askPrice; }
Example #2
Source File: ITCHSessionTest.java From juncture with Apache License 2.0 | 6 votes |
@Test public void loginRequest() throws Exception { ASCII.putLeft(loginRequest.loginName, "foo"); ASCII.putLeft(loginRequest.password, "bar"); loginRequest.marketDataUnsubscribe = ITCH.TRUE; ASCII.putLongRight(loginRequest.reserved, 0); client.login(loginRequest); while (serverEvents.collect().size() != 1) server.receive(); assertEquals(asList(new LoginRequest( "foo ", "bar ", ITCH.TRUE, 0)), serverEvents.collect()); }
Example #3
Source File: TerminalClient.java From parity with Apache License 2.0 | 6 votes |
static TerminalClient open(InetSocketAddress address, String username, String password, Instruments instruments) throws IOException { Events events = new Events(); OrderEntry orderEntry = OrderEntry.open(address, events); SoupBinTCP.LoginRequest loginRequest = new SoupBinTCP.LoginRequest(); ASCII.putLeft(loginRequest.username, username); ASCII.putLeft(loginRequest.password, password); ASCII.putRight(loginRequest.requestedSession, ""); ASCII.putLongRight(loginRequest.requestedSequenceNumber, 0); orderEntry.getTransport().login(loginRequest); return new TerminalClient(events, orderEntry, instruments); }
Example #4
Source File: CboeFXBookFormatter.java From juncture with Apache License 2.0 | 6 votes |
public void reset() { ASCII.putLongRight(lengthOfMessage, 0); ASCII.putLongRight(numberOfItems, 0); lengthOfMessagePosition = -1; numberOfCurrencyPairsPosition = -1; numberOfPricesPosition = -1; numberOfOrdersPosition = -1; currencyPairs = 0; prices = 0; orders = 0; ASCII.putLeft(currencyPair, " "); buyOrSellIndicator = ' '; ASCII.putLeft(price, " "); }
Example #5
Source File: EnterCommand.java From parity with Apache License 2.0 | 6 votes |
@Override public void execute(TerminalClient client, Scanner arguments) throws IOException { try { double quantity = arguments.nextDouble(); long instrument = ASCII.packLong(arguments.next()); double price = arguments.nextDouble(); if (arguments.hasNext()) throw new IllegalArgumentException(); Instrument config = client.getInstruments().get(instrument); if (config == null) throw new IllegalArgumentException(); execute(client, Math.round(quantity * config.getSizeFactor()), instrument, Math.round(price * config.getPriceFactor())); } catch (NoSuchElementException e) { throw new IllegalArgumentException(); } }
Example #6
Source File: Session.java From parity with Apache License 2.0 | 6 votes |
@Override public void logon(FIXConnection connection, FIXMessage message) throws IOException { FIXValue username = message.valueOf(Username); FIXValue password = message.valueOf(Password); if (requiredTagMissing(message, username, "Username(553)")) return; if (requiredTagMissing(message, password, "Password(554)")) return; fix.updateCompID(message); ASCII.putLeft(loginRequest.username, username.asString()); ASCII.putLeft(loginRequest.password, password.asString()); ASCII.putRight(loginRequest.requestedSession, ""); ASCII.putLongRight(loginRequest.requestedSequenceNumber, 0); orderEntry.login(loginRequest); }
Example #7
Source File: Session.java From parity with Apache License 2.0 | 6 votes |
@Override public void orderExecuted(POE.OrderExecuted message) throws IOException { long orderEntryId = ASCII.getLong(message.orderId); Order order = orders.findByOrderEntryID(orderEntryId); if (order == null) return; Instrument config = instruments.get(order.getSymbol()); double lastQty = message.quantity / config.getSizeFactor(); double lastPx = message.price / config.getPriceFactor(); order.orderExecuted(lastQty, lastPx); sendOrderExecuted(order, lastQty, lastPx, config); if (order.getLeavesQty() == 0) { orders.removeByOrderEntryID(orderEntryId); if (order.isInPendingStatus()) sendOrderCancelReject(order); } }
Example #8
Source File: Session.java From parity with Apache License 2.0 | 6 votes |
@Override public void orderCanceled(POE.OrderCanceled message) throws IOException { long orderEntryId = ASCII.getLong(message.orderId); Order order = orders.findByOrderEntryID(orderEntryId); if (order == null) return; Instrument config = instruments.get(order.getSymbol()); order.orderCanceled(message.canceledQuantity / config.getSizeFactor()); sendOrderCanceled(order, config); if (order.getLeavesQty() == 0) orders.removeByOrderEntryID(orderEntryId); }
Example #9
Source File: Session.java From parity with Apache License 2.0 | 6 votes |
@Override public void orderRejected(POE.OrderRejected message) throws IOException { long orderEntryId = ASCII.getLong(message.orderId); Order order = orders.findByOrderEntryID(orderEntryId); if (order == null) return; switch (message.reason) { case POE.ORDER_REJECT_REASON_UNKNOWN_INSTRUMENT: sendOrderRejected(order, OrdRejReasonValues.UnknownSymbol); break; case POE.ORDER_REJECT_REASON_INVALID_PRICE: sendOrderRejected(order, OrdRejReasonValues.Other); break; case POE.ORDER_REJECT_REASON_INVALID_QUANTITY: sendOrderRejected(order, OrdRejReasonValues.IncorrectQuantity); break; default: sendOrderRejected(order, OrdRejReasonValues.Other); break; } orders.removeByOrderEntryID(orderEntryId); }
Example #10
Source File: ITCHSessionTest.java From juncture with Apache License 2.0 | 5 votes |
@Test public void marketDataSubscription() throws Exception { ASCII.putLeft(marketDataSubscribeRequest.currencyPair, "FOO/BAR"); ASCII.putLeft(marketDataUnsubscribeRequest.currencyPair, "FOO/BAR"); client.request(marketDataSubscribeRequest); client.request(marketDataUnsubscribeRequest); while (serverEvents.collect().size() != 2) server.receive(); assertEquals(asList(new MarketDataSubscribeRequest("FOO/BAR"), new MarketDataUnsubscribeRequest("FOO/BAR")), serverEvents.collect()); }
Example #11
Source File: ITCHSessionTest.java From juncture with Apache License 2.0 | 5 votes |
@Test public void loginRejected() throws Exception { ASCII.putLeft(loginRejected.reason, "foo"); server.reject(loginRejected); while (clientEvents.collect().size() != 1) client.receive(); assertEquals(asList(new LoginRejected("foo ")), clientEvents.collect()); }
Example #12
Source File: ITCHSessionTest.java From juncture with Apache License 2.0 | 5 votes |
@Test public void sequencedData() throws Exception { ASCII.putLeft(sequencedData.time, "093000250"); byte[] payload = new byte[] { 'f', 'o', 'o' }; server.send(sequencedData, ByteBuffer.wrap(payload)); while (clientEvents.collect().size() != 1) client.receive(); assertEquals(asList(new SequencedData("093000250", payload)), clientEvents.collect()); }
Example #13
Source File: ITCHSessionTest.java From juncture with Apache License 2.0 | 5 votes |
@Test public void fullBuffer() throws Exception { ASCII.putLeft(sequencedData.time, "093000250"); byte[] payload = repeat((byte)'A', RX_BUFFER_CAPACITY - 11); server.send(sequencedData, ByteBuffer.wrap(payload)); while (clientEvents.collect().size() != 1) client.receive(); assertEquals(asList(new SequencedData("093000250", payload)), clientEvents.collect()); }
Example #14
Source File: ITCHSessionTest.java From juncture with Apache License 2.0 | 5 votes |
@Test(expected=ITCHException.class) public void packetLengthExceedsBufferCapacity() throws Exception { ASCII.putLeft(sequencedData.time, "093000250"); byte[] payload = repeat((byte)'A', RX_BUFFER_CAPACITY - 10); server.send(sequencedData, ByteBuffer.wrap(payload)); while (true) client.receive(); }
Example #15
Source File: ITCHSessionTest.java From juncture with Apache License 2.0 | 5 votes |
@Test public void errorNotification() throws Exception { ASCII.putLeft(errorNotification.errorExplanation, "foo"); server.notifyError(errorNotification); while (clientEvents.collect().size() != 1) client.receive(); assertEquals(asList(new ErrorNotification( "foo " + " ")), clientEvents.collect()); }
Example #16
Source File: ITCHSessionTest.java From juncture with Apache License 2.0 | 5 votes |
@Test public void instrumentDirectory() throws Exception { ASCII.putLongRight(instrumentDirectory.numberOfCurrencyPairs, 3); ASCII.putLeft(instrumentDirectory.currencyPair[0], "FOO/BAR"); ASCII.putLeft(instrumentDirectory.currencyPair[1], "BAR/BAZ"); ASCII.putLeft(instrumentDirectory.currencyPair[2], "BAZ/FOO"); server.instrumentDirectory(instrumentDirectory); while (clientEvents.collect().size() != 1) client.receive(); assertEquals(asList(new InstrumentDirectory(asList("FOO/BAR", "BAR/BAZ", "BAZ/FOO"))), clientEvents.collect()); }
Example #17
Source File: Instrument.java From parity with Apache License 2.0 | 5 votes |
private Instrument(String asString, int priceFractionDigits, int sizeFractionDigits) { this.asString = asString; this.asLong = ASCII.packLong(asString); this.priceFractionDigits = priceFractionDigits; this.sizeFractionDigits = sizeFractionDigits; this.priceFactor = POWERS_OF_TEN[priceFractionDigits]; this.sizeFactor = POWERS_OF_TEN[sizeFractionDigits]; setPriceFormat(1, priceFractionDigits); setSizeFormat(1, sizeFractionDigits); }
Example #18
Source File: ITCHSessionTest.java From juncture with Apache License 2.0 | 5 votes |
@Test public void marketSnapshotRequest() throws Exception { ASCII.putLeft(marketSnapshotRequest.currencyPair, "FOO/BAR"); client.request(marketSnapshotRequest); while (serverEvents.collect().size() != 1) server.receive(); assertEquals(asList(new MarketSnapshotRequest("FOO/BAR")), serverEvents.collect()); }
Example #19
Source File: ITCHSessionTest.java From juncture with Apache License 2.0 | 5 votes |
@Test public void tickerSubscription() throws Exception { ASCII.putLeft(tickerSubscribeRequest.currencyPair, "FOO/BAR"); ASCII.putLeft(tickerUnsubscribeRequest.currencyPair, "FOO/BAR"); client.request(tickerSubscribeRequest); client.request(tickerUnsubscribeRequest); while (serverEvents.collect().size() != 2) server.receive(); assertEquals(asList(new TickerSubscribeRequest("FOO/BAR"), new TickerUnsubscribeRequest("FOO/BAR")), serverEvents.collect()); }
Example #20
Source File: ITCHServerEvents.java From juncture with Apache License 2.0 | 5 votes |
@Override public void loginRequest(ITCHServer session, ITCH.LoginRequest packet) { String loginName = ASCII.get(packet.loginName); String password = ASCII.get(packet.password); byte marketDataUnsubscribe = packet.marketDataUnsubscribe; long reserved = ASCII.getLong(packet.reserved); events.add(new LoginRequest(loginName, password, marketDataUnsubscribe, reserved)); }
Example #21
Source File: ITCH50StatListener.java From exchange-core with Apache License 2.0 | 5 votes |
@Override public void stockDirectory(ITCH50.StockDirectory itchMsg) { // log.debug("{}", itchMsg); symbolDescr.put(itchMsg.stockLocate, new StockDescr(ASCII.unpackLong(itchMsg.stock), itchMsg.etpFlag, itchMsg.etpLeverageFactor)); // CoreSymbolSpecification symbolSpecification = CoreSymbolSpecification.builder() // .symbolId(itchMsg.stockLocate) // .type(SymbolType.FUTURES_CONTRACT) // allow margin trade TODO calculate based on ETP // .baseCurrency(itchMsg.stockLocate + 10_000) // .quoteCurrency(TestConstants.CURRENECY_USD) // .takerFee(3) // .makerFee(1) // .quoteScaleK(2) // .baseScaleK(itchMsg.roundLotSize) // .marginBuy(itchMsg.etpLeverageFactor + 100L) // TODO price // .marginSell(itchMsg.etpLeverageFactor + 100L) // TODO price // .build(); // // final CompletableFuture<OrderCommand> response = api.submitBinaryCommandAsync(new BatchAddSymbolsCommand(symbolSpecification), itchMsg.stockLocate, Function.identity()); // // response.thenAccept(cmdRes -> { // if (cmdRes.resultCode != CommandResultCode.SUCCESS) { // log.error("symbol add failed: {}", response); // } // if (ASCII.unpackLong(itchMsg.stock).trim().equals("INTL")) { // log.debug("{} {} ls={} mc={} etpF={} etpL={} rlo={}", // ASCII.unpackLong(itchMsg.stock), // itchMsg.stockLocate, // itchMsg.roundLotSize, // (char) itchMsg.marketCategory, // (char) itchMsg.etpFlag, // itchMsg.etpLeverageFactor, // (char) itchMsg.roundLotsOnly); // } // }); }
Example #22
Source File: OrderBooks.java From parity with Apache License 2.0 | 5 votes |
OrderBooks(List<String> instruments, MarketData marketData, MarketReporting marketReporting) { this.books = new Long2ObjectArrayMap<>(); this.orders = new Long2ObjectOpenHashMap<>(); EventHandler handler = new EventHandler(); for (String instrument : instruments) books.put(ASCII.packLong(instrument), new OrderBook(handler)); this.marketData = marketData; this.marketReporting = marketReporting; this.nextOrderNumber = 1; this.nextMatchNumber = 1; }
Example #23
Source File: Event.java From parity with Apache License 2.0 | 5 votes |
public OrderAccepted(POE.OrderAccepted message) { this.timestamp = message.timestamp; this.orderId = ASCII.get(message.orderId); this.side = message.side; this.instrument = message.instrument; this.quantity = message.quantity; this.price = message.price; this.orderNumber = message.orderNumber; }
Example #24
Source File: Event.java From parity with Apache License 2.0 | 5 votes |
public OrderExecuted(POE.OrderExecuted message) { this.timestamp = message.timestamp; this.orderId = ASCII.get(message.orderId); this.quantity = message.quantity; this.price = message.price; this.liquidityFlag = message.liquidityFlag; this.matchNumber = message.matchNumber; }
Example #25
Source File: EnterCommand.java From parity with Apache License 2.0 | 5 votes |
private void execute(TerminalClient client, long quantity, long instrument, long price) throws IOException { String orderId = client.getOrderIdGenerator().next(); ASCII.putLeft(message.orderId, orderId); message.quantity = quantity; message.instrument = instrument; message.price = price; client.getOrderEntry().send(message); printf("\nOrder ID\n----------------\n%s\n\n", orderId); }
Example #26
Source File: Session.java From parity with Apache License 2.0 | 5 votes |
@Override public void orderAccepted(POE.OrderAccepted message) throws IOException { long orderEntryId = ASCII.getLong(message.orderId); Order order = orders.findByOrderEntryID(orderEntryId); if (order == null) return; order.orderAccepted(message.orderNumber); sendOrderAccepted(order); }
Example #27
Source File: CboeFXBookEvents.java From juncture with Apache License 2.0 | 5 votes |
@Override public void ticker(CboeFXBook.Ticker message) { byte aggressorBuyOrSellIndicator = message.aggressorBuyOrSellIndicator; String currencyPair = ASCII.get(message.currencyPair); long price = ASCII.getFixed(message.price, PRICE_DECIMALS); long transactionDate = ASCII.getLong(message.transactionDate); long transactionTime = ASCII.getLong(message.transactionTime); events.add(new Ticker(aggressorBuyOrSellIndicator, currencyPair, price, transactionDate, transactionTime)); }
Example #28
Source File: Simulator.java From parity-extras with Apache License 2.0 | 5 votes |
private static MarketData marketData(Config config) throws IOException { NetworkInterface multicastInterface = Configs.getNetworkInterface(config, "market-data.multicast-interface"); InetAddress multicastGroup = Configs.getInetAddress(config, "market-data.multicast-group"); int multicastPort = Configs.getPort(config, "market-data.multicast-port"); InetAddress requestAddress = Configs.getInetAddress(config, "market-data.request-address"); int requestPort = Configs.getPort(config, "market-data.request-port"); String instrument = config.getString("instrument"); return MarketData.open(multicastInterface, new InetSocketAddress(multicastGroup, multicastPort), new InetSocketAddress(requestAddress, requestPort), ASCII.packLong(instrument)); }
Example #29
Source File: Simulator.java From parity-extras with Apache License 2.0 | 5 votes |
private static Open open(Config config) throws IOException { double bidPrice = config.getDouble("open.bid.price"); long bidSize = config.getLong("open.bid.size"); double askPrice = config.getDouble("open.ask.price"); long askSize = config.getLong("open.ask.size"); String instrument = config.getString("instrument"); return new Open(orderEntry(config), ASCII.packLong(instrument), (long)(bidPrice * PRICE_FACTOR), bidSize, (long)(askPrice * PRICE_FACTOR), askSize); }
Example #30
Source File: Model.java From parity-extras with Apache License 2.0 | 5 votes |
private void enter(byte side, double price) throws IOException { ASCII.putLeft(enterOrder.orderId, orderId.next()); enterOrder.side = side; enterOrder.price = (long)Math.round(price * 100.0) * 100; getOrderEntry().send(enterOrder); }