OrderRequest.go 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. package request
  2. import (
  3. "encoding/xml"
  4. "log"
  5. "bytes"
  6. )
  7. var _ = log.Println
  8. //type OrderType
  9. type TimeInForceString struct {
  10. FILL_OR_KILL string
  11. IMMEDIATE_OR_CANCEL string
  12. GOOD_FOR_DAY string
  13. GOOD_TIL_CANCELLED string
  14. UNKNOWN string
  15. }
  16. var TimeInForce TimeInForceString = TimeInForceString{FILL_OR_KILL: "FillOrKill",
  17. IMMEDIATE_OR_CANCEL: "ImmediateOrCancel", GOOD_FOR_DAY: "GoodForDay",
  18. GOOD_TIL_CANCELLED: "GoodTilCancelled", UNKNOWN: "Unknown"}
  19. type OrderRequest struct {
  20. XMLName xml.Name `xml:"req" json:"-"`
  21. InstrumentId int64 `xml:"body>order>instrumentId" json:"instrumentId"`
  22. InstructionId string `xml:"body>order>instructionId,omitempty" json:"instructionId"`
  23. Price float64 `xml:"body>order>price,omitempty" json:"price"`
  24. StopPrice float64 `xml:"body>order>stopPrice,omitempty" json:"stopPrice"`
  25. Quantity float64 `xml:"body>order>quantity" json:"quantity"`
  26. TimeInForce string `xml:"body>order>timeInForce" json:"timeInForce"`
  27. StopLossPriceOffset float64 `xml:"body>order>stopLossOffset,omitempty" json:"stopLossOffset"`
  28. StopProfitPriceOffset float64 `xml:"body>order>stopProfitOffset,omitempty" json:"stopProfitOffset"`
  29. }
  30. func (this *OrderRequest) Url() string {
  31. return "/secure/trade/placeOrder"
  32. }
  33. func (this *OrderRequest) GetId() string {
  34. return this.InstructionId
  35. }
  36. func (this *OrderRequest) SetId(id string) {
  37. this.InstructionId = id
  38. }
  39. func (this *OrderRequest) SetAccountId(id int64) {
  40. }
  41. func (this *OrderRequest) Clone() interface{} {
  42. tmp := *this
  43. return &tmp
  44. }
  45. func (this *OrderRequest) GetRequestData() *bytes.Buffer {
  46. output, _ := xml.Marshal(this)
  47. return bytes.NewBuffer(output)
  48. }
  49. ///////////////// MarketOrderRequest ////////////////
  50. type MarketOrderRequest struct {
  51. OrderRequest
  52. }
  53. func NewMarketOrderRequest(instrumentId int64, instructionId, timeInForce string,
  54. quantity, stopLossOffset, stopProfitOffset float64) *MarketOrderRequest {
  55. return &MarketOrderRequest{OrderRequest{InstrumentId: instrumentId,
  56. InstructionId: instructionId,
  57. Quantity: quantity,
  58. TimeInForce: timeInForce,
  59. StopLossPriceOffset : stopLossOffset,
  60. StopProfitPriceOffset : stopProfitOffset}}
  61. }
  62. /////////////// LimitOrderReuqest ///////////////
  63. type LimitOrderRequest struct {
  64. OrderRequest
  65. }
  66. func NewLimitOrderRequest(instrumentId int64, instructionId , timeInForce string,
  67. price , quantity , stopLossOffset, stopProfitOffset float64) *LimitOrderRequest {
  68. return &LimitOrderRequest{OrderRequest{InstrumentId: instrumentId,
  69. InstructionId: instructionId,
  70. Quantity: quantity,
  71. TimeInForce: timeInForce,
  72. Price : price,
  73. StopLossPriceOffset : stopLossOffset,
  74. StopProfitPriceOffset : stopProfitOffset}}
  75. }
  76. /////////////// StopOrderReuqest ///////////////
  77. type StopOrderRequest struct {
  78. OrderRequest
  79. }
  80. func NewStopOrderRequest(instrumentId int64, instructionId , timeInForce string,
  81. price , quantity , stopLossOffset, stopProfitOffset float64) *StopOrderRequest {
  82. return &StopOrderRequest{OrderRequest{InstrumentId: instrumentId,
  83. InstructionId: instructionId,
  84. Quantity: quantity,
  85. TimeInForce: timeInForce,
  86. StopPrice : price,
  87. StopLossPriceOffset : stopLossOffset,
  88. StopProfitPriceOffset : stopProfitOffset}}
  89. }
  90. ///////////////// CancelOrderRequest /////////////////////
  91. type CancelOrderRequest struct {
  92. XMLName xml.Name `xml:"req" json:"-"`
  93. InstrumentId int64 `xml:"body>instrumentId" json:"instrumentId"`
  94. OriginalInstructionId string `xml:"body>originalInstructionId" json:"originalInstructionId"`
  95. InstructionId string `xml:"body>instructionId,omitempty" json:"instructionId"`
  96. }
  97. func (this *CancelOrderRequest) Url() string {
  98. return "/secure/trade/cancel"
  99. }
  100. func (this *CancelOrderRequest) GetId() string {
  101. return this.InstructionId
  102. }
  103. func (this *CancelOrderRequest) SetAccountId(id int64) {
  104. }
  105. func (this *CancelOrderRequest) SetId(id string) {
  106. this.InstructionId = id
  107. }
  108. func (this *CancelOrderRequest) Clone() interface{} {
  109. tmp := *this
  110. return &tmp
  111. }
  112. func (this *CancelOrderRequest) GetRequestData() *bytes.Buffer {
  113. output, _ := xml.Marshal(this)
  114. return bytes.NewBuffer(output)
  115. }
  116. func NewCancelOrderRequest(instrumentId int64, originalInstructionId, instructionId string) *CancelOrderRequest {
  117. return &CancelOrderRequest{InstrumentId: instrumentId, OriginalInstructionId: originalInstructionId, InstructionId: instructionId}
  118. }
  119. ///////////////////////// ClosingOrderRequest ///////////////
  120. type ClosingOrderRequest struct {
  121. XMLName xml.Name `xml:"req" json:"-"`
  122. InstructionId string `xml:"body>instructionId,omitempty" json:"instructionId"`
  123. InstrumentId int64 `xml:"body>instrumentId,omitempty" json:"instrumentId"`
  124. OriginalInstructionId string `xml:"body>originalInstructionId" json:"originalInstructionId"`
  125. Quantity float64 `xml:"body>quantity" json:"quantity"`
  126. }
  127. func (this *ClosingOrderRequest) Url() string {
  128. if this.OriginalInstructionId != "" {
  129. return "/secure/trade/closeOutOrder"
  130. }
  131. return "/secure/trade/closeOutInstrumentPosition"
  132. }
  133. func (this *ClosingOrderRequest) GetId() string {
  134. return this.InstructionId
  135. }
  136. func (this *ClosingOrderRequest) SetAccountId(id int64) {
  137. }
  138. func (this *ClosingOrderRequest) SetId(id string) {
  139. this.InstructionId = id
  140. }
  141. func (this *ClosingOrderRequest) Clone() interface{} {
  142. tmp := *this
  143. return &tmp
  144. }
  145. func (this *ClosingOrderRequest) GetRequestData() *bytes.Buffer {
  146. output, _ := xml.Marshal(this)
  147. return bytes.NewBuffer(output)
  148. }
  149. func NewClosingOrderRequest(instrumentId int64, originalInstructionId, instructionId string, quantity float64) *ClosingOrderRequest {
  150. return &ClosingOrderRequest{InstrumentId: instrumentId,
  151. OriginalInstructionId: originalInstructionId,
  152. InstructionId: instructionId,
  153. Quantity: quantity}
  154. }
  155. //////////////////////// AmendStopsRequest //////////////////
  156. type AmendStopsOrderRequest struct {
  157. XMLName xml.Name `xml:"req" json:"-"`
  158. InstrumentId int64 `xml:"body>instrumentId" json:"instrumentId"`
  159. OriginalInstructionId string `xml:"body>originalInstructionId" json:"originalInstructionId"`
  160. InstructionId string `xml:"body>instructionId,omitempty" json:"instructionId"`
  161. StopLossPriceOffset float64 `xml:"body>stopLossOffset" json:"stopLossOffset"`
  162. StopProfitPriceOffset float64 `xml:"body>stopProfitOffset" json:"stopProfitOffset"`
  163. }
  164. func (this *AmendStopsOrderRequest) Url() string {
  165. return "/secure/trade/amendOrder"
  166. }
  167. func (this *AmendStopsOrderRequest) GetRequestData() *bytes.Buffer {
  168. output, _ := xml.Marshal(this)
  169. return bytes.NewBuffer(output)
  170. }
  171. func (this *AmendStopsOrderRequest) GetId() string {
  172. return this.InstructionId
  173. }
  174. func (this *AmendStopsOrderRequest) SetAccountId(id int64) {
  175. }
  176. func (this *AmendStopsOrderRequest) SetId(id string) {
  177. this.InstructionId = id
  178. }
  179. func (this *AmendStopsOrderRequest) Clone() interface{} {
  180. tmp := *this
  181. return &tmp
  182. }
  183. func NewAmendStopsOrderRequest(instrumentId int64, originalInstructionId, instructionId string,
  184. stopLossPrice, stopProfitPrice float64) *AmendStopsOrderRequest {
  185. return &AmendStopsOrderRequest{InstrumentId: instrumentId,
  186. OriginalInstructionId: originalInstructionId,
  187. InstructionId: instructionId,
  188. StopLossPriceOffset: stopLossPrice,
  189. StopProfitPriceOffset: stopProfitPrice}
  190. }
  191. type OrderTransaction struct {
  192. orderId string
  193. }
  194. func NewOrderTransactionRequest(orderId string) *OrderTransaction {
  195. return &OrderTransaction{orderId}
  196. }
  197. func (this *OrderTransaction) Url() string {
  198. return "/secure/read/account/getOrderTransactions?orderId="+this.orderId
  199. }
  200. func (this *OrderTransaction) GetRequestData() *bytes.Buffer {
  201. return nil
  202. }
  203. type OrderActivityAuditTrailRequest struct {
  204. XMLName xml.Name `xml:"req" json:"-"`
  205. OrderId string `xml:"body>orderId"`
  206. Offset int32 `xml:"body>offset"`
  207. PageSize int32 `xml:"body>pageSize"`
  208. }
  209. func NewOrderActivityAuditTrailRequest(orderId string, pageSize int32, offset int32) *OrderActivityAuditTrailRequest {
  210. return &OrderActivityAuditTrailRequest{xml.Name{}, orderId, offset, pageSize}
  211. }
  212. func (this *OrderActivityAuditTrailRequest) Url() string {
  213. return "/secure/read/account/getOrderActivityAuditTrail"
  214. }
  215. func (this *OrderActivityAuditTrailRequest) GetRequestData() *bytes.Buffer {
  216. output, _ := xml.Marshal(this)
  217. log.Println(string(output))
  218. return bytes.NewBuffer(output)
  219. }