-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstockAnalyzer_api.py
132 lines (106 loc) · 5.56 KB
/
stockAnalyzer_api.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
"""Hello World API implemented using Google Cloud Endpoints.
Defined here are the ProtoRPC messages needed to define Schemas for methods
as well as those methods defined in an API.
"""
import endpoints
from protorpc import messages
from protorpc import message_types
from protorpc import remote
from main import *
package = 'stockAnalyzer'
class Greeting(messages.Message):
"""Greeting that stores a message."""
message = messages.StringField(1)
class GreetingCollection(messages.Message):
"""Collection of Greetings."""
items = messages.MessageField(Greeting, 1, repeated=True)
STORED_GREETINGS = GreetingCollection(items=[
Greeting(message='hello world!'),
Greeting(message='goodbye world!'),
])
class StockAnalyzerResponseMessage(messages.Message):
ticker = messages.StringField(1, required=True)
recommendation= messages.StringField(2, required=True)
price = messages.StringField(3);
pe = messages.FloatField(4);
pegRatio = messages.FloatField(5);
debtToEquity= messages.StringField(6);
qRevGrowth = messages.StringField(7);
divYield= messages.StringField(8);
isPeOk=messages.BooleanField(9);
isPegOk=messages.BooleanField(10);
isQRevGrowthOk=messages.BooleanField(11);
isDivYieldOk=messages.BooleanField(12);
isDebtOk=messages.BooleanField(13);
tickerName= messages.StringField(14);
optimalPeRatio = messages.FloatField(15);
optimalPegRatio = messages.FloatField(16);
optimalDebtToEquity = messages.FloatField(17);
optimalYield= messages.FloatField(18);
optimalQRevGrowth= messages.FloatField(19);
optimalBeta = messages.FloatField(20);
class StockAnalyzerRequestMessage(messages.Message):
ticker = messages.StringField(1);
configType= messages.StringField(2);
@endpoints.api(name='stockAnalyzer', version='v1')
class StockAnalyzer(remote.Service):
"""StockAnalyzer API v1."""
@endpoints.method(message_types.VoidMessage, GreetingCollection,
path='hellogreeting', http_method='GET',
name='greetings.listGreeting')
def greetings_list(self, unused_request):
return STORED_GREETINGS
ID_RESOURCE = endpoints.ResourceContainer(
message_types.VoidMessage,
id=messages.IntegerField(1, variant=messages.Variant.INT32))
@endpoints.method(ID_RESOURCE, Greeting,
path='hellogreeting/{id}', http_method='GET',
name='greetings.getGreeting')
def greeting_get(self, request):
try:
return STORED_GREETINGS.items[request.id]
except (IndexError, TypeError):
raise endpoints.NotFoundException('Greeting %s not found.' %
(request.id,))
@endpoints.method( StockAnalyzerRequestMessage, StockAnalyzerResponseMessage,
path='stockAnalyzer', http_method='GET',
name='stockAnalyzer.getInfo')
def stockAnalyzer_getInfo(self, request):
try:
# response = request.ticker;
""" Adding Code """
configType= request.configType;
optimalValues=getOptimalValues( configType )
if ( request.ticker != "" ):
templateValues=getRecommendation(request.ticker, optimalValues)
else:
templateValues = {
'ticker': request.ticker,
'keyCount': 0,
'recommendation': "*** Please enter a valid Ticker ***"
}
""" End Added Code """
return StockAnalyzerResponseMessage( ticker=request.ticker
, recommendation= templateValues['recommendation']
, price= templateValues['price']
,pe = templateValues['pe']
,pegRatio =templateValues['pegRatio']
,debtToEquity =templateValues['debtToEquity']
,qRevGrowth =templateValues['qRevGrowth']
,divYield =templateValues['divYield']
,isPeOk=templateValues['isPeOk']
,isPegOk=templateValues['isPegOk']
,isQRevGrowthOk=templateValues['isQRevGrowthOk']
,isDivYieldOk=templateValues['isDivYieldOk']
,isDebtOk=templateValues['isDebtOk']
,tickerName=templateValues['tickerName']
,optimalPeRatio=templateValues['optimalPeRatio']
,optimalPegRatio=templateValues['optimalPegRatio']
,optimalDebtToEquity=templateValues['optimalDebtToEquity']
,optimalYield=templateValues['optimalYield']
,optimalQRevGrowth=templateValues['optimalQRevGrowth']
,optimalBeta=templateValues['optimalBeta']
);
except (IndexError, TypeError):
raise endpoints.NotFoundException('Got Exception');
APPLICATION = endpoints.api_server([StockAnalyzer])