LoginRequest.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package request
  2. import (
  3. "bytes"
  4. "encoding/xml"
  5. )
  6. type productTypeString struct {
  7. CFD_LIVE string
  8. CFD_DEMO string
  9. }
  10. const protocolVersion = "1.8"
  11. var ProductType productTypeString = productTypeString{CFD_LIVE: "CFD_LIVE", CFD_DEMO: "CFD_DEMO"}
  12. type LoginRequest struct {
  13. XMLName xml.Name `xml:"req" json:"-"`
  14. UserName string `xml:"body>username" json:"username"`
  15. Password string `xml:"body>password" json:"password"`
  16. Version string `xml:"body>protocolVersion" json:"version"`
  17. ProductType string `xml:"body>productType" json:"productType"`
  18. }
  19. func NewLoginRequest(username, password, producttype string) *LoginRequest {
  20. lr := LoginRequest{UserName: username, Password: password, ProductType: producttype, Version: protocolVersion}
  21. return &lr
  22. }
  23. func (this *LoginRequest) Url() string {
  24. return "/public/security/login"
  25. }
  26. func (this *LoginRequest) GetRequestData() *bytes.Buffer {
  27. output, _ := xml.Marshal(this)
  28. return bytes.NewBuffer(output)
  29. }
  30. const CurrencyUSD = "USD"
  31. const AccountTypeStandard = "STANDARD_TRADER"
  32. type RegisterRequest struct {
  33. XMLName xml.Name `xml:"req" json:"-"`
  34. Title string `xml:"body>title" json:"title"`
  35. FirstName string `xml:"body>firstname" json:"firstname"`
  36. Surname string `xml:"body>surname" json:"surname"`
  37. Email string `xml:"body>email" json:"email"`
  38. Phone string `xml:"body>phone" json:"phone"`
  39. UserName string `xml:"body>username" json:"username"`
  40. Password string `xml:"body>password" json:"password"`
  41. Currency string `xml:"body>currency" json:"currency"`
  42. AccountType string `xml:"body>accountType" json:"accountType"`
  43. ProductType string `xml:"body>productType" json:"productType"`
  44. }
  45. func (this *RegisterRequest) Url() string {
  46. return "/public/security/register"
  47. }
  48. func (this *RegisterRequest) GetRequestData() *bytes.Buffer {
  49. output, _ := xml.Marshal(this)
  50. return bytes.NewBuffer(output)
  51. }