123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273 |
- 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)
- }
|