コード例 #1
0
    def query_data(self, symbol='', timestamp=None, n_bars=None, from_timestamp=None):
        """
        Queries and caches pricebar data
        """
        if not n_bars and not from_timestamp:
            raise Exception('query_data requires oen of n_bars or from_timestamp to be specified')

        if not symbol:
            symbol = self.instrument.symbol
        if not timestamp:
            timestamp = self.timestamp


        if symbol not in DataCache().query_cache:
            print 'querying http server'
            try:
                data = self.api.pricebar.get(symbol = symbol, order_by = 'timestamp', limit=0)
            except Exception, e:
                print 'http server error: %s' % e.message

            for obj in data['objects']:
                if 'timestamp' in obj:
                    obj['timestamp'] = parsedt(obj['timestamp'])
                if 'date' in obj:
                    obj['date'] = parsedt(obj['date']).date()
            DataCache().query_cache[symbol] = [DotDict(i) for i in data['objects']]
コード例 #2
0
def get_typed_value(datatype, value):

    if datatype == date:
        return parsedt(value).date()
    if datatype == datetime:
        return parsedt(value)
    if datatype == Decimal:
        return Decimal(value)
    if datatype == float:
        return float(value)

    return value  #: Returns string or object content as is
コード例 #3
0
    def dict_to_object(self, d):
        if '__type__' not in d:
            return d

        thetype = d.pop('__type__')
        thevalue = d['value']
        if thetype == 'datetime':
            return parsedt(thevalue)
        elif thetype == 'date':
            return parsedt(thevalue).date()
        elif thetype == 'timedelta':
            return timedelta(seconds=float(thevalue))
        elif thetype == 'objectid' and ObjectId is not None:
            return ObjectId(oid=thevalue)
        else:
            d['__type__'] = thetype
            return d
コード例 #4
0
    def dict_to_object(self, d):
        if "__type__" not in d:
            return d

        thetype = d.pop("__type__")
        thevalue = d["value"]
        if thetype == "datetime":
            return parsedt(thevalue)
        elif thetype == "date":
            return parsedt(thevalue).date()
        elif thetype == "timedelta":
            return timedelta(seconds=float(thevalue))
        elif thetype == "objectid" and ObjectId is not None:
            return ObjectId(oid=thevalue)
        else:
            d["__type__"] = thetype
            return d
コード例 #5
0
    def has_upcoming_earnings(self, num_days):
        """
        Gets upcoming earnings over API
        TODO: need an API call here
        """
        if not self._earnings_announcements_cache:
            data = self.api.earnings_announcement(instrument__id = self.instrument.id, order_by = 'datestamp')
            for obj in data['objects']:
                if 'datestamp' in obj:
                    obj['datestamp'] = parsedt(obj['datestamp'])
            self._earnings_announcements_cache = [DotDict(i) for i in data['objects']]

        dt = self.timestamp + timedelta(days = num_days)

        for ea in self._earnings_announcements_cache:
            if ea.instrument.id != self.instrument.id:
                continue

            if self.useralgo.timestamp.date() <= ea.datestamp <= dt.date():
                return True

        return False
コード例 #6
0
ファイル: utils.py プロジェクト: nanuxbe/bungiesearch
def __str_to_tzdate__(date_str):
    return timezone.make_aware(parsedt(date_str),
                               timezone.get_current_timezone())
コード例 #7
0
                        '--reso',
                        required=True,
                        help='the resolution transformation',
                        type=str)
    args = parser.parse_args()

    # Parse the resolution
    unit = args.reso[-1]
    resolution_units = {'d': 'days', 'm': 'minutes', 's': 'seconds'}
    if unit not in resolution_units:
        raise ValueError("unknown unit " + unit)
    reso_num = int(args.reso[0])  # Let it raise.
    deltaargs = {resolution_units[unit]: reso_num}
    year = int(args.year)  # Let is raise
    print('Generating {} ephemeride for {}'.format(args.planet, year))
    start_date = parsedt('{}-01-01'.format(year))
    end_date = parsedt('{}-01-01'.format(year + 1))

    _load_kernels_()
    outdir = os.path.dirname(
        os.path.abspath(__file__)) + '/../../data/horizon/'
    path = outdir + args.planet + '-' + str(start_date.year) + '.csv'
    f = open(path, 'w')
    prev_month = 0
    while start_date <= end_date:
        if prev_month != start_date.month:
            prev_month = start_date.month
            print('Generating for month ' + str(prev_month))
        date_str = '{0.year}-{0.month}-{0.day}T{0.hour}:{0.minute}:{0.second}.{0.microsecond}'.format(
            start_date)
        et = spice.str2et(date_str)
コード例 #8
0
ファイル: utils.py プロジェクト: afrancis13/bungiesearch
def __str_to_tzdate__(date_str):
    return timezone.make_aware(parsedt(date_str), timezone.get_current_timezone())
コード例 #9
0
ファイル: settings.py プロジェクト: jajberni/PyRTM
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with PyRTM.  If not, see <http://www.gnu.org/licenses/>.
"""

from dateutil.parser import parse as parsedt

defaults = {
    'description': 'Default Config',  # use internally; any string
    'solar_constant': 1367,  # W/m^2 in space
    'season': 'summer',  # summer or winter
    'time':
    parsedt('2012-10-11 12:00:00 -0500'),  # specifying tz is important!
    'latitude': 44,  # degrees, north-positive
    'longitude': 283.7,  # degrees, east-positive
    'elevation': 0,  # metres above sea level
    'surface_type': 'vegetation',  # see docs for valid options
    'single_scattering_albedo': 0.8,
    'atmosphere': 'sub-arctic summer',  # see docs for valid options
    'average_daily_temperature': 15,  # degrees C
    'temperature': 15,  # degrees C
    'pressure': 1013.250,  # mb
    'relative_humidity': 35,  # %
    'angstroms_coefficient': 0.08,
    'angstroms_exponent': 1.1977,
    'aerosol_asymmetry': 0.6,
    'boundary_layer_ozone': 0.3,  # atm-cm
コード例 #10
0
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with PyRTM.  If not, see <http://www.gnu.org/licenses/>.
"""

from dateutil.parser import parse as parsedt

defaults = {
    'description': 'Default Config', # use internally; any string
    
    'solar_constant': 1367, # W/m^2 in space
    
    'season': 'summer', # summer or winter
    'time': parsedt('2012-10-11 12:00:00 -0500'), # specifying tz is important!
    'latitude': 44, # degrees, north-positive
    'longitude': 283.7, # degrees, east-positive
    'elevation': 0, # metres above sea level
    'surface_type': 'vegetation', # see docs for valid options
    'single_scattering_albedo': 0.8,

    'atmosphere': 'sub-arctic summer', # see docs for valid options
    'average_daily_temperature': 15, # degrees C
    'temperature': 15, # degrees C
    'pressure': 1013.250, # mb
    'relative_humidity': 35, # %
    'angstroms_coefficient': 0.08,
    'angstroms_exponent': 1.1977,
    'aerosol_asymmetry': 0.6, 
    'boundary_layer_ozone': 0.3, # atm-cm