1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- package lmaxapi
- import (
- "bytes"
- "tickserver/api/lmaxapi/request"
- )
- type IRequest interface {
- Url() string
- GetRequestData() *bytes.Buffer
- }
- type UrlSetter interface {
- SetUrl(url string)
- }
- //============= multi sub ==============//
- type MultiSubscribe struct {
- req []IRequest
- url string
- }
- func NewMultiSubscribe() *MultiSubscribe {
- return &MultiSubscribe{}
- }
- func (multi *MultiSubscribe) Add(req IRequest) {
- multi.req = append(multi.req, req)
- }
- func (multi *MultiSubscribe) SetUrl(url string) {
- multi.url = url
- }
- func (multi *MultiSubscribe) Url() string {
- if multi.url == "" {
- return "/secure/subscribe"
- }
- return multi.url
- }
- func (multi *MultiSubscribe) GetRequestData() *bytes.Buffer {
- buf := bytes.NewBufferString("")
- buf.WriteString("<req><body>")
- for i := 0; i < len(multi.req); i++ {
- data2 := multi.req[i].GetRequestData().Bytes()
- data2 = data2[len("<req><body>") : len(data2)-len("</body></req>")]
- buf.Write(data2)
- }
- buf.WriteString("</body></req>")
- return buf
- }
- type OrderActionsRequest struct {
- req []IRequest
- url string
- }
- func NewOrderActionsRequest() *OrderActionsRequest {
- actions := &OrderActionsRequest{}
- return actions
- }
- func (this *OrderActionsRequest) Url() string {
- return "/secure/trade/orderActions"
- }
- func (this *OrderActionsRequest) Add(req IRequest) {
- this.req = append(this.req, req)
- }
- func (this *OrderActionsRequest) GetRequestData() *bytes.Buffer {
- buf := bytes.NewBufferString("")
- buf.WriteString("<req><body>")
- for i := 0; i < len(this.req); i++ {
- data2 := this.req[i].GetRequestData().Bytes()
- data2 = data2[len("<req><body>") : len(data2)-len("</body></req>")]
- send := string(data2)
- switch this.req[i].(type) {
- case *request.AmendStopsOrderRequest:
- send = "<amend>" + send + "</amend>"
- case *request.CancelOrderRequest:
- send = "<cancel>" + send + "</cancel>"
- case *request.ClosingOrderRequest:
- send = "<close>" + send + "</close>"
- }
- buf.WriteString(send)
- }
- buf.WriteString("</body></req>")
- return buf
- }
|