package request import ( "bytes" "encoding/xml" ) type suburl struct { url string } func (this *suburl) SetUrl(url string) { this.url = url } func (this *suburl) Url() string { if this.url == "" { return "/secure/subscribe" } else { return this.url } } type SubscriptionRequest struct { XMLName xml.Name `xml:"req" json:"-"` SubType string `xml:"body>subscription>type" json:"type"` suburl } func (this *SubscriptionRequest) GetRequestData() *bytes.Buffer { output, _ := xml.Marshal(this) return bytes.NewBuffer(output) } // ================ AccountSubscriptionRequest ================ type AccountSubscriptionRequest struct { SubscriptionRequest } func NewAccountSubscriptionRequest() *AccountSubscriptionRequest { return &AccountSubscriptionRequest{SubscriptionRequest{SubType: "account"}} } // ================= HeartbeatSubscriptionRequest type HeartbeatSubscriptionRequest struct { SubscriptionRequest } func NewHeartbeatSubscriptionRequest() *HeartbeatSubscriptionRequest { return &HeartbeatSubscriptionRequest{SubscriptionRequest{SubType: "account"}} } // ================ ExecutionSubscriptionRequest ================ type ExecutionSubscriptionRequest struct { SubscriptionRequest } func NewExecutionSubscriptionRequest() *ExecutionSubscriptionRequest { return &ExecutionSubscriptionRequest{SubscriptionRequest{SubType: "account"}} } //============== OrderSubscriptionRequest ================ type OrderSubscriptionRequest struct { SubscriptionRequest } func NewOrderSubscriptionRequest() *OrderSubscriptionRequest { return &OrderSubscriptionRequest{SubscriptionRequest{SubType: "order"}} } //============== PositionSubscriptionRequest ================ type PositionSubscriptionRequest struct { SubscriptionRequest } func NewPositionSubscriptionRequest() *OrderSubscriptionRequest { return &OrderSubscriptionRequest{SubscriptionRequest{SubType: "position"}} } //============= HistoricMarketDataSubscriptionRequest ========== type HistoricMarketDataSubscriptionRequest struct { SubscriptionRequest } func NewHistoricSubscriptionRequest() *HistoricMarketDataSubscriptionRequest { return &HistoricMarketDataSubscriptionRequest{SubscriptionRequest{SubType: "historicMarketData"}} } //============= OrderBookSubscriptionRequest ================== type OrderBookSubscriptionRequest struct { XMLName xml.Name `xml:"req" json:"-"` InstrumentId int64 `xml:"body>subscription>ob2" json:"instrumentId"` suburl } func (this *OrderBookSubscriptionRequest) GetRequestData() *bytes.Buffer { output, _ := xml.Marshal(this) return bytes.NewBuffer(output) } func NewOrderBookSubscriptionRequest(insId int64) *OrderBookSubscriptionRequest { return &OrderBookSubscriptionRequest{InstrumentId: insId} } //============ OrderBookStatusSubscriptionRequest ====== type OrderBookStatusRequest struct { XMLName xml.Name `xml:"req" json:"-"` InstrumentId int64 `xml:"body>subscription>orderBookStatus" json:"instrumentId"` suburl } func (this *OrderBookStatusRequest) GetRequestData() *bytes.Buffer { output, _ := xml.Marshal(this) return bytes.NewBuffer(output) } func NewOrderBookStatusRequest(insId int64) *OrderBookStatusRequest { return &OrderBookStatusRequest{InstrumentId : insId} } //======= exchange rate =========== type ExchangeRateRequest struct { XMLName xml.Name `xml:"req" json:"-"` From string `xml:"body>subscription>exchangeRate>from" json:"from"` To string `xml:"body>subscription>exchangeRate>to" json:"to"` suburl } func (this *ExchangeRateRequest) GetRequestData() *bytes.Buffer { output, _ := xml.Marshal(this) return bytes.NewBuffer(output) } func NewExchangeRateRequest(from string, to string) *ExchangeRateRequest { return &ExchangeRateRequest{xml.Name{}, from, to, suburl{}} } //============= instrument info ============ type InstrumentRequest struct { XMLName xml.Name `xml:"req" json:"-"` InstrumentId int64 `xml:"body>subscription>instrument" json:"instrumentId"` suburl } func NewInstrumentRequest(instrumentId int64) *InstrumentRequest { return &InstrumentRequest{xml.Name{}, instrumentId, suburl{}} } func (this *InstrumentRequest) GetRequestData() *bytes.Buffer { output, _ := xml.Marshal(this) return bytes.NewBuffer(output) }