HistoricRequest.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package request
  2. import (
  3. "bytes"
  4. "encoding/xml"
  5. "time"
  6. )
  7. func (this *TopOfBookHistoricMarketDataRequest) Url() string {
  8. return "/secure/read/marketData/requestHistoricMarketData"
  9. }
  10. type TopOfBookHistoricMarketDataRequest struct {
  11. XMLName xml.Name `xml:"req" json:"-"`
  12. InstructionId string `xml:"body>instructionId" json:"instructionId"`
  13. InstrumentId int64 `xml:"body>orderBookId" json:"instrumentId"`
  14. From int64 `xml:"body>from" json:"from"`
  15. To int64 `xml:"body>to" json:"to"`
  16. Option []string `xml:"body>orderBook>options>option" json:"option"`
  17. Depth int32 `xml:"body>orderBook>depth" json:"depth"`
  18. Format string `xml:"body>orderBook>format" json:"format"`
  19. }
  20. func (this *TopOfBookHistoricMarketDataRequest) GetRequestData() *bytes.Buffer {
  21. data, _ := xml.Marshal(this)
  22. return bytes.NewBuffer(data)
  23. }
  24. func NewTopOfBookHistoricRequest(instructionId string, instrumentId int64,
  25. from time.Time, to time.Time, format string) *TopOfBookHistoricMarketDataRequest {
  26. return &TopOfBookHistoricMarketDataRequest{
  27. InstructionId: instructionId,
  28. InstrumentId: instrumentId, From: from.Unix() * 1000, To: to.Unix() * 1000,
  29. Option: []string{"BID", "ASK"}, Depth: 1,
  30. Format: format}
  31. }
  32. type AggregateHistoricMarketDataRequest struct {
  33. XMLName xml.Name `xml:"req" json:"-"`
  34. InstructionId string `xml:"body>instructionId" json:"instructionId"`
  35. InstrumentId int64 `xml:"body>orderBookId" json:"instrumentId"`
  36. From int64 `xml:"body>from" json:"from"`
  37. To int64 `xml:"body>to" json:"to"`
  38. Option []string `xml:"body>aggregate>options>option" json:"option"`
  39. Resolution string `xml:"body>aggregate>resolution" json:"resolution"`
  40. Depth int `xml:"body>aggregate>depth" json:"depth"`
  41. Format string `xml:"body>aggregate>format" json:"format"`
  42. }
  43. func (this *AggregateHistoricMarketDataRequest) Url() string {
  44. return "/secure/read/marketData/requestHistoricMarketData"
  45. }
  46. func (this *AggregateHistoricMarketDataRequest) GetRequestData() *bytes.Buffer {
  47. output, _ := xml.Marshal(this)
  48. return bytes.NewBuffer(output)
  49. }
  50. func NewAggregateHistoricRequest(instructionId string, instrumentId int64, from time.Time, to time.Time,
  51. format string, resolution string, option []string) *AggregateHistoricMarketDataRequest {
  52. return &AggregateHistoricMarketDataRequest{
  53. InstructionId: instructionId,
  54. InstrumentId: instrumentId,
  55. From: from.Unix() * 1000, To: to.Unix() * 1000, Format: format,
  56. Resolution: resolution, Option: option, Depth: 1}
  57. }