package request import ( "encoding/xml" "log" "bytes" ) var _ = log.Println //type OrderType type TimeInForceString struct { FILL_OR_KILL string IMMEDIATE_OR_CANCEL string GOOD_FOR_DAY string GOOD_TIL_CANCELLED string UNKNOWN string } var TimeInForce TimeInForceString = TimeInForceString{FILL_OR_KILL: "FillOrKill", IMMEDIATE_OR_CANCEL: "ImmediateOrCancel", GOOD_FOR_DAY: "GoodForDay", GOOD_TIL_CANCELLED: "GoodTilCancelled", UNKNOWN: "Unknown"} type OrderRequest struct { XMLName xml.Name `xml:"req" json:"-"` InstrumentId int64 `xml:"body>order>instrumentId" json:"instrumentId"` InstructionId string `xml:"body>order>instructionId,omitempty" json:"instructionId"` Price float64 `xml:"body>order>price,omitempty" json:"price"` StopPrice float64 `xml:"body>order>stopPrice,omitempty" json:"stopPrice"` Quantity float64 `xml:"body>order>quantity" json:"quantity"` TimeInForce string `xml:"body>order>timeInForce" json:"timeInForce"` StopLossPriceOffset float64 `xml:"body>order>stopLossOffset,omitempty" json:"stopLossOffset"` StopProfitPriceOffset float64 `xml:"body>order>stopProfitOffset,omitempty" json:"stopProfitOffset"` } func (this *OrderRequest) Url() string { return "/secure/trade/placeOrder" } func (this *OrderRequest) GetId() string { return this.InstructionId } func (this *OrderRequest) SetId(id string) { this.InstructionId = id } func (this *OrderRequest) SetAccountId(id int64) { } func (this *OrderRequest) Clone() interface{} { tmp := *this return &tmp } func (this *OrderRequest) GetRequestData() *bytes.Buffer { output, _ := xml.Marshal(this) return bytes.NewBuffer(output) } ///////////////// MarketOrderRequest //////////////// type MarketOrderRequest struct { OrderRequest } func NewMarketOrderRequest(instrumentId int64, instructionId, timeInForce string, quantity, stopLossOffset, stopProfitOffset float64) *MarketOrderRequest { return &MarketOrderRequest{OrderRequest{InstrumentId: instrumentId, InstructionId: instructionId, Quantity: quantity, TimeInForce: timeInForce, StopLossPriceOffset : stopLossOffset, StopProfitPriceOffset : stopProfitOffset}} } /////////////// LimitOrderReuqest /////////////// type LimitOrderRequest struct { OrderRequest } func NewLimitOrderRequest(instrumentId int64, instructionId , timeInForce string, price , quantity , stopLossOffset, stopProfitOffset float64) *LimitOrderRequest { return &LimitOrderRequest{OrderRequest{InstrumentId: instrumentId, InstructionId: instructionId, Quantity: quantity, TimeInForce: timeInForce, Price : price, StopLossPriceOffset : stopLossOffset, StopProfitPriceOffset : stopProfitOffset}} } /////////////// StopOrderReuqest /////////////// type StopOrderRequest struct { OrderRequest } func NewStopOrderRequest(instrumentId int64, instructionId , timeInForce string, price , quantity , stopLossOffset, stopProfitOffset float64) *StopOrderRequest { return &StopOrderRequest{OrderRequest{InstrumentId: instrumentId, InstructionId: instructionId, Quantity: quantity, TimeInForce: timeInForce, StopPrice : price, StopLossPriceOffset : stopLossOffset, StopProfitPriceOffset : stopProfitOffset}} } ///////////////// CancelOrderRequest ///////////////////// type CancelOrderRequest struct { XMLName xml.Name `xml:"req" json:"-"` InstrumentId int64 `xml:"body>instrumentId" json:"instrumentId"` OriginalInstructionId string `xml:"body>originalInstructionId" json:"originalInstructionId"` InstructionId string `xml:"body>instructionId,omitempty" json:"instructionId"` } func (this *CancelOrderRequest) Url() string { return "/secure/trade/cancel" } func (this *CancelOrderRequest) GetId() string { return this.InstructionId } func (this *CancelOrderRequest) SetAccountId(id int64) { } func (this *CancelOrderRequest) SetId(id string) { this.InstructionId = id } func (this *CancelOrderRequest) Clone() interface{} { tmp := *this return &tmp } func (this *CancelOrderRequest) GetRequestData() *bytes.Buffer { output, _ := xml.Marshal(this) return bytes.NewBuffer(output) } func NewCancelOrderRequest(instrumentId int64, originalInstructionId, instructionId string) *CancelOrderRequest { return &CancelOrderRequest{InstrumentId: instrumentId, OriginalInstructionId: originalInstructionId, InstructionId: instructionId} } ///////////////////////// ClosingOrderRequest /////////////// type ClosingOrderRequest struct { XMLName xml.Name `xml:"req" json:"-"` InstructionId string `xml:"body>instructionId,omitempty" json:"instructionId"` InstrumentId int64 `xml:"body>instrumentId,omitempty" json:"instrumentId"` OriginalInstructionId string `xml:"body>originalInstructionId" json:"originalInstructionId"` Quantity float64 `xml:"body>quantity" json:"quantity"` } func (this *ClosingOrderRequest) Url() string { if this.OriginalInstructionId != "" { return "/secure/trade/closeOutOrder" } return "/secure/trade/closeOutInstrumentPosition" } func (this *ClosingOrderRequest) GetId() string { return this.InstructionId } func (this *ClosingOrderRequest) SetAccountId(id int64) { } func (this *ClosingOrderRequest) SetId(id string) { this.InstructionId = id } func (this *ClosingOrderRequest) Clone() interface{} { tmp := *this return &tmp } func (this *ClosingOrderRequest) GetRequestData() *bytes.Buffer { output, _ := xml.Marshal(this) return bytes.NewBuffer(output) } func NewClosingOrderRequest(instrumentId int64, originalInstructionId, instructionId string, quantity float64) *ClosingOrderRequest { return &ClosingOrderRequest{InstrumentId: instrumentId, OriginalInstructionId: originalInstructionId, InstructionId: instructionId, Quantity: quantity} } //////////////////////// AmendStopsRequest ////////////////// type AmendStopsOrderRequest struct { XMLName xml.Name `xml:"req" json:"-"` InstrumentId int64 `xml:"body>instrumentId" json:"instrumentId"` OriginalInstructionId string `xml:"body>originalInstructionId" json:"originalInstructionId"` InstructionId string `xml:"body>instructionId,omitempty" json:"instructionId"` StopLossPriceOffset float64 `xml:"body>stopLossOffset" json:"stopLossOffset"` StopProfitPriceOffset float64 `xml:"body>stopProfitOffset" json:"stopProfitOffset"` } func (this *AmendStopsOrderRequest) Url() string { return "/secure/trade/amendOrder" } func (this *AmendStopsOrderRequest) GetRequestData() *bytes.Buffer { output, _ := xml.Marshal(this) return bytes.NewBuffer(output) } func (this *AmendStopsOrderRequest) GetId() string { return this.InstructionId } func (this *AmendStopsOrderRequest) SetAccountId(id int64) { } func (this *AmendStopsOrderRequest) SetId(id string) { this.InstructionId = id } func (this *AmendStopsOrderRequest) Clone() interface{} { tmp := *this return &tmp } func NewAmendStopsOrderRequest(instrumentId int64, originalInstructionId, instructionId string, stopLossPrice, stopProfitPrice float64) *AmendStopsOrderRequest { return &AmendStopsOrderRequest{InstrumentId: instrumentId, OriginalInstructionId: originalInstructionId, InstructionId: instructionId, StopLossPriceOffset: stopLossPrice, StopProfitPriceOffset: stopProfitPrice} } type OrderTransaction struct { orderId string } func NewOrderTransactionRequest(orderId string) *OrderTransaction { return &OrderTransaction{orderId} } func (this *OrderTransaction) Url() string { return "/secure/read/account/getOrderTransactions?orderId="+this.orderId } func (this *OrderTransaction) GetRequestData() *bytes.Buffer { return nil } type OrderActivityAuditTrailRequest struct { XMLName xml.Name `xml:"req" json:"-"` OrderId string `xml:"body>orderId"` Offset int32 `xml:"body>offset"` PageSize int32 `xml:"body>pageSize"` } func NewOrderActivityAuditTrailRequest(orderId string, pageSize int32, offset int32) *OrderActivityAuditTrailRequest { return &OrderActivityAuditTrailRequest{xml.Name{}, orderId, offset, pageSize} } func (this *OrderActivityAuditTrailRequest) Url() string { return "/secure/read/account/getOrderActivityAuditTrail" } func (this *OrderActivityAuditTrailRequest) GetRequestData() *bytes.Buffer { output, _ := xml.Marshal(this) log.Println(string(output)) return bytes.NewBuffer(output) }