Custom Fields
When we were doing fix development, we often encountered the original fix label and did not meet our business needs, and this time we need to involve custom "fields", "Classes", "collections".
Non-Secure custom fields
Message.setfield (New Doublefield (6123), "value");
Doublefield field = Message.getfield (new Doublefield (6123));
recommended custom Fields Methods
The above customization method often leads to unnecessary hassles in team development (tags are reused and labels are difficult to understand).
FIXJ website recommended that we use the following methods to customize the field
//Remitenofield.java
import Quickfix. Stringfield;
public class Remitenofield extends Stringfield
{public
Remitenofield () {super (C);}
Public Remitenofield (String data) {Super (Remitenofield, data);
}}
Of course, after customizing the field. You need to add the corresponding field description in the Fix4.4.xml file.
<fields>
<field number= "1" name= "Remitenofield" type= "String"/>
...
<field number= "4" name= "Advside" type= "CHAR" >
<value enum= "B" description= "buy"/> <value
enum = "S" description= "SELL"/>
<value enum= "X" description= "CROSS"/> <value enum=
"T" description= " TRADE "/>
</field>
Custom Message
The message in fix is quite the Java class we understand. You can customize the message to describe an object. Then add the corresponding message description in the XML file.
Note: Remember to add the corresponding enumeration
<value enum= "Z6666" description= "Ordersaftersomeidrequest" in the 35 label position/>
Java Class Code
Import Quickfix.
message;
Import Quickfix.field.OrdStatus;
Import Quickfix.field.OrderID;
Import Quickfix.field.SecurityType;
Import quickfix.field.StrikeCurrency;
Import Quickfix.field.Symbol;
Import Quickfix.field.TradeRequestID;
Import Quickfix.field.TradeRequestType;
Import Com.okcoin.okfix.okserver.response.future.PageNO; /** * @ClassName: Ordersrequest * @Description: Get the order number of the specified ID * * */public class Ordersaftersomeidrequest extends message
{private static final long serialversionuid = 7922839466982400795L;
public static final String Msgtype = "Z6666";
Public Ordersaftersomeidrequest () {GetHeader (). SetField (New Quickfix.field.MsgType ("Z6666"));
public void Set (Symbol field) {//SetField (field);
public void Set (OrderID field) {//SetField (field);
public void Set (ordstatus field) {//SetField (field);
public void Set (Traderequestid field) {//568 setfield (field);
} public void Set (Traderequesttype field) {//569 setfield (field);
public void Set (PageNo field) {//8214 page SetField (field);
public void Set (strikecurrency field) {//947 setfield (field);
public void Set (SecurityType field) {//167 setfield (field);
}
}
XML Description
<message name= "Tradeordersafteroneid" msgtype= "Z6666" msgcat= "app" >
<field name= "Symbol" required= "N"/ >
<field name= "OrderID" required= "n"/> <field name=
"Ordstatus" required= "n"/>
<field Name= "Traderequestid" required= "n"/>
<field name= "Traderequesttype" required= "n"/> <field
Name = "PageNo" required= "n"/>
<field name= "strikecurrency" required= "N"/> <field name= "SecurityType"
"required=" N "/>
</message>
Custom Group
A group is essentially a collection that describes a class of collections of the same attributes. QFIXJ fully embodies its flexibility.
Attention. Add the corresponding field in the Fields tab
Group,java Code
/** * @ClassName: Futurepositionsresponse * @Description: Positions Information */public class Futurepositionsresponse extends Mess
Age {private static final long serialversionuid = 1L;
private static final String Msgtype = "Z3333";
Public Futurepositionsresponse () {GetHeader (). SetField (New Quickfix.field.MsgType (Msgtype));
public void Set (Currency field) {//Currency type SetField (field);
public void set (symbol field) {//Flag setfield (field); /** * @ClassName: Nouserpostion * @Description: User information Position Information </group>/* public static C
Lass Nouserpostion extends Group {private static final long serialversionuid = 6684058490806701199L;
Public Nouserpostion () {super (8303, new int[] {55,8213, 6, 38, 8212, 44, 99, 54, 8001, 8203,
898, 8207, 8208,8210,8209});
public void Set (Contractid field) {//Futures contract ID setfield (field); public void Set (AVGPX field) {//Open warehouse price setfield (field);
public void Set (OrderQty field) {//Positions SetField (field);
public void Set (Contractname field) {//contract type Contract_name LTC0108 setfield (field);
public void Set (Price field) {//Open warehouse SetField (field);
public void Set (stoppx field) {//Qiangping price SetField (field);
public void Set (Side field) {//Position: Open more, open empty setfield (field);
public void Set (Balance field) {//Contract account balance setfield (field);
public void Set (Positionrealprofit field) {//Realized breakeven setfield (field);
public void Set (Marginratio field) {//Position: Guarantee Rate (lever multiple) setfield (field);
public void Set (Frozenamt field) {//current contract freeze margin SetField (field); public void Set (Margincash field) {//POSition: Margin SetField (field);
public void Set (PositionType field) {//Position type SetField (field);
public void Set (Positionsid field) {//Position ID setfield (field);
public void Set (Symbol field) {//Contract type SetField (field);
public void Set (Eveningup field) {//Volume setfield (field);
}
}
}
groupxml Configuration
<message name= "Futurepositionsresponse" msgtype= "Z3333" msgcat= "app" > <field name= "Currency" required= "N"/ > <field name= "Symbol" required= "n"/> <group name= "nouserpostion" required= "n" > <fi Eld name= "Symbol" required= "Y"/> <field name= "Contractid" required= "N"/> <field name= "AVGPX" R equired= "n"/> <field name= "OrderQty" required= "n"/> "<field" name= "Contractname" required= "n"/&G
T <field name= "Price" required= "n"/> <field name= "stoppx" required= "N"/> <field-name= "Side" R equired= "n"/> <field name= "Balance" required= "n"/> <field "name=" Positionrealprofit "required="
N "/> <field name=" Marginratio "required=" n "/> <field name=" Frozenamt "required=" n "/> <field name= "Margincash" required= "n"/> <field name= "PositionType" required= "n"/> <field Name= "PositioNsid "required=" n "/> <field name=" Eveningup "required=" n "/> </group> </message>