Instrument.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. package response
  2. import (
  3. "encoding/xml"
  4. "log"
  5. "time"
  6. )
  7. type CommercialInfo struct {
  8. AggressiveCommissionPerContract float64 `xml:"aggressiveCommissionPerContract"`
  9. PassiveCommissionPerContract float64 `xml:"passiveCommissionPerContract"`
  10. FundingPremiumPercentage float64 `xml:"fundingPremiumPercentage"`
  11. FundingReductionPercentage float64 `xml:"fundingReductionPercentage"`
  12. FundingBaseRate string `xml:"fundingBaseRate"`
  13. }
  14. type Instrument struct {
  15. Id int64 `xml:"id"`
  16. Name string `xml:"name"`
  17. StartTime *time.Time `xml:"-"`
  18. StartTimeStr string `xml:"startTime"`
  19. OpenOffset int `xml:"tradingHours>openingOffset"`
  20. CloseOffset int `xml:"tradingHours>closingOffset"`
  21. TimeZone string `xml:"tradingHours>timezone"`
  22. MarginRate float64 `xml:"margin"`
  23. Currency string `xml:"currency"`
  24. UnitPrice float64 `xml:"unitPrice"`
  25. MinimumOrderQuantity float64 `xml:"minimumOrderQuantity"`
  26. OrderQuantityIncrement float64 `xml:"orderQuantityIncrement"`
  27. MinimumPrice float64 `xml:"minimumPrice"`
  28. MaximumPrice float64 `xml:"maximumPrice"`
  29. TrustedSpread float64 `xml:"trustedSpread"`
  30. PriceIncrement float64 `xml:"priceIncrement"`
  31. StopBuffer bool `xml:"stopBuffer"`
  32. AssetClass string `xml:"assetClass"`
  33. Isin string `xml:"underlyingIsin"`
  34. Symbol string `xml:"symbol"`
  35. MaximumPosition float64 `xml:"maximumPositionThreshold"`
  36. AggressiveCommissionRate float64 `xml:"aggressiveCommissionRate"`
  37. PassiveCommissionRate float64 `xml:"passiveCommissionRate"`
  38. MinimumCommission float64 `xml:"minimumCommission"`
  39. LongSwapPoints float64 `xml:"longSwapPoints"`
  40. ShortSwapPoints float64 `xml:"shortSwapPoints"`
  41. DailyInterestRateBasis int `xml:"dailyInterestRateBasis"`
  42. UnitOfMeasure string `xml:"contractUnitOfMeasure"`
  43. ContractSize float64 `xml:"contractSize"`
  44. TradingDays []string `xml:"tradingDays>tradingDay"`
  45. VolatilityBandPercentage float64 `xml:"retailVolatilityBandPercentage"`
  46. }
  47. type Instruments struct {
  48. XMLName xml.Name `xml:"res"`
  49. Header
  50. Data []*Instrument `xml:"body>instruments>instrument"`
  51. HasMoreResults bool `xml:"body>hasMoreResults"`
  52. }
  53. func NewInstrument(data []byte) *Instrument {
  54. r := Instrument{}
  55. err := xml.Unmarshal(data, &r)
  56. if err != nil {
  57. log.Println(err)
  58. return nil
  59. }
  60. t , err := time.Parse("2006-01-02T15:04:05", r.StartTimeStr)
  61. if err != nil {
  62. log.Println(err)
  63. return nil
  64. }
  65. r.StartTime = &t
  66. r.MarginRate = r.MarginRate / 100
  67. return &r
  68. }
  69. func NewInstruments(data string) *Instruments {
  70. r := Instruments{}
  71. err := xml.Unmarshal([]byte(data), &r)
  72. if err != nil {
  73. log.Println(err)
  74. return nil
  75. }
  76. for i := 0; i < len(r.Data); i++ {
  77. t , err := time.Parse("2006-01-02T15:04:05", r.Data[i].StartTimeStr)
  78. if err != nil {
  79. log.Println(err)
  80. return nil
  81. }
  82. r.Data[i].StartTime = &t
  83. r.Data[i].MarginRate = r.Data[i].MarginRate / 100
  84. }
  85. return &r
  86. }
  87. type ExchangeRateEvent struct {
  88. XMLName xml.Name `xml:"exchangeRate"`
  89. From string `xml:"from"`
  90. To string `xml:"to"`
  91. Buy float64 `xml:"buy"`
  92. Sell float64 `xml:"sell"`
  93. Wallet float64 `xml:"-"`
  94. }
  95. func NewExchangeRateEvent(data string) *ExchangeRateEvent {
  96. r := &ExchangeRateEvent{}
  97. err := xml.Unmarshal([]byte(data), r)
  98. if err != nil {
  99. return nil
  100. }
  101. return r
  102. }