File: receiving_messages.html

package info (click to toggle)
quickfix 1.15.1%2Bdfsg-4
  • links: PTS
  • area: main
  • in suites: bookworm, bullseye
  • size: 42,080 kB
  • sloc: cpp: 631,686; python: 129,549; ruby: 106,716; xml: 43,737; ansic: 7,668; java: 1,826; cs: 816; makefile: 544; sh: 462; sql: 313
file content (127 lines) | stat: -rw-r--r-- 3,844 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">

<html>
<head>
  <link href="doxygen.css" rel="stylesheet" type="text/css">

  <title>Receiving Messages</title>
</head>

<body>
  <div class='header'>
    <div class='headertitle'>
      Receiving Messages
    </div>
  </div>

  <div class='contents'>
    <p>Most of the messages you will be interested in looking at
    will be arriving in your overloaded <b>fromApp</b> function of
    your application. All messages have a header and a trailer. If
    you want to see those fields, you must call <b>getHeader()</b>
    or <b>getTrailer()</b> on the message to access them.</p>

    <hr/>
    <h2>Type Safe Messages And Fields</h2>

    <p>QuickFIX has a class for all messages defined in the
    standard spec.</p>
    <pre class='fragment'>
void fromApp( const FIX::Message&amp; message, const FIX::SessionID&amp; sessionID )
  throw( FIX::FieldNotFound&amp;, FIX::IncorrectDataFormat&amp;, FIX::IncorrectTagValue&amp;, FIX::UnsupportedMessageType&amp; )
{
  crack(message, sessionID);
}

void onMessage( const FIX42::NewOrderSingle&amp; message, const FIX::SessionID&amp; )
{
  FIX::ClOrdID clOrdID;
  message.get(clOrdID);

  FIX::ClearingAccount clearingAccount;
  message.get(clearingAccount);
}

void onMessage( const FIX41::NewOrderSingle&amp; message, const FIX::SessionID&amp; )
{
  FIX::ClOrdID clOrdID;
  message.get(clOrdID);

  // compile time error!! field not defined in FIX41
  FIX::ClearingAccount clearingAccount;
  message.get(clearingAccount);
}

void onMessage( const FIX42::OrderCancelRequest&amp; message, const FIX::SessionID&amp; )
{
  FIX::ClOrdID clOrdID;
  message.get(clOrdID);

  // compile time error!! field not defined for OrderCancelRequest
  FIX::Price price;
  message.get(price);
}
</pre>

    <p>In order to use this you must use the <b>MessageCracker</b>
    as a mixin to your application. This will provide you with the
    <b>crack</b> function and allow you to overload specific
    message functions. Any function you do not overload will by
    default throw an <b>UnsupportedMessageType</b> exception<br>
    <br>
    Define your application like this:</p>
    <pre class='fragment'>
#include "quickfix/Application.h"
#include "quickfix/MessageCracker.h"

class MyApplication
: public FIX::Application,
  public FIX::MessageCracker
</pre>

    <br/><hr/>
    <h2>Type Safe Fields Only</h2>

    <p>Use the <b>getField</b> method to get any field from any
    message.</p>See this code in <a href=
    "python/receiving_messages_2.html">PYTHON</a>, <a href=
    "ruby/receiving_messages_2.html">RUBY</a>
    <pre class='fragment'>
void fromApp( const FIX::Message&amp; message, const FIX::SessionID&amp; sessionID )
  throw( FIX::FieldNotFound&amp;, FIX::IncorrectDataFormat&amp;, FIX::IncorrectTagValue&amp;, FIX::UnsupportedMessageType&amp; )
{
  // retrieve value into field class
  FIX::Price price;
  message.getField(price);

  // another field...
  FIX::ClOrdID clOrdID;
  message.getField(clOrdID);
}
</pre>

    <br/><hr/>
    <h2>No Type Safety</h2>

    <p>Create your own fields using tag numbers.</p>See this code
    in <a href="python/receiving_messages_1.html">PYTHON</a>,
    <a href="ruby/receiving_messages_1.html">RUBY</a>
    <pre class='fragment'>
void fromApp( const FIX::Message&amp; message, const FIX::SessionID&amp; sessionID )
  throw( FIX::FieldNotFound&amp;, FIX::IncorrectDataFormat&amp;, FIX::IncorrectTagValue&amp;, FIX::UnsupportedMessageType&amp; )
{
  // retreive value into string with integer field ID
  std::string value;
  value = message.getField(44);

  // retrieve value into a field base with integer field ID
  FIX::FieldBase field(44, "");
  message.getField(field);

  // retreive value with an enumeration, a little better
  message.getField(FIX::FIELD::Price);
}
</pre>
  </div>
</body>
</html>