root/isimud/exchanges/FIX/common/types.hpp

/* [<][>][^][v][top][bottom][index][help] */

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. to_stream

   1 #ifndef libjmmcg_isimud_exchanges_FIX_common_types_hpp
   2 #define libjmmcg_isimud_exchanges_FIX_common_types_hpp
   3 
   4 /******************************************************************************
   5 ** $Header: svn+ssh://jmmcg@svn.code.sf.net/p/libjmmcg/code/trunk/libjmmcg/isimud/exchanges/FIX/common/types.hpp 2332 2018-09-26 04:00:27Z jmmcg $
   6 **
   7 ** Copyright (c) 2015 by J.M.McGuiness, isimud@hussar.me.uk
   8 **
   9 ** This library is free software; you can redistribute it and/or
  10 ** modify it under the terms of the GNU Lesser General Public
  11 ** License as published by the Free Software Foundation; either
  12 ** version 2.1 of the License, or (at your option) any later version.
  13 **
  14 ** This library is distributed in the hope that it will be useful,
  15 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  16 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17 ** Lesser General Public License for more details.
  18 **
  19 ** You should have received a copy of the GNU Lesser General Public
  20 ** License along with this library; if not, write to the Free Software
  21 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  22 */
  23 
  24 #include "core/enum_as_char_array.hpp"
  25 
  26 #include <array>
  27 #include <iterator>
  28 #include <iostream>
  29 #include <limits>
  30 
  31 namespace isimud { namespace exchanges { namespace FIX { namespace common {
  32 
  33 using element_type=char;
  34 enum : std::size_t {
  35         max_size_of_fix_message=sizeof(__uint128_t)*32  ///< The largest size of FIX message that the library can accommodate including all components, e.g. type, size & checksum fields. Note that this must be in units of 512 bits, due to the use of AVX2 operations, if available.
  36 };
  37 /// An underlying data-buffer into which the fix message may be created.
  38 /**
  39         Ideally this should be suitably aligned, e.g. 64-it aligned. For optimal performance it would actually be the underlying memory of the network card or IP stack.
  40 */
  41 using underlying_fix_data_buffer=std::array<element_type, max_size_of_fix_message>;
  42 using pointer=element_type *;
  43 using const_pointer=element_type const *;
  44 /// The type of the internal data-buffer.
  45 /**
  46         FIX messages are basically an array of chars. so we need a type that is compatible with this char-array that is received from a socket.
  47 */
  48 using data_block_t=pointer;
  49 
  50 using MsgTypes_t=std::uint16_t;
  51 
  52 using SecurityID_t=std::array<char, 20>;
  53 using ClientOrderID_t=std::array<char, 20>;
  54 using Reason_t=std::array<char, 20>;
  55 using Password_t=std::array<char, 25>;
  56 using UserName_t=std::array<char, 25>;
  57 using Price_t=std::array<char, 25>;
  58 
  59 constexpr const char Separator='\001';
  60 constexpr const unsigned short CheckSumLength=3;
  61 
  62 /// The checksum type used by FIX.
  63 using checksum_t=std::array<char, CheckSumLength+1>;
  64 
  65 using field_str_range_t=std::pair<const_pointer, const_pointer>;
  66 
  67 constexpr const std::uint64_t implied_decimal_places=100000000;
  68 
  69 enum class MsgTypes : MsgTypes_t {
  70         Heartbeat=jmmcg::enum_tags::mpl::to_tag<'0'>::value,
  71         TestRequest=jmmcg::enum_tags::mpl::to_tag<'1'>::value,
  72         ResendRequest=jmmcg::enum_tags::mpl::to_tag<'2'>::value,
  73         Reject=jmmcg::enum_tags::mpl::to_tag<'3'>::value,
  74         SequenceReset=jmmcg::enum_tags::mpl::to_tag<'4'>::value,
  75         Logout=jmmcg::enum_tags::mpl::to_tag<'5'>::value,
  76         IOI=jmmcg::enum_tags::mpl::to_tag<'6'>::value,
  77         Advertisement=jmmcg::enum_tags::mpl::to_tag<'7'>::value,
  78         ExecutionReport=jmmcg::enum_tags::mpl::to_tag<'8'>::value,
  79         OrderCancelReject=jmmcg::enum_tags::mpl::to_tag<'9'>::value,
  80         LogonRequest=jmmcg::enum_tags::mpl::to_tag<'A'>::value,
  81         DerivativeSecurityList=jmmcg::enum_tags::mpl::to_tag<'A', 'A'>::value,
  82         NewOrderMultileg=jmmcg::enum_tags::mpl::to_tag<'A', 'B'>::value,
  83         MultilegOrderCancelReplace=jmmcg::enum_tags::mpl::to_tag<'A', 'C'>::value,
  84         TradeCaptureReportRequest=jmmcg::enum_tags::mpl::to_tag<'A', 'D'>::value,
  85         TradeCaptureReport=jmmcg::enum_tags::mpl::to_tag<'A', 'E'>::value,
  86         OrderMassStatusRequest=jmmcg::enum_tags::mpl::to_tag<'A', 'F'>::value,
  87         QuoteRequestReject=jmmcg::enum_tags::mpl::to_tag<'A', 'G'>::value,
  88         RFQRequest=jmmcg::enum_tags::mpl::to_tag<'A', 'H'>::value,
  89         QuoteStatusReport=jmmcg::enum_tags::mpl::to_tag<'A', 'I'>::value,
  90         QuoteResponse=jmmcg::enum_tags::mpl::to_tag<'A', 'J'>::value,
  91         Confirmation=jmmcg::enum_tags::mpl::to_tag<'A', 'K'>::value,
  92         PositionMaintenanceRequest=jmmcg::enum_tags::mpl::to_tag<'A', 'L'>::value,
  93         PositionMaintenanceReport=jmmcg::enum_tags::mpl::to_tag<'A', 'M'>::value,
  94         RequestForPositions=jmmcg::enum_tags::mpl::to_tag<'A', 'N'>::value,
  95         RequestForPositionsAck=jmmcg::enum_tags::mpl::to_tag<'A', 'O'>::value,
  96         PositionReport=jmmcg::enum_tags::mpl::to_tag<'A', 'P'>::value,
  97         TradeCaptureReportRequestAck=jmmcg::enum_tags::mpl::to_tag<'A', 'Q'>::value,
  98         TradeCaptureReportAck=jmmcg::enum_tags::mpl::to_tag<'A', 'R'>::value,
  99         AllocationReport=jmmcg::enum_tags::mpl::to_tag<'A', 'S'>::value,
 100         AllocationReportAck=jmmcg::enum_tags::mpl::to_tag<'A', 'T'>::value,
 101         ConfirmationAck=jmmcg::enum_tags::mpl::to_tag<'A', 'U'>::value,
 102         SettlementInstructionRequest=jmmcg::enum_tags::mpl::to_tag<'A', 'V'>::value,
 103         AssignmentReport=jmmcg::enum_tags::mpl::to_tag<'A', 'W'>::value,
 104         CollateralRequest=jmmcg::enum_tags::mpl::to_tag<'A', 'X'>::value,
 105         CollateralAssignment=jmmcg::enum_tags::mpl::to_tag<'A', 'Y'>::value,
 106         CollateralResponse=jmmcg::enum_tags::mpl::to_tag<'A', 'Z'>::value,
 107         News=jmmcg::enum_tags::mpl::to_tag<'B'>::value,
 108         CollateralReport=jmmcg::enum_tags::mpl::to_tag<'B', 'A'>::value,
 109         CollateralInquiry=jmmcg::enum_tags::mpl::to_tag<'B', 'B'>::value,
 110         NetworkCounterpartySystemStatusRequest=jmmcg::enum_tags::mpl::to_tag<'B', 'C'>::value,
 111         NetworkCounterpartySystemStatusResponse=jmmcg::enum_tags::mpl::to_tag<'B', 'D'>::value,
 112         UserRequest=jmmcg::enum_tags::mpl::to_tag<'B', 'E'>::value,
 113         UserResponse=jmmcg::enum_tags::mpl::to_tag<'B', 'F'>::value,
 114         CollateralInquiryAck=jmmcg::enum_tags::mpl::to_tag<'B', 'G'>::value,
 115         ConfirmationRequest=jmmcg::enum_tags::mpl::to_tag<'B', 'H'>::value,
 116         TradingSessionListRequest=jmmcg::enum_tags::mpl::to_tag<'B', 'I'>::value,
 117         TradingSessionList=jmmcg::enum_tags::mpl::to_tag<'B', 'J'>::value,
 118         SecurityListUpdateReport=jmmcg::enum_tags::mpl::to_tag<'B', 'K'>::value,
 119         AdjustedPositionReport=jmmcg::enum_tags::mpl::to_tag<'B', 'L'>::value,
 120         AllocationInstructionAlert=jmmcg::enum_tags::mpl::to_tag<'B', 'M'>::value,
 121         ExecutionAcknowledgement=jmmcg::enum_tags::mpl::to_tag<'B', 'N'>::value,
 122         ContraryIntentionReport=jmmcg::enum_tags::mpl::to_tag<'B', 'O'>::value,
 123         SecurityDefinitionUpdateReport=jmmcg::enum_tags::mpl::to_tag<'B', 'P'>::value,
 124         SettlementObligationReport=jmmcg::enum_tags::mpl::to_tag<'B', 'Q'>::value,
 125         DerivativeSecurityListUpdateReport=jmmcg::enum_tags::mpl::to_tag<'B', 'R'>::value,
 126         TradingSessionListUpdateReport=jmmcg::enum_tags::mpl::to_tag<'B', 'S'>::value,
 127         MarketDefinitionRequest=jmmcg::enum_tags::mpl::to_tag<'B', 'T'>::value,
 128         MarketDefinition=jmmcg::enum_tags::mpl::to_tag<'B', 'U'>::value,
 129         MarketDefinitionUpdateReport=jmmcg::enum_tags::mpl::to_tag<'B', 'V'>::value,
 130         ApplicationMessageRequest=jmmcg::enum_tags::mpl::to_tag<'B', 'W'>::value,
 131         ApplicationMessageRequestAck=jmmcg::enum_tags::mpl::to_tag<'B', 'X'>::value,
 132         ApplicationMessageReport=jmmcg::enum_tags::mpl::to_tag<'B', 'Y'>::value,
 133         OrderMassActionReport=jmmcg::enum_tags::mpl::to_tag<'B', 'Z'>::value,
 134         Email=jmmcg::enum_tags::mpl::to_tag<'C'>::value,
 135         OrderMassActionRequest=jmmcg::enum_tags::mpl::to_tag<'C', 'A'>::value,
 136         UserNotification=jmmcg::enum_tags::mpl::to_tag<'C', 'B'>::value,
 137         StreamAssignmentRequest=jmmcg::enum_tags::mpl::to_tag<'C', 'C'>::value,
 138         StreamAssignmentReport=jmmcg::enum_tags::mpl::to_tag<'C', 'D'>::value,
 139         StreamAssignmentReportACK=jmmcg::enum_tags::mpl::to_tag<'C', 'E'>::value,
 140         NewOrderSingle=jmmcg::enum_tags::mpl::to_tag<'D'>::value,
 141         NewOrderList=jmmcg::enum_tags::mpl::to_tag<'E'>::value,
 142         OrderCancelRequest=jmmcg::enum_tags::mpl::to_tag<'F'>::value,
 143         OrderCancelReplaceRequest=jmmcg::enum_tags::mpl::to_tag<'G'>::value,
 144         OrderStatusRequest=jmmcg::enum_tags::mpl::to_tag<'H'>::value,
 145         AllocationInstruction=jmmcg::enum_tags::mpl::to_tag<'J'>::value,
 146         ListCancelRequest=jmmcg::enum_tags::mpl::to_tag<'K'>::value,
 147         ListExecute=jmmcg::enum_tags::mpl::to_tag<'L'>::value,
 148         ListStatusRequest=jmmcg::enum_tags::mpl::to_tag<'M'>::value,
 149         ListStatus=jmmcg::enum_tags::mpl::to_tag<'N'>::value,
 150         AllocationInstructionAck=jmmcg::enum_tags::mpl::to_tag<'P'>::value,
 151         DontKnowTrade=jmmcg::enum_tags::mpl::to_tag<'Q'>::value,
 152         QuoteRequest=jmmcg::enum_tags::mpl::to_tag<'R'>::value,
 153         Quote=jmmcg::enum_tags::mpl::to_tag<'S'>::value,
 154         SettlementInstructions=jmmcg::enum_tags::mpl::to_tag<'T'>::value,
 155         MarketDataRequest=jmmcg::enum_tags::mpl::to_tag<'V'>::value,
 156         MarketDataSnapshotFullRefresh=jmmcg::enum_tags::mpl::to_tag<'W'>::value,
 157         MarketDataIncrementalRefresh=jmmcg::enum_tags::mpl::to_tag<'X'>::value,
 158         MarketDataRequestReject=jmmcg::enum_tags::mpl::to_tag<'Y'>::value,
 159         QuoteCancel=jmmcg::enum_tags::mpl::to_tag<'Z'>::value,
 160         QuoteStatusRequest=jmmcg::enum_tags::mpl::to_tag<'a'>::value,
 161         MassQuoteAcknowledgement=jmmcg::enum_tags::mpl::to_tag<'b'>::value,
 162         SecurityDefinitionRequest=jmmcg::enum_tags::mpl::to_tag<'c'>::value,
 163         SecurityDefinition=jmmcg::enum_tags::mpl::to_tag<'d'>::value,
 164         SecurityStatusRequest=jmmcg::enum_tags::mpl::to_tag<'e'>::value,
 165         SecurityStatus=jmmcg::enum_tags::mpl::to_tag<'f'>::value,
 166         TradingSessionStatusRequest=jmmcg::enum_tags::mpl::to_tag<'g'>::value,
 167         TradingSessionStatus=jmmcg::enum_tags::mpl::to_tag<'h'>::value,
 168         MassQuote=jmmcg::enum_tags::mpl::to_tag<'i'>::value,
 169         BusinessMessageReject=jmmcg::enum_tags::mpl::to_tag<'j'>::value,
 170         BidRequest=jmmcg::enum_tags::mpl::to_tag<'k'>::value,
 171         BidResponse=jmmcg::enum_tags::mpl::to_tag<'l'>::value,
 172         ListStrikePrice=jmmcg::enum_tags::mpl::to_tag<'m'>::value,
 173         XMLnonFIX=jmmcg::enum_tags::mpl::to_tag<'n'>::value,
 174         RegistrationInstructions=jmmcg::enum_tags::mpl::to_tag<'o'>::value,
 175         RegistrationInstructionsResponse=jmmcg::enum_tags::mpl::to_tag<'p'>::value,
 176         OrderMassCancelRequest=jmmcg::enum_tags::mpl::to_tag<'q'>::value,
 177         OrderMassCancelReport=jmmcg::enum_tags::mpl::to_tag<'r'>::value,
 178         NewOrderCross=jmmcg::enum_tags::mpl::to_tag<'s'>::value,
 179         CrossOrderCancelReplaceRequest=jmmcg::enum_tags::mpl::to_tag<'t'>::value,
 180         CrossOrderCancelRequest=jmmcg::enum_tags::mpl::to_tag<'u'>::value,
 181         SecurityTypeRequest=jmmcg::enum_tags::mpl::to_tag<'v'>::value,
 182         SecurityTypes=jmmcg::enum_tags::mpl::to_tag<'w'>::value,
 183         SecurityListRequest=jmmcg::enum_tags::mpl::to_tag<'x'>::value,
 184         SecurityList=jmmcg::enum_tags::mpl::to_tag<'y'>::value,
 185         DerivativeSecurityListRequest=jmmcg::enum_tags::mpl::to_tag<'z'>::value,
 186         MatchAll=std::numeric_limits<MsgTypes_t>::max()-1,      ///< For the meta-state machine to allow a catch-all rule to reject anything unhandled.
 187         Exit=std::numeric_limits<MsgTypes_t>::max()     ///< For the meta-state machine: the exit state to exit the msm.
 188 };
 189 
 190 constexpr inline MsgTypes
 191 operator|(const MsgTypes lhs, const MsgTypes rhs) noexcept(true) {
 192         return static_cast<MsgTypes>(
 193                 static_cast<std::underlying_type<MsgTypes>::type>(lhs)|static_cast<std::underlying_type<MsgTypes>::type>(rhs)
 194         );
 195 }
 196 
 197 template<MsgTypes Msg>
 198 inline std::ostream &
 199 to_stream(std::ostream &os) noexcept(false) {
 200         const constexpr auto &msg_str=jmmcg::enum_tags::mpl::to_array<MsgTypes, Msg>::value;
 201         os<<msg_str;
 202         return os;
 203 }
 204 
 205 inline std::ostream &
 206 operator<<(std::ostream &os, MsgTypes msg) noexcept(false) {
 207         union convertor {
 208                 MsgTypes msg_;
 209                 char str_[sizeof(MsgTypes)];
 210         };
 211         convertor conv;
 212         conv.msg_=msg;
 213         os<<conv.str_;
 214         return os;
 215 }
 216 
 217 /// When creating a FIX message it will always have this many chars. All this variable-sized stuff is a crock.
 218 #define JMMCG_FIX_MSG_BODY_LENGTH_NULL "000"
 219 
 220 #define JMMCG_FIX_MSG_BODY_LENGTH_TAG "\0019="
 221 #define JMMCG_FIX_MSG_TYPE_TAG "\00135="
 222 
 223 enum class FieldsFast : std::uint64_t {
 224         BodyLength=jmmcg::enum_tags::mpl::to_tag<'\001', '9', '='>::value,
 225         ClOrdID=jmmcg::enum_tags::mpl::to_tag<'\001', '1', '1', '='>::value,
 226         Currency=jmmcg::enum_tags::mpl::to_tag<'\001', '1', '5', '='>::value,
 227         SecurityIDSource=jmmcg::enum_tags::mpl::to_tag<'\001', '2', '2', '='>::value,
 228         MsgSeqNum=jmmcg::enum_tags::mpl::to_tag<'\001', '3', '4', '='>::value,
 229         MsgType=jmmcg::enum_tags::mpl::to_tag<'\001', '3', '5', '='>::value,
 230         OrderID=jmmcg::enum_tags::mpl::to_tag<'\001', '3', '7', '='>::value,
 231         OrderQty=jmmcg::enum_tags::mpl::to_tag<'\001', '3', '8', '='>::value,
 232         OrdStatus=jmmcg::enum_tags::mpl::to_tag<'\001', '3', '9', '='>::value,
 233         OrdType=jmmcg::enum_tags::mpl::to_tag<'\001', '4', '0', '='>::value,
 234         OrigClOrdID=jmmcg::enum_tags::mpl::to_tag<'\001', '4', '1', '='>::value,
 235         Price=jmmcg::enum_tags::mpl::to_tag<'\001', '4', '4', '='>::value,
 236         RefSeqNum=jmmcg::enum_tags::mpl::to_tag<'\001', '4', '5', '='>::value,
 237         SecurityID=jmmcg::enum_tags::mpl::to_tag<'\001', '4', '8', '='>::value,
 238         SenderCompID=jmmcg::enum_tags::mpl::to_tag<'\001', '4', '9', '='>::value,
 239         Symbol=jmmcg::enum_tags::mpl::to_tag<'\001', '5', '5', '='>::value,
 240         SendingTime=jmmcg::enum_tags::mpl::to_tag<'\001', '5', '2', '='>::value,
 241         Side=jmmcg::enum_tags::mpl::to_tag<'\001', '5', '4', '='>::value,
 242         TargetCompID=jmmcg::enum_tags::mpl::to_tag<'\001', '5', '6', '='>::value,
 243         TimeInForce=jmmcg::enum_tags::mpl::to_tag<'\001', '5', '9', '='>::value,
 244         TransactTime=jmmcg::enum_tags::mpl::to_tag<'\001', '6', '0', '='>::value,
 245         XDestination=jmmcg::enum_tags::mpl::to_tag<'\001', '1', '0', '0', '='>::value,
 246         CountryOfIssue=jmmcg::enum_tags::mpl::to_tag<'\001', '4', '7', '0', '='>::value,
 247         Username=jmmcg::enum_tags::mpl::to_tag<'\001', '5', '5', '3', '='>::value,
 248         Password=jmmcg::enum_tags::mpl::to_tag<'\001', '5', '5', '4', '='>::value,
 249         NewPassword=jmmcg::enum_tags::mpl::to_tag<'\001', '9', '2', '5', '='>::value,
 250         ExecType=jmmcg::enum_tags::mpl::to_tag<'\001', '1', '5', '0', '='>::value,
 251         MarketSegmentID=jmmcg::enum_tags::mpl::to_tag<'\001', '1', '5', '1', '='>::value,
 252         LeavesQty=jmmcg::enum_tags::mpl::to_tag<'\001', '1', '3', '0', '0', '='>::value,
 253         CheckSum=jmmcg::enum_tags::mpl::to_tag<'\001', '1', '0', '='>::value
 254 };
 255 
 256 BOOST_MPL_ASSERT_RELATION((jmmcg::enum_tags::mpl::to_array<FieldsFast, FieldsFast::BodyLength>::size), ==, sizeof(JMMCG_FIX_MSG_BODY_LENGTH_TAG)-1);
 257 BOOST_MPL_ASSERT_RELATION((jmmcg::enum_tags::mpl::to_array<FieldsFast, FieldsFast::MsgType>::size), >=, sizeof(JMMCG_FIX_MSG_TYPE_TAG)-1);
 258 const std::size_t shortest_field_length=4u;
 259 
 260 enum class ExecType : char {
 261         New='0',
 262         DoneForDay='3',
 263         Cancelled='4',
 264         Replaced='5',
 265         PendingCancel='6',
 266         Stopped='7',
 267         Rejected='8',
 268         Suspended='9',
 269         PendingNew='A',
 270         Calculated='B',
 271         Expired='C',
 272         Restated='D',
 273         PendingReplace='E',
 274         Trade_PartialFillOrFill='F',
 275         TradeCorrect='G',
 276         TradeCancel='H',
 277         OrderStatus='I',
 278         TradeInAClearingHold='J',
 279         TradeHasBeenReleasedToClearing='K',
 280         TriggeredOrActivatedBySystem='L'
 281 };
 282 
 283 inline std::ostream &
 284 operator<<(std::ostream &os, ExecType a) {
 285         os<<static_cast<std::underlying_type<ExecType>::type>(a);
 286         return os;
 287 }
 288 
 289 enum class OrdStatus : char {
 290         New='0',
 291         PartiallyFilled='1',
 292         Filled='2',
 293         DoneForDay='3',
 294         Cancelled='4',
 295         Replaced='5',
 296         PendingCancel='6',
 297         Stopped='7',
 298         Rejected='8',
 299         Suspended='9',
 300         PendingNew='A',
 301         Calculated='B',
 302         Expired='C',
 303         AcceptedForBidding='D',
 304         PendingReplace='E'
 305 };
 306 
 307 inline std::ostream &
 308 operator<<(std::ostream &os, OrdStatus a) {
 309         os<<static_cast<std::underlying_type<OrdStatus>::type>(a);
 310         return os;
 311 }
 312 
 313 enum SecurityIDSource : char {
 314         CUSIP='1',
 315         SEDOL='2',
 316         QUIK='3',
 317         ISIN='4',
 318         RIC='5',
 319         ISOCurrencyCode='6',
 320         ISOCountryCode='7'
 321 };
 322 
 323 enum Side : char {
 324         Buy='1',
 325         Sell='2',
 326         SellShort='5',
 327         SellShortExempt='6'
 328 };
 329 
 330 } } } }
 331 
 332 namespace std {
 333 
 334 inline std::ostream &
 335 operator<<(std::ostream &os, isimud::exchanges::FIX::common::field_str_range_t const &v) {
 336         std::copy(v.first, v.second, std::ostream_iterator<isimud::exchanges::FIX::common::element_type>(os));
 337         return os;
 338 }
 339 
 340 }
 341 
 342 #endif

/* [<][>][^][v][top][bottom][index][help] */