/gdata/finance/data.py
Python | 156 lines | 124 code | 14 blank | 18 comment | 2 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 17 18"""Contains the data classes of the Google Finance Portfolio Data API""" 19 20 21__author__ = 'j.s@google.com (Jeff Scudder)' 22 23 24import atom.core 25import atom.data 26import gdata.data 27import gdata.opensearch.data 28 29 30GF_TEMPLATE = '{http://schemas.google.com/finance/2007/}%s' 31 32 33class Commission(atom.core.XmlElement): 34 """Commission for the transaction""" 35 _qname = GF_TEMPLATE % 'commission' 36 money = [gdata.data.Money] 37 38 39class CostBasis(atom.core.XmlElement): 40 """Cost basis for the portfolio or position""" 41 _qname = GF_TEMPLATE % 'costBasis' 42 money = [gdata.data.Money] 43 44 45class DaysGain(atom.core.XmlElement): 46 """Today's gain for the portfolio or position""" 47 _qname = GF_TEMPLATE % 'daysGain' 48 money = [gdata.data.Money] 49 50 51class Gain(atom.core.XmlElement): 52 """Total gain for the portfolio or position""" 53 _qname = GF_TEMPLATE % 'gain' 54 money = [gdata.data.Money] 55 56 57class MarketValue(atom.core.XmlElement): 58 """Market value for the portfolio or position""" 59 _qname = GF_TEMPLATE % 'marketValue' 60 money = [gdata.data.Money] 61 62 63class PortfolioData(atom.core.XmlElement): 64 """Data for the portfolio""" 65 _qname = GF_TEMPLATE % 'portfolioData' 66 return_overall = 'returnOverall' 67 currency_code = 'currencyCode' 68 return3y = 'return3y' 69 return4w = 'return4w' 70 market_value = MarketValue 71 return_y_t_d = 'returnYTD' 72 cost_basis = CostBasis 73 gain_percentage = 'gainPercentage' 74 days_gain = DaysGain 75 return3m = 'return3m' 76 return5y = 'return5y' 77 return1w = 'return1w' 78 gain = Gain 79 return1y = 'return1y' 80 81 82class PortfolioEntry(gdata.data.GDEntry): 83 """Describes an entry in a feed of Finance portfolios""" 84 portfolio_data = PortfolioData 85 86 87class PortfolioFeed(gdata.data.GDFeed): 88 """Describes a Finance portfolio feed""" 89 entry = [PortfolioEntry] 90 91 92class PositionData(atom.core.XmlElement): 93 """Data for the position""" 94 _qname = GF_TEMPLATE % 'positionData' 95 return_y_t_d = 'returnYTD' 96 return5y = 'return5y' 97 return_overall = 'returnOverall' 98 cost_basis = CostBasis 99 return3y = 'return3y' 100 return1y = 'return1y' 101 return4w = 'return4w' 102 shares = 'shares' 103 days_gain = DaysGain 104 gain_percentage = 'gainPercentage' 105 market_value = MarketValue 106 gain = Gain 107 return3m = 'return3m' 108 return1w = 'return1w' 109 110 111class Price(atom.core.XmlElement): 112 """Price of the transaction""" 113 _qname = GF_TEMPLATE % 'price' 114 money = [gdata.data.Money] 115 116 117class Symbol(atom.core.XmlElement): 118 """Stock symbol for the company""" 119 _qname = GF_TEMPLATE % 'symbol' 120 symbol = 'symbol' 121 exchange = 'exchange' 122 full_name = 'fullName' 123 124 125class PositionEntry(gdata.data.GDEntry): 126 """Describes an entry in a feed of Finance positions""" 127 symbol = Symbol 128 position_data = PositionData 129 130 131class PositionFeed(gdata.data.GDFeed): 132 """Describes a Finance position feed""" 133 entry = [PositionEntry] 134 135 136class TransactionData(atom.core.XmlElement): 137 """Data for the transction""" 138 _qname = GF_TEMPLATE % 'transactionData' 139 shares = 'shares' 140 notes = 'notes' 141 date = 'date' 142 type = 'type' 143 commission = Commission 144 price = Price 145 146 147class TransactionEntry(gdata.data.GDEntry): 148 """Describes an entry in a feed of Finance transactions""" 149 transaction_data = TransactionData 150 151 152class TransactionFeed(gdata.data.GDFeed): 153 """Describes a Finance transaction feed""" 154 entry = [TransactionEntry] 155 156