View Javadoc
1   package org.oxerr.okcoin.fix;
2   
3   import java.math.BigDecimal;
4   import java.util.Date;
5   
6   import org.oxerr.okcoin.fix.field.AccReqID;
7   import org.oxerr.okcoin.fix.fix44.AccountInfoRequest;
8   import org.oxerr.okcoin.fix.fix44.OrdersInfoAfterSomeIDRequest;
9   
10  import quickfix.field.Account;
11  import quickfix.field.ClOrdID;
12  import quickfix.field.MassStatusReqID;
13  import quickfix.field.MassStatusReqType;
14  import quickfix.field.OrdStatus;
15  import quickfix.field.OrdType;
16  import quickfix.field.OrderID;
17  import quickfix.field.OrderQty;
18  import quickfix.field.OrigClOrdID;
19  import quickfix.field.Price;
20  import quickfix.field.Side;
21  import quickfix.field.Symbol;
22  import quickfix.field.TradeRequestID;
23  import quickfix.field.TradeRequestType;
24  import quickfix.field.TransactTime;
25  import quickfix.fix44.NewOrderSingle;
26  import quickfix.fix44.OrderCancelRequest;
27  import quickfix.fix44.OrderMassStatusRequest;
28  import quickfix.fix44.TradeCaptureReportRequest;
29  
30  /**
31   * Utilities for creating trade request messages.
32   */
33  public class TradeRequestCreator {
34  
35  	private final String account;
36  
37  	public TradeRequestCreator(String apiKey, String secretKey) {
38  		this.account = String.format("%s,%s", apiKey, secretKey);
39  	}
40  
41  	public AccountInfoRequest createAccountInfoRequest(String accReqId) {
42  		AccountInfoRequest message = new AccountInfoRequest();
43  		message.set(new AccReqID(accReqId));
44  		message.set(new Account(account));
45  		return message;
46  	}
47  
48  	public NewOrderSingle createNewOrderSingle(
49  			String clOrdId,
50  			char side,
51  			char ordType,
52  			BigDecimal orderQty,
53  			BigDecimal price,
54  			String symbol) {
55  		NewOrderSingle message = new NewOrderSingle(
56  				new ClOrdID(clOrdId),
57  				new Side(side),
58  				new TransactTime(new Date()),
59  				new OrdType(ordType));
60  		message.set(new Account(account));
61  		message.set(new OrderQty(orderQty));
62  		message.set(new Price(price));
63  		message.set(new Symbol(symbol));
64  		return message;
65  	}
66  
67  	public OrderCancelRequest createOrderCancelRequest(
68  			String clOrdId,
69  			String origClOrdId,
70  			char side,
71  			String symbol) {
72  		OrderCancelRequest message = new OrderCancelRequest(
73  				new OrigClOrdID(origClOrdId),
74  				new ClOrdID(clOrdId),
75  				new Side(side),
76  				new TransactTime(new Date()));
77  		message.set(new Symbol(symbol));
78  		return message;
79  	}
80  
81  	public OrderMassStatusRequest createOrderMassStatusRequest(
82  			String massStatusReqId,
83  			int massStatusReqType) {
84  		OrderMassStatusRequest message  = new OrderMassStatusRequest(
85  				new MassStatusReqID(massStatusReqId),
86  				new MassStatusReqType(massStatusReqType));
87  		return message;
88  	}
89  
90  	public TradeCaptureReportRequest createTradeCaptureReportRequest(
91  			String tradeRequestId, String symbol) {
92  		TradeCaptureReportRequest message = new TradeCaptureReportRequest(
93  				new TradeRequestID(tradeRequestId),
94  				new TradeRequestType(
95  						TradeRequestType.MATCHED_TRADES_MATCHING_CRITERIA_PROVIDED_ON_REQUEST));
96  		message.set(new Symbol(symbol));
97  		return message;
98  	}
99  
100 	public OrdersInfoAfterSomeIDRequest createOrdersInfoAfterSomeIDRequest(
101 			String tradeRequestId, String symbol, long orderId, char ordStatus) {
102 		OrdersInfoAfterSomeIDRequest message = new OrdersInfoAfterSomeIDRequest(
103 				new TradeRequestID(tradeRequestId),
104 				new Symbol(symbol),
105 				new OrderID(String.valueOf(orderId)),
106 				new OrdStatus(ordStatus));
107 		return message;
108 	}
109 
110 }