diff --git a/metrik/__init__.py b/metrik/__init__.py index 561af6b..28f4b13 100644 --- a/metrik/__init__.py +++ b/metrik/__init__.py @@ -1,2 +1,2 @@ -__version__ = '0.3.4' +__version__ = '0.3.5' __release__ = __version__ \ No newline at end of file diff --git a/metrik/tasks/tradeking.py b/metrik/tasks/tradeking.py index 403b354..59df70a 100644 --- a/metrik/tasks/tradeking.py +++ b/metrik/tasks/tradeking.py @@ -48,26 +48,33 @@ class Tradeking1mTimesales(MongoCreateTask): interval=timedelta(minutes=1) ) if did_acquire: - json_data = tradeking.api_request('market/timesales', { + response = tradeking.api_request('market/timesales', { 'symbols': symbol, 'interval': '1min', 'startdate': present.strftime('%Y-%m-%d'), 'enddate': present.strftime('%Y-%m-%d') - }).json() + }) + json_data = response.json() quotes = json_data['response']['quotes']['quote'] + def format_quote(quote): - return { - 'last': float(quote['last']), - 'lo': float(quote['lo']), - 'vl': int(quote['vl']), - 'datetime': parse(quote['datetime']), - 'incr_vl': int(quote['incr_vl']), - 'hi': float(quote['hi']), - 'timestamp': parse(quote['timestamp']), - 'date': parse(quote['date']), - 'opn': float(quote['opn']) - } + if quote == '': + logging.warning('Empty quote for symbol {}'.format(symbol)) + return {} + else: + return { + 'last': float(quote['last']), + 'lo': float(quote['lo']), + 'vl': int(quote['vl']), + 'datetime': parse(quote['datetime']), + 'incr_vl': int(quote['incr_vl']), + 'hi': float(quote['hi']), + 'timestamp': parse(quote['timestamp']), + 'date': parse(quote['date']), + 'opn': float(quote['opn']) + } + quotes_typed = [format_quote(q) for q in quotes] return {