Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ tmp
bin
.exe
dist/
certs/
config/*.local.cfg
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@ make build
This will try to connect to a FIX acceptor on `localhost:5001` and expose the UI on `localhost:8080`.
You can modify the quickfix config for this found in config/tradeclient.cfg to suit your own needs.

## Locate

The `Locate` tab sends `QuoteRequest (35=R)` and `OrderStatusRequest (35=H)` for Alpaca's Locate FIX 4.2 profile; Locates are created from the Orders tab (Buy, Market or Limit, TIF IOC or FOK). Every inbound application message, including `Quote`, `QuoteAcknowledgement`, `BusinessMessageReject` and `ExecutionReport`, is listed on the Locate tab.

```sh
./bin/traderui -file-store -clordid-prefix "$(date +%s)-" config/locate.cfg
```

- `config/locate.cfg` sets mutual TLS and the Locate CompIDs; fill in the certificate paths and server name.
- `-file-store` keeps sequence numbers in `FileStorePath` so the session resumes across restarts. Do not set `ResetOnLogon` against the Locate acceptor.
- `-clordid-prefix` keeps generated ClOrdIDs unique across restarts; the acceptor rejects a repeated ClOrdID.

## Licensing
This software is available under the QuickFIX Software License. Please see the [LICENSE](https://github.com/quickfixgo/traderui/blob/main/LICENSE) for the terms specified by the QuickFIX Software License.

Expand Down
175 changes: 175 additions & 0 deletions assets/js/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ $(function() {
setInterval(function() {
App.orders.fetch({reset: true});
App.executions.fetch({reset: true});
App.messages.fetch({reset: true});

}, 1000);

Expand All @@ -39,6 +40,11 @@ var App = new( Backbone.View.extend({
session_ids: options.session_ids
});

this.locateForm = new App.Models.LocateForm({
session_ids: options.session_ids
});

this.messages = new App.Collections.Messages(options.messages);
this.orders = new App.Collections.Orders(options.orders);
this.executions = new App.Collections.Executions(options.executions);
this.router = new App.Router();
Expand All @@ -55,6 +61,7 @@ var App = new( Backbone.View.extend({
$("#nav-order").addClass("active");
$("#nav-execution").removeClass("active");
$("#nav-secdef").removeClass("active");
$("#nav-locate").removeClass("active");
},

showExecutions: function() {
Expand All @@ -66,6 +73,7 @@ var App = new( Backbone.View.extend({
$("#nav-order").removeClass("active");
$("#nav-execution").addClass("active");
$("#nav-secdef").removeClass("active");
$("#nav-locate").removeClass("active");
},

showSecurityDefinitions: function() {
Expand All @@ -74,6 +82,19 @@ var App = new( Backbone.View.extend({
$("#nav-order").removeClass("active");
$("#nav-execution").removeClass("active");
$("#nav-secdef").addClass("active");
$("#nav-locate").removeClass("active");
},

showLocate: function() {
var locateView = new App.Views.Locate({model: this.locateForm});
var messagesView = new App.Views.MessagesView({collection: this.messages});

$("#app").html(locateView.render().el);
$("#app").append(messagesView.render().el);
$("#nav-order").removeClass("active");
$("#nav-execution").removeClass("active");
$("#nav-secdef").removeClass("active");
$("#nav-locate").addClass("active");
},

showOrderDetails: function(id) {
Expand Down Expand Up @@ -108,6 +129,7 @@ App.Router = Backbone.Router.extend({
"orders": "index",
"executions": "executions",
"secdefs": "secdefs",
"locate": "locate",
"orders/:id": "orderDetails",
"executions/:id": "executionDetails",
},
Expand All @@ -124,6 +146,10 @@ App.Router = Backbone.Router.extend({
App.showSecurityDefinitions();
},

locate: function() {
App.showLocate();
},

orderDetails: function(id) {
App.showOrderDetails(id)
},
Expand All @@ -145,6 +171,15 @@ App.Models.SecurityDefinitionRequest = Backbone.Model.extend({
urlRoot: "securitydefinitionrequest"
});

App.Models.QuoteRequest = Backbone.Model.extend({
urlRoot: "/quoterequests"
});

App.Models.OrderStatusRequest = Backbone.Model.extend({
urlRoot: "/orderstatusrequests"
});

App.Models.LocateForm = Backbone.Model.extend({});
App.Models.OrderTicket = Backbone.Model.extend({});
App.Models.SecurityDefinitionForm = Backbone.Model.extend({});

Expand All @@ -153,6 +188,11 @@ App.Collections.Orders = Backbone.Collection.extend({
comparator: 'id'
});

App.Collections.Messages = Backbone.Collection.extend({
url: '/messages',
comparator: 'id'
});

App.Collections.Executions = Backbone.Collection.extend({
url: '/executions',
comparator: 'id'
Expand Down Expand Up @@ -461,6 +501,129 @@ App.Views.Executions = Backbone.View.extend({
}
});

App.Views.MessageRowView = Backbone.View.extend({
tagName: 'tr',
template: _.template(`
<td><%= id %></td>
<td><%= App.prettyMsgType(msg_type) %></td>
<td><%= session_id %></td>
<td><code><%- raw %></code></td>
`),

render: function() {
this.$el.html(this.template(this.model.attributes));
return this;
}
});

App.Views.MessagesView = Backbone.View.extend({
initialize: function() {
this.listenTo(this.collection, 'reset', this.addAll);
},

render: function() {
this.$el.html(`
<h4>Inbound messages</h4>
<table class='table table-striped' id='messages'>
<thead>
<tr>
<th>#</th>
<th>Type</th>
<th>Session</th>
<th>Message</th>
</tr>
</thead>
<tbody>
</tbody>
</table>`);

this.addAll();

return this;
},

addAll: function() {
this.$("tbody").empty();
this.collection.forEach(this.addOne, this);
return this;
},

addOne: function(message) {
var row = new App.Views.MessageRowView({model: message});
this.$("tbody").append(row.render().el);
}
});

App.Views.Locate = Backbone.View.extend({
template: _.template(`
<h4>Quote request</h4>
<form class='form-inline' id='quote-request'>
<div class='form-group'>
<label for='quote_symbol'>Symbol</label>
<input type='text' class='form-control' name='symbol' id='quote_symbol' placeholder='Symbol' required>
</div>
<div class='form-group'>
<label for='quote_req_id'>QuoteReqID</label>
<input type='text' class='form-control' name='quote_req_id' id='quote_req_id' placeholder='generated if empty'>
</div>
<div class='form-group'>
<label for='quote_session'>Session</label>
<select class='form-control' name='session' id='quote_session'>
<% _.each(session_ids, function(i){ %><option><%= i %></option><% }); %>
</select>
</div>
<button type='submit' class='btn btn-default'>Send</button>
</form>

<h4>Order status request</h4>
<form class='form-inline' id='status-request'>
<div class='form-group'>
<label for='status_order_id'>OrderID</label>
<input type='text' class='form-control' name='order_id' id='status_order_id' placeholder='OrderID (37) from the create response' size='40' required>
</div>
<div class='form-group'>
<label for='status_session'>Session</label>
<select class='form-control' name='session' id='status_session'>
<% _.each(session_ids, function(i){ %><option><%= i %></option><% }); %>
</select>
</div>
<button type='submit' class='btn btn-default'>Send</button>
</form>
<p class='help-block'>Create a Locate from the Orders tab: Buy, Market or Limit, TIF IOC (partial allowed) or FOK (all-or-none).</p>
`),

events: {
"submit #quote-request": "sendQuote",
"submit #status-request": "sendStatus"
},

sendQuote: function(e) {
e.preventDefault();
var req = new App.Models.QuoteRequest();
req.set({
session_id: this.$('#quote_session').val(),
symbol: this.$('#quote_symbol').val(),
quote_req_id: this.$('#quote_req_id').val()
});
req.save();
},

sendStatus: function(e) {
e.preventDefault();
var req = new App.Models.OrderStatusRequest();
req.set({
session_id: this.$('#status_session').val(),
order_id: this.$('#status_order_id').val()
});
req.save();
},

render: function() {
this.$el.html(this.template(this.model.attributes));
return this;
}
});

App.Views.OrdersView = Backbone.View.extend({
initialize: function() {
this.listenTo(this.collection, 'reset', this.addAll);
Expand Down Expand Up @@ -670,6 +833,7 @@ App.Views.OrderTicket = Backbone.View.extend({
<select class='form-control' name='tif'>
<option value='0'>Day</option>
<option value='3'>IOC</option>
<option value='4'>FOK</option>
<option value='2'>OPG</option>
<option value='1'>GTC</option>
<option value='5'>GTX</option>
Expand Down Expand Up @@ -818,6 +982,17 @@ App.prettySide = function(sideEnum) {
return sideEnum;
};

App.prettyMsgType = function(msgType) {
switch (msgType) {
case "8": return "ExecutionReport (8)";
case "S": return "Quote (S)";
case "b": return "QuoteAcknowledgement (b)";
case "j": return "BusinessMessageReject (j)";
};

return msgType;
};

App.prettyOrdType = function(ordTypeEnum) {
switch (ordTypeEnum) {
case "1": return "Market";
Expand Down
4 changes: 3 additions & 1 deletion basic/clordid_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
)

type ClOrdIDGenerator struct {
// Prefix is prepended to every ClOrdID so IDs stay unique across restarts.
Prefix string
clOrdIDLock sync.Mutex
clOrdID int
}
Expand All @@ -15,5 +17,5 @@ func (f *ClOrdIDGenerator) Next() string {
defer f.clOrdIDLock.Unlock()

f.clOrdID++
return strconv.Itoa(f.clOrdID)
return f.Prefix + strconv.Itoa(f.clOrdID)
}
16 changes: 15 additions & 1 deletion basic/fix_application.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package basic

import (
"log"
"strings"

"github.com/quickfixgo/enum"
"github.com/quickfixgo/field"
Expand Down Expand Up @@ -41,16 +42,29 @@ func (a *FIXApplication) ToApp(msg *quickfix.Message, sessionID quickfix.Session
return
}

// FromApp listens for just execution reports
// FromApp records every inbound application message, then handles execution
// reports. Locate replies (Quote, QuoteAcknowledgement, BusinessMessageReject)
// are only recorded.
func (a *FIXApplication) FromApp(msg *quickfix.Message, sessionID quickfix.SessionID) quickfix.MessageRejectError {
msgType, err := msg.MsgType()
if err != nil {
return err
}

a.Lock()
a.SaveMessage(&oms.Message{
Session: sessionID.String(),
MsgType: msgType,
Raw: strings.ReplaceAll(msg.String(), "\x01", "|"),
})
a.Unlock()

switch enum.MsgType(msgType) {
case enum.MsgType_EXECUTION_REPORT:
return a.onExecutionReport(msg, sessionID)
// 35=b is QuoteAcknowledgement in FIX 4.2; the enum names it after the later MassQuoteAcknowledgement.
case enum.MsgType_QUOTE, enum.MsgType_MASS_QUOTE_ACKNOWLEDGEMENT, enum.MsgType_BUSINESS_MESSAGE_REJECT:
return nil
}

return quickfix.UnsupportedMessageType()
Expand Down
37 changes: 37 additions & 0 deletions basic/fix_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (

"github.com/quickfixgo/enum"
"github.com/quickfixgo/field"
"github.com/quickfixgo/tag"
"github.com/quickfixgo/traderui/locate"
"github.com/quickfixgo/traderui/oms"
"github.com/quickfixgo/traderui/secmaster"

Expand Down Expand Up @@ -61,9 +63,44 @@ func (FIXFactory) SecurityDefinitionRequest(req secmaster.SecurityDefinitionRequ
return
}

// QuoteRequest builds a FIX 4.2 QuoteRequest (35=R) for one symbol.
func (FIXFactory) QuoteRequest(req locate.QuoteRequest) (quickfix.Messagable, error) {
if req.SessionID.BeginString != quickfix.BeginStringFIX42 {
return nil, errors.New("Unhandled BeginString")
}

msg := quickfix.NewMessage()
msg.Header.SetString(tag.MsgType, string(enum.MsgType_QUOTE_REQUEST))
msg.Body.SetString(tag.QuoteReqID, req.QuoteReqID)

group := quickfix.NewRepeatingGroup(tag.NoRelatedSym, quickfix.GroupTemplate{quickfix.GroupElement(tag.Symbol)})
group.Add().SetString(tag.Symbol, req.Symbol)
msg.Body.SetGroup(group)

return msg, nil
}

// OrderStatusRequest builds a FIX 4.2 OrderStatusRequest (35=H) that carries
// only OrderID, which is all the Locate profile requires.
func (FIXFactory) OrderStatusRequest(req locate.OrderStatusRequest) (quickfix.Messagable, error) {
if req.SessionID.BeginString != quickfix.BeginStringFIX42 {
return nil, errors.New("Unhandled BeginString")
}

msg := quickfix.NewMessage()
msg.Header.SetString(tag.MsgType, string(enum.MsgType_ORDER_STATUS_REQUEST))
msg.Body.SetString(tag.OrderID, req.OrderID)

return msg, nil
}

func populateOrder(genMessage quickfix.Messagable, ord oms.Order) (quickfix.Messagable, error) {
msg := genMessage.ToMessage()

if ord.TimeInForce != "" {
msg.Body.Set(field.NewTimeInForce(ord.TimeInForce))
}

switch ord.OrdType {
case enum.OrdType_LIMIT, enum.OrdType_STOP_LIMIT:
msg.Body.Set(field.NewPrice(ord.PriceDecimal, 2))
Expand Down
Loading