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