Java Code Examples for com.paritytrading.foundation.ASCII#putLeft()

The following examples show how to use com.paritytrading.foundation.ASCII#putLeft() . 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: Session.java    From parity with Apache License 2.0 6 votes vote down vote up
@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 2
Source File: TerminalClient.java    From parity with Apache License 2.0 6 votes vote down vote up
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 3
Source File: CboeFXBookFormatter.java    From juncture with Apache License 2.0 6 votes vote down vote up
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 4
Source File: ITCHSessionTest.java    From juncture with Apache License 2.0 6 votes vote down vote up
@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 5
Source File: Open.java    From parity-extras with Apache License 2.0 6 votes vote down vote up
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 6
Source File: ITCHSessionTest.java    From juncture with Apache License 2.0 5 votes vote down vote up
@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 7
Source File: EnterCommand.java    From parity with Apache License 2.0 5 votes vote down vote up
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 8
Source File: ITCHSessionTest.java    From juncture with Apache License 2.0 5 votes vote down vote up
@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 9
Source File: ITCHSessionTest.java    From juncture with Apache License 2.0 5 votes vote down vote up
@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 10
Source File: ITCHSessionTest.java    From juncture with Apache License 2.0 5 votes vote down vote up
@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 11
Source File: ITCHSessionTest.java    From juncture with Apache License 2.0 5 votes vote down vote up
@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 12
Source File: ITCHSessionTest.java    From juncture with Apache License 2.0 5 votes vote down vote up
@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 13
Source File: ITCHSessionTest.java    From juncture with Apache License 2.0 5 votes vote down vote up
@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 vote down vote up
@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 15
Source File: ITCHSessionTest.java    From juncture with Apache License 2.0 5 votes vote down vote up
@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 16
Source File: OrderEntry.java    From parity-extras with Apache License 2.0 5 votes vote down vote up
public void login(String username, String password) throws IOException {
    SoupBinTCP.LoginRequest request = new SoupBinTCP.LoginRequest();

    ASCII.putLeft(request.username, username);
    ASCII.putLeft(request.password, password);
    ASCII.putRight(request.requestedSession, "");
    ASCII.putLongRight(request.requestedSequenceNumber, 0);

    transport.login(request);
}
 
Example 17
Source File: Model.java    From parity-extras with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 18
Source File: CancelCommand.java    From parity with Apache License 2.0 4 votes vote down vote up
private void execute(TerminalClient client, String orderId) throws IOException {
    ASCII.putLeft(message.orderId, orderId);
    message.quantity = 0;

    client.getOrderEntry().send(message);
}
 
Example 19
Source File: Model.java    From parity-extras with Apache License 2.0 4 votes vote down vote up
private void cancel(String orderId) throws IOException {
    ASCII.putLeft(cancelOrder.orderId, orderId);
    cancelOrder.quantity = 0;

    getOrderEntry().send(cancelOrder);
}