forked from yiransheng/Option-Quotes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
97 lines (80 loc) · 2.58 KB
/
models.py
File metadata and controls
97 lines (80 loc) · 2.58 KB
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
import datetime
import sys
import urllib2
from google.appengine.ext import db
FETCH_THEM_ALL = 65535
class Option(db.Model):
symbol = db.StringProperty(required=True)
date = db.DateProperty(required=True, auto_now_add=True)
expiration = db.DateProperty()
type = db.StringProperty(required=True, choices=set([u"calls",u"puts"]))
contractname = db.StringProperty()
strike = db.FloatProperty()
last = db.FloatProperty()
change = db.FloatProperty()
bid = db.FloatProperty()
ask = db.FloatProperty()
underlying = db.FloatProperty()
volume = db.IntegerProperty()
openinterest = db.IntegerProperty()
@classmethod
def to_dict(self):
return dict([(p, unicode(getattr(self, p))) for p in self.properties()])
@classmethod
def get_all(cls):
q = db.Query(Option)
q.order('-date')
return q.fetch(FETCH_THEM_ALL)
@classmethod
def get_all_symbol(cls, symbol):
q = db.Query(Option)
q.filter('symbol = ', symbol)
q.order('-date')
return q.fetch(FETCH_THEM_ALL)
@classmethod
def get(cls, symbol, date, expiration):
q = db.Query(Option)
q.filter('symbol = ', symbol)
q.filter('date = ', date)
q.filter('expiration = ', expiration)
return q.fetch(FETCH_THEM_ALL)
def __unicode__(self):
return self.__str__()
def __str__(self):
return '[%s] %s' %\
(self.date.strftime('%Y/%m/%d'), self.contractname)
class OptionData(db.Model):
symbol = db.StringProperty(required=True)
date = db.DateProperty(required=True, auto_now_add=True)
expiration = db.DateProperty()
data = db.TextProperty(required=True)
id = db.StringProperty(required=True)
@classmethod
def get_all(cls):
q = db.Query(OptionData)
q.order('-date')
return q.fetch(FETCH_THEM_ALL)
@classmethod
def get_all_symbol(cls, symbol):
q = db.Query(OptionData)
q.filter('symbol = ', symbol)
q.order('-date')
return q.fetch(FETCH_THEM_ALL)
@classmethod
def get(cls, id):
q = db.Query(OptionData)
q.filter('id = ', id)
return q.get()
class Stock(db.Model):
symbol = db.StringProperty(required=True)
cboe_id = db.StringProperty()
exp_months = db.ListProperty(datetime.date)
@classmethod
def get_all(cls):
q = db.Query(Stock)
return q.fetch(FETCH_THEM_ALL)
@classmethod
def get(cls,symbol):
q = db.Query(Stock)
q.filter('symbol = ', symbol)
return q.get()