com.paritytrading.philadelphia.FIXMessage Java Examples

The following examples show how to use com.paritytrading.philadelphia.FIXMessage. 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: CoinbaseTest.java    From philadelphia-extras with Apache License 2.0 6 votes vote down vote up
@Test
public void sign() {
    FIXMessage message = new FIXMessage(64, 64);

    message.addField(SenderCompID).setString("foo");
    message.addField(TargetCompID).setString("Coinbase");
    message.addField(MsgSeqNum).setInt(1);
    message.addField(SendingTime).setString("20160118-09:30:00.000");
    message.addField(EncryptMethod).setInt(EncryptMethodValues.None);
    message.addField(HeartBtInt).setInt(30);
    message.addField(Password).setString("bar");

    String secret = "baz";

    Coinbase.sign(message, secret);

    assertNotNull(message.valueOf(RawData));
}
 
Example #2
Source File: Message.java    From philadelphia with Apache License 2.0 6 votes vote down vote up
static Message get(FIXMessage message) {
    List<Field> fields = new ArrayList<>();

    String msgType = null;

    for (int i = 0; i < message.getFieldCount(); i++) {
        int    tag   = message.tagAt(i);
        String value = message.valueAt(i).asString();

        if (tag == MsgType)
            msgType = value;
        else
            fields.add(new Field(tag, value));
    }

    if (msgType == null)
        throw new IllegalArgumentException("MsgType(35) missing");

    return new Message(msgType, fields);
}
 
Example #3
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 #4
Source File: Initiator.java    From philadelphia with Apache License 2.0 5 votes vote down vote up
void sendAndReceive(FIXMessage message, FIXValue clOrdId, int orders) throws IOException {
    for (long sentAtNanoTime = System.nanoTime(); receiveCount < orders; connection.receive()) {
        if (System.nanoTime() >= sentAtNanoTime) {
            clOrdId.setInt(sentAtNanoTime);

            connection.update(message);
            connection.send(message);

            sentAtNanoTime += intervalNanos;
        }
    }
}
 
Example #5
Source File: Session.java    From parity with Apache License 2.0 5 votes vote down vote up
private boolean requiredTagMissing(FIXMessage message, FIXValue value, String tag) throws IOException {
    if (value != null)
        return false;

    fix.sendReject(message.getMsgSeqNum(), SessionRejectReasonValues.RequiredTagMissing, tag + " missing");

    return true;
}
 
Example #6
Source File: Coinbase.java    From philadelphia-extras with Apache License 2.0 5 votes vote down vote up
private static void appendField(FIXMessage message, int tag, String fieldName, StringBuilder s) {
    FIXValue value = message.valueOf(tag);
    if (value == null)
        throw new IllegalStateException(fieldName + " not found");

    value.asString(s);
}
 
Example #7
Source File: Messages.java    From philadelphia with Apache License 2.0 4 votes vote down vote up
@Override
public void logout(FIXConnection connection, FIXMessage message) {
    add(message);
}
 
Example #8
Source File: Messages.java    From philadelphia with Apache License 2.0 4 votes vote down vote up
private void add(FIXMessage message) {
    add(Message.get(message));
}
 
Example #9
Source File: Messages.java    From philadelphia with Apache License 2.0 4 votes vote down vote up
@Override
public void logon(FIXConnection connection, FIXMessage message) {
    add(message);
}
 
Example #10
Source File: Session.java    From parity with Apache License 2.0 4 votes vote down vote up
private void orderCancel(FIXMessage message, char msgType) throws IOException {
    FIXValue clOrdIdValue     = null;
    FIXValue origClOrdIdValue = null;
    FIXValue orderQtyValue    = null;

    for (int i = 0; i < message.getFieldCount(); i++) {
        switch (message.tagAt(i)) {
        case ClOrdID:
            clOrdIdValue = message.valueAt(i);
            break;
        case OrigClOrdID:
            origClOrdIdValue = message.valueAt(i);
            break;
        case OrderQty:
            orderQtyValue = message.valueAt(i);
            break;
        }
    }

    if (requiredTagMissing(message, origClOrdIdValue, "OrigClOrdID(41)"))
        return;

    if (requiredTagMissing(message, clOrdIdValue, "ClOrdID(11)"))
        return;

    if (msgType == OrderCancelReplaceRequest) {
        if (requiredTagMissing(message, orderQtyValue, "OrderQty(38)"))
            return;
    }

    char cxlRejResponseTo = CxlRejResponseToValues.OrderCancelRequest;

    if (msgType == OrderCancelReplaceRequest)
        cxlRejResponseTo = CxlRejResponseToValues.OrderCancel;

    String origClOrdId = origClOrdIdValue.asString();
    String clOrdId     = clOrdIdValue.asString();

    Order order = orders.findByClOrdID(origClOrdId);
    if (order == null) {
        sendOrderCancelReject(clOrdId, origClOrdId, cxlRejResponseTo);

        return;
    } else if (order.isInPendingStatus()) {
        sendOrderCancelReject(order, clOrdId, cxlRejResponseTo,
                CxlRejReasonValues.OrderAlreadyInPendingStatus);

        return;
    }

    if (orders.findByClOrdID(clOrdId) != null) {
        sendOrderCancelReject(order, clOrdId, cxlRejResponseTo,
                CxlRejReasonValues.DuplicateClOrdID);
        return;
    }

    double orderQty = 0.0;

    if (msgType == OrderCancelReplaceRequest) {
        try {
            orderQty = orderQtyValue.asFloat();
        } catch (FIXValueFormatException e) {
            incorrectDataFormatForValue(message, "Expected 'float' in OrderQty(38)");
            return;
        }
    }

    double qty = Math.max(orderQty - order.getCumQty(), 0);

    Instrument config = instruments.get(order.getSymbol());

    order.setNextClOrdID(clOrdId);
    order.setCxlRejResponseTo(cxlRejResponseTo);

    ASCII.putLongLeft(cancelOrder.orderId, order.getOrderEntryID());
    cancelOrder.quantity = (long)(qty * config.getSizeFactor());

    send(cancelOrder);

    char execType  = ExecTypeValues.PendingCancel;
    char ordStatus = OrdStatusValues.PendingCancel;

    if (msgType == OrderCancelReplaceRequest) {
        execType  = ExecTypeValues.PendingReplace;
        ordStatus = OrdStatusValues.PendingReplace;
    }

    sendOrderCancelAcknowledgement(order, execType, ordStatus);
}
 
Example #11
Source File: Messages.java    From philadelphia with Apache License 2.0 4 votes vote down vote up
@Override
public void reject(FIXConnection connection, FIXMessage message) {
    add(message);
}
 
Example #12
Source File: Session.java    From parity with Apache License 2.0 4 votes vote down vote up
@Override
public void logout(FIXConnection connection, FIXMessage message) throws IOException {
    fix.sendLogout();

    orderEntry.logout();
}
 
Example #13
Source File: Session.java    From parity with Apache License 2.0 4 votes vote down vote up
@Override
public void reject(FIXConnection connection, FIXMessage message) {
}
 
Example #14
Source File: Session.java    From parity with Apache License 2.0 4 votes vote down vote up
private void invalidMsgType(FIXMessage message) throws IOException {
    fix.sendReject(message.getMsgSeqNum(), SessionRejectReasonValues.InvalidMsgType,
            "Invalid MsgType(35)");
}
 
Example #15
Source File: Message.java    From philadelphia with Apache License 2.0 4 votes vote down vote up
void put(FIXMessage message) {
    for (Field field : fields)
        message.addField(field.getTag()).setString(field.getValue());
}
 
Example #16
Source File: Session.java    From parity with Apache License 2.0 4 votes vote down vote up
private void valueIsIncorrect(FIXMessage message, String text) throws IOException {
    fix.sendReject(message.getMsgSeqNum(), SessionRejectReasonValues.ValueIsIncorrect, text);
}
 
Example #17
Source File: Session.java    From parity with Apache License 2.0 4 votes vote down vote up
private void incorrectDataFormatForValue(FIXMessage message, String text) throws IOException {
    fix.sendReject(message.getMsgSeqNum(), SessionRejectReasonValues.IncorrectDataFormatForValue, text);
}