Skip to content

Commit

Permalink
we are using sinatra for website, here is the basic code
Browse files Browse the repository at this point in the history
  • Loading branch information
Kenny Stone committed Oct 2, 2011
1 parent 227bbcb commit 1d4d470
Show file tree
Hide file tree
Showing 12 changed files with 559 additions and 29 deletions.
5 changes: 5 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
source "http://rubygems.org"
gem "sinatra"
gem "redcarpet", "~>2.0.0b5"
gem "albino"
gem "nokogiri"
6 changes: 6 additions & 0 deletions config.ru
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
$LOAD_PATH << File.dirname(__FILE__)
$LOAD_PATH << File.dirname(__FILE__) + '/web'

require 'web/qfn_web'
run Sinatra::Application

56 changes: 27 additions & 29 deletions tutorial/sending-messages.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
---
layout: default
title: Sending Messages
---

Sending Messages
================

We are going to send some FIX messages in this tutorial:
In this tutorial, we will send some FIX messages:

{% highlight csharp %}
```c#

var order = new FIX44.NewOrderSingle(
new ClOrdID("1234"),
Expand All @@ -19,7 +14,7 @@ We are going to send some FIX messages in this tutorial:

Session.SendToTaget(order, sessionID);

{% endhighlight%}
```

First, we need to learn how to direct messages with Sessions.

Expand All @@ -31,52 +26,54 @@ All QuickFIX Sessions are identified by fields in the header of a
message, usually `SenderCompID`, `TargetCompID`, and `BeginString`.
These are specified in the config file.

```
SenderCompID=CONNAMARA
TargetCompID=CBOE
BeginString=FIX4.4
```

When sending a message, we must tell QuickFIX which Session to send it
to. There are a few patterns to gather the session.

We can grab the `SessionID` after a successful logon and cache it:

{% highlight csharp %}
```c#

private SessionID MySessionID { get; set; }
public void OnLogon(SessionID sessionID)
{
MySessionID = sessionID;
}

{% endhighlight %}
```

We can get the `SessionID` when responding to an incoming message:

{% highlight csharp %}
```c#

public void OnMessage(FIX42.ExecutionReport execution, SessionID sessionID)
{
ProcessExecution(execution, sessionID);
}

{% endhighlight %}
```

Or, we can construct a `SessionID` by matching the values from
our config file:

{% highlight csharp %}
```c#

var mySessionID = new SessionID("FIX4.4", "CONNAMARA", "CBOE");

{% endhighlight %}
```

Creating and Sending a Message
------------------------------

The preferred constructor to use includes the specific FIX version
and message type. We also pass in the required fields:

{% highlight csharp %}
```c#

import QuickFix;
import QuickFix.Fields;
Expand All @@ -88,22 +85,22 @@ and message type. We also pass in the required fields:
new TransactTime(DateTime.Now),
new OrdType(OrdType.LIMIT));

{% endhighlight %}
```

To set fields, use the message's field properties:
{% highlight csharp %}

```c#

order.Price = new Price(new decimal(22.4));
order.Account = new Account("18861112");

{% endhighlight %}
```

Putting it all together - creating the message, setting its required
fields, setting two additional fields, using `SessionID` from the
section above, we send the message on its way:

{% highlight csharp %}

```c#
var order = new QuickFix.FIX44.NewOrderSingle(
new ClOrdID("1234"),
new Symbol("AAPL"),
Expand All @@ -116,8 +113,9 @@ section above, we send the message on its way:

Session.SendToTarget(order, sessionID);

{% endhighlight %}
```

--

Alternative Constructors and Field Setters
------------------------------------------
Expand All @@ -127,37 +125,37 @@ are a few other ways to create messages and set fields.

Each message type has a default constructor:

{% highlight csharp %}
```c#

var order = new QuickFix.FIX44.NewOrderSingle();
order.ClOrdID = new ClOrdID("1234");
order.Symbol = new Symbol("AAPL");
order.Side = new Side(Side.BUY);

{% endhighlight %}
```

We have the QuickFIX C++ and QuickFIX/J style get/set methods available,
which are also type safe:

{% highlight csharp %}
```c#

order.Set(new TransactTime(DateTime.Now));
order.Set(new OrdType(OrdType.LIMIT));

{% endhighlight %}
```

For setting a field that isn't a property of a message, use `setField`:

{% highlight csharp %}
```c#

order.SetField(new Account("18861112"));

{% endhighlight %}
```

Here we create base `Message` class; it has no properties so `SetField`
must be used everywhere. *This style is not recommended*:

{% highlight csharp %}
```c#

var order = new QuickFix.Message();
order.Header.SetField(new MsgType("D"));
Expand All @@ -167,4 +165,4 @@ must be used everywhere. *This style is not recommended*:
order.SetField(new TransactTime(DateTime.Now));
order.SetField(new OrdType(OrdType.LIMIT));

{% endhighlight %}
```
32 changes: 32 additions & 0 deletions web/mdalbino.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
require 'redcarpet'
require 'albino'
require 'pry'

class MarkdownAlbinoEngine < Tilt::Template

class MarkdownAlbino < Redcarpet::Render::HTML
def block_code(code, language)
return "<pre class='highlight'>#{code}</pre>" if language.nil?
Albino.colorize(code, language)
end
end

self.default_mime_type = 'text/html'

def self.engine_initialized?
defined? ::MarkdownAlbino
end

def initialize_engine
end

def prepare
@engine = Redcarpet::Markdown.new(MarkdownAlbino, :fenced_code_blocks => true)
@output = nil
end

def evaluate(scope, locals, &block)
@output ||= @engine.render(data)
end
end

36 changes: 36 additions & 0 deletions web/public/css/blueprint/ie.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* -----------------------------------------------------------------------
Blueprint CSS Framework 1.0.1
http://blueprintcss.org
* Copyright (c) 2007-Present. See LICENSE for more info.
* See README for instructions on how to use Blueprint.
* For credits and origins, see AUTHORS.
* This is a compressed file. See the sources in the 'src' directory.
----------------------------------------------------------------------- */

/* ie.css */
body {text-align:center;}
.container {text-align:left;}
* html .column, * html .span-1, * html .span-2, * html .span-3, * html .span-4, * html .span-5, * html .span-6, * html .span-7, * html .span-8, * html .span-9, * html .span-10, * html .span-11, * html .span-12, * html .span-13, * html .span-14, * html .span-15, * html .span-16, * html .span-17, * html .span-18, * html .span-19, * html .span-20, * html .span-21, * html .span-22, * html .span-23, * html .span-24 {display:inline;overflow-x:hidden;}
* html legend {margin:0px -8px 16px 0;padding:0;}
sup {vertical-align:text-top;}
sub {vertical-align:text-bottom;}
html>body p code {*white-space:normal;}
hr {margin:-8px auto 11px;}
img {-ms-interpolation-mode:bicubic;}
.clearfix, .container {display:inline-block;}
* html .clearfix, * html .container {height:1%;}
fieldset {padding-top:0;}
legend {margin-top:-0.2em;margin-bottom:1em;margin-left:-0.5em;}
textarea {overflow:auto;}
label {vertical-align:middle;position:relative;top:-0.25em;}
input.text, input.title, textarea {background-color:#fff;border:1px solid #bbb;}
input.text:focus, input.title:focus {border-color:#666;}
input.text, input.title, textarea, select {margin:0.5em 0;}
input.checkbox, input.radio {position:relative;top:.25em;}
form.inline div, form.inline p {vertical-align:middle;}
form.inline input.checkbox, form.inline input.radio, form.inline input.button, form.inline button {margin:0.5em 0;}
button, input.button {position:relative;top:0.25em;}
29 changes: 29 additions & 0 deletions web/public/css/blueprint/print.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* -----------------------------------------------------------------------
Blueprint CSS Framework 1.0.1
http://blueprintcss.org
* Copyright (c) 2007-Present. See LICENSE for more info.
* See README for instructions on how to use Blueprint.
* For credits and origins, see AUTHORS.
* This is a compressed file. See the sources in the 'src' directory.
----------------------------------------------------------------------- */

/* print.css */
body {line-height:1.5;font-family:Verdana, "Helvetica Neue", Arial, Helvetica, sans-serif;color:#000;background:none;font-size:10pt;}
.container {background:none;}
hr {background:#ccc;color:#ccc;width:100%;height:2px;margin:2em 0;padding:0;border:none;}
hr.space {background:#fff;color:#fff;visibility:hidden;}
h1, h2, h3, h4, h5, h6 {font-family:Verdana, "Helvetica Neue", Arial, "Lucida Grande", sans-serif;}
code {font:.9em "Courier New", Monaco, Courier, monospace;}
a img {border:none;}
p img.top {margin-top:0;}
blockquote {margin:1.5em;padding:1em;font-style:italic;font-size:.9em;}
.small {font-size:.9em;}
.large {font-size:1.1em;}
.quiet {color:#999;}
.hide {display:none;}
a:link, a:visited {background:transparent;font-weight:700;text-decoration:underline;}
a:link:after, a:visited:after {content:" (" attr(href) ")";font-size:90%;}
Loading

0 comments on commit 1d4d470

Please sign in to comment.