2015年5月22日 星期五

[FIX Protocol] What is Message Sequence?


Quotes from FIX.4.2 specs
[Start quote from Section "FIX MESSAGE FORMAT AND DELIVERY > Sequence Numbers"]
All FIX messages are identified by a unique sequence number. Sequence numbers are initialized at the start of each FIX session (see Session Protocol section) starting at 1 (one) and increment throughout the session. Monitoring sequence numbers will enable parties to identify and react to missed messages and to gracefully synchronize applications when reconnecting during a FIX session.
Each session will establish an independent incoming and outgoing sequence series; participants will maintain a sequence series to assign to outgoing messages and a separate series to monitor for sequence gaps on incoming messages.
[End quote]
[Start Quote from section "Session Protocol > Message Recovery"]
During initialization, or in the middle of a FIX session, message gaps may occur which are detected via the tracking of incoming sequence numbers. The following section provides details on how to recover messages.
As previously stated, each FIX participant must maintain two sequence numbers for each FIX session, one each for incoming and outgoing messages which are initialized at ‘1’ at the beginning of the FIX session. Each message is assigned a unique (by connection) sequence number, which is incremented after each message. Likewise, every message received has a unique sequence number and the incoming sequence counter is incremented after each message.
When the incoming sequence number does not match the expected number corrective processing is required. Note that the SeqReset-Reset message (used only to recover from a disaster scenario vs. normal resend request processing) is an exception to this rule as it should be processed without regards to its MsgSeqNum. If the incoming message has a sequence number less than expected and the PossDupFlag is not set, it indicates a serious error. It is strongly recommended that the session be terminated and manual intervention be initiated. If the incoming sequence number is greater than expected, it indicates that messages were missed and retransmission of the messages is requested via the Resend Request (see the earlier section, Ordered Message Processing).
[End Quote]
If Sequence number(s) are changed on your side without following the above rules and and your counterparty does not abnormally change sequence numbers on their side, then the following situations would occur
1) Your side increases Outbound Sequence number - Your counterparty would send you a resend request
2) Your side decreases Outbound Sequence number - Your counterparty is expected to drop the Session
3) Your side increases next expected Inbound sequence number - receipt of the next message would cause your FIX engine to drop the session because the sequence number of the message received is less than the number your FIX engine is expecting.
4) Your side decreases next expected Inbound sequence number - receipt of next message would cause your FIX engine to send a resend request.
We have used this manually increasing / descreasing sequence numbers abnormally as part of certification tests to check that resend request processing and session disconnect are working properly at both ends.

2015年5月18日 星期一

[FIX Protocol] Fix Parser

http://fixparser.targetcompid.com/

I quite like its domain name, targetCompID.com, so FIX, and the parser is quite user-friendly I think

[FIX Protocol] CompIDs in the Message

Assumption (A=sellside, B=buyside, X=third party):




Send from A to B via X
1)
A sends to X
A

X
B


2)
X sends to B
X
A
B



B responds to A via X
1)
B sends to X
B

X
A


2)
X sends to A
X
B
A


[FIX Protocol] Understanding OrdStatus[39] and ExecType[150] in FIX4.4

Both are for Execution Report[8], while ...

OrdStatus[39] identifies current status of order.

Valid values:
0 = New
1 = Partially filled
2 = Filled
3 = Done for day
4 = Canceled
<5 has been removed~!>
6 = Pending Cancel (e.g. result of Order Cancel Request <F>)
7 = Stopped
8 = Rejected
9 = Suspended
A = Pending New
B = Calculated
C = Expired
D = Accepted for bidding


ExecType[150] describes the specific ExecutionRpt. (I guess it implies the action just executed on sell side ... Rather than the current status of that order, separated terms with different "nature")

Valid values:
0 = New
3 = Done for day
4 = Canceled
5 = Replace
6 = Pending Cancel (e.g. result of Order Cancel Request <F>)
7 = Stopped
8 = Rejected
9 = Suspended
A = Pending New
B = Calculated
C = Expired
D = Restated (ExecutionRpt sent unsolicited by sellside, with ExecRestatementReason <378> (378) set)
E = Pending Replace (e.g. result of Order Cancel/Replace Request <G>)
F = Trade (partial fill or fill)
G = Trade Correct (formerly an ExecTransType <20> (20))
H = Trade Cancel (formerly an ExecTransType <20>)


Oh, my supervisor gave me this one to read then ... And I have read for around an hour to figure out more on the difference between ExecType & OrdStatus ... together with the behaviour of amending orders: 
http://www.fixdeveloper.com/2014/05/fix-44-order-state-change-matrices.html

An example captured:


C.3 - Replace to decrease quantity 

C.3.a - Cancel/replace request sent whilst execution is being reported, the requested order qty exceeds the cum qty. Order is replaced then filled

TimeMessage Received (ClOrdID, OrigClOrdID)Message Sent (ClOrdID, OrigClOrdID)Exec TypeOrdStatusOrder QtyCum QtyLeaves QtyLast QtyComment
1New Order(X)10000
2Execution(X)RejectedRejected10000000If order is rejected
2Execution(X)NewNew100000100000
3Execution(X)TradePartially Filled10000100090001000Execution for 1000
4Replace Request(Y,X)8000Request a decrease order quantity to 8000 (leaving 7000 open)
4Execution(X)TradePartially Filled1000015008500500Execution for 500 sent. Replace request and this execution report pass each other on the connection
5Cancel Reject (Y,X)Partially FilledIf request is rejected by salesperson
5Execution (Y,X)Pending ReplacePending Replace10000150085000"Pending replace" order status takes precedence over "partially filled" order status
6Execution(X)TradePending Replace1000016008400100Execution for 100 occurs before cancel/replace request is accepted
7Cancel Reject (Y,X)Partially FilledIf request is rejected by trader/exchange
7Execution (Y,X)ReplacePartially Filled8000160064000Replace is accepted as requested order qty exceeds cum qty
8Execution (Y)TradeFilled8000800006400Execution for 6400.

[康復路] 試完又試

見了醫生,因為血色素又變低了,醫生想檢查是否「缺鐵」為成因,檢查又檢查…… 感覺有些麻煩……又抽血,又要留樣本…… 令我回想起當日入院的時光,因為一些原因,留樣本只需留一次,免卻留三次的麻煩;現在每天都要留一次,連續三天。每天早上就要跑醫院一趟再上班。 幸好也完成了。 第二次抽血...