/gdata/finance/data.py

http://radioappz.googlecode.com/ · Python · 156 lines · 124 code · 14 blank · 18 comment · 10 complexity · cc72e20b65d563c8d486cb7e7fd449f3 MD5 · raw file

  1. #!/usr/bin/python
  2. #
  3. # Copyright (C) 2009 Google Inc.
  4. #
  5. # Licensed under the Apache License, Version 2.0 (the "License");
  6. # you may not use this file except in compliance with the License.
  7. # You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. """Contains the data classes of the Google Finance Portfolio Data API"""
  17. __author__ = 'j.s@google.com (Jeff Scudder)'
  18. import atom.core
  19. import atom.data
  20. import gdata.data
  21. import gdata.opensearch.data
  22. GF_TEMPLATE = '{http://schemas.google.com/finance/2007/}%s'
  23. class Commission(atom.core.XmlElement):
  24. """Commission for the transaction"""
  25. _qname = GF_TEMPLATE % 'commission'
  26. money = [gdata.data.Money]
  27. class CostBasis(atom.core.XmlElement):
  28. """Cost basis for the portfolio or position"""
  29. _qname = GF_TEMPLATE % 'costBasis'
  30. money = [gdata.data.Money]
  31. class DaysGain(atom.core.XmlElement):
  32. """Today's gain for the portfolio or position"""
  33. _qname = GF_TEMPLATE % 'daysGain'
  34. money = [gdata.data.Money]
  35. class Gain(atom.core.XmlElement):
  36. """Total gain for the portfolio or position"""
  37. _qname = GF_TEMPLATE % 'gain'
  38. money = [gdata.data.Money]
  39. class MarketValue(atom.core.XmlElement):
  40. """Market value for the portfolio or position"""
  41. _qname = GF_TEMPLATE % 'marketValue'
  42. money = [gdata.data.Money]
  43. class PortfolioData(atom.core.XmlElement):
  44. """Data for the portfolio"""
  45. _qname = GF_TEMPLATE % 'portfolioData'
  46. return_overall = 'returnOverall'
  47. currency_code = 'currencyCode'
  48. return3y = 'return3y'
  49. return4w = 'return4w'
  50. market_value = MarketValue
  51. return_y_t_d = 'returnYTD'
  52. cost_basis = CostBasis
  53. gain_percentage = 'gainPercentage'
  54. days_gain = DaysGain
  55. return3m = 'return3m'
  56. return5y = 'return5y'
  57. return1w = 'return1w'
  58. gain = Gain
  59. return1y = 'return1y'
  60. class PortfolioEntry(gdata.data.GDEntry):
  61. """Describes an entry in a feed of Finance portfolios"""
  62. portfolio_data = PortfolioData
  63. class PortfolioFeed(gdata.data.GDFeed):
  64. """Describes a Finance portfolio feed"""
  65. entry = [PortfolioEntry]
  66. class PositionData(atom.core.XmlElement):
  67. """Data for the position"""
  68. _qname = GF_TEMPLATE % 'positionData'
  69. return_y_t_d = 'returnYTD'
  70. return5y = 'return5y'
  71. return_overall = 'returnOverall'
  72. cost_basis = CostBasis
  73. return3y = 'return3y'
  74. return1y = 'return1y'
  75. return4w = 'return4w'
  76. shares = 'shares'
  77. days_gain = DaysGain
  78. gain_percentage = 'gainPercentage'
  79. market_value = MarketValue
  80. gain = Gain
  81. return3m = 'return3m'
  82. return1w = 'return1w'
  83. class Price(atom.core.XmlElement):
  84. """Price of the transaction"""
  85. _qname = GF_TEMPLATE % 'price'
  86. money = [gdata.data.Money]
  87. class Symbol(atom.core.XmlElement):
  88. """Stock symbol for the company"""
  89. _qname = GF_TEMPLATE % 'symbol'
  90. symbol = 'symbol'
  91. exchange = 'exchange'
  92. full_name = 'fullName'
  93. class PositionEntry(gdata.data.GDEntry):
  94. """Describes an entry in a feed of Finance positions"""
  95. symbol = Symbol
  96. position_data = PositionData
  97. class PositionFeed(gdata.data.GDFeed):
  98. """Describes a Finance position feed"""
  99. entry = [PositionEntry]
  100. class TransactionData(atom.core.XmlElement):
  101. """Data for the transction"""
  102. _qname = GF_TEMPLATE % 'transactionData'
  103. shares = 'shares'
  104. notes = 'notes'
  105. date = 'date'
  106. type = 'type'
  107. commission = Commission
  108. price = Price
  109. class TransactionEntry(gdata.data.GDEntry):
  110. """Describes an entry in a feed of Finance transactions"""
  111. transaction_data = TransactionData
  112. class TransactionFeed(gdata.data.GDFeed):
  113. """Describes a Finance transaction feed"""
  114. entry = [TransactionEntry]