From a8871af4e73219ecbcee699049f341533ae9cdb7 Mon Sep 17 00:00:00 2001 From: bspeice Date: Thu, 24 Nov 2016 18:33:52 -0500 Subject: [PATCH] Add a flow for options quotes --- metrik/__init__.py | 2 +- metrik/flows/options_flow.py | 23 +++++++++++++++++++++++ metrik/tasks/tradeking.py | 3 +-- 3 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 metrik/flows/options_flow.py diff --git a/metrik/__init__.py b/metrik/__init__.py index ba0e4af..fa7fdae 100644 --- a/metrik/__init__.py +++ b/metrik/__init__.py @@ -1,2 +1,2 @@ -__version__ = '0.4.2' +__version__ = '0.5.0' __release__ = __version__ \ No newline at end of file diff --git a/metrik/flows/options_flow.py b/metrik/flows/options_flow.py new file mode 100644 index 0000000..1644cf7 --- /dev/null +++ b/metrik/flows/options_flow.py @@ -0,0 +1,23 @@ +from metrik.flows.base import Flow, MarketClose +from metrik.conf import get_config +from metrik.tasks.cboe import CboeOptionableList +from metrik.tasks.tradeking import TradekingOptionsQuotes + +class EquitiesFlow(Flow): + def __init__(self, *args, **kwargs): + super(EquitiesFlow, self).__init__(*args, **kwargs) + + @staticmethod + def get_schedule(): + return MarketClose() + + def _run(self): + optionable = CboeOptionableList(current_datetime=self.present, + live=self.live) + yield optionable + + options_quotes = [TradekingOptionsQuotes(symbol=s, + current_datetime=self.present, + live=self.live) + for s in optionable.output().retrieve()['companies']] + yield options_quotes \ No newline at end of file diff --git a/metrik/tasks/tradeking.py b/metrik/tasks/tradeking.py index ba361a4..1e7b227 100644 --- a/metrik/tasks/tradeking.py +++ b/metrik/tasks/tradeking.py @@ -134,7 +134,6 @@ class TradekingOptionsQuotes(MongoNoBackCreateTask): if not chain_acquire: return {} - chain = TradekingOptionsQuotes.retrieve_chain_syms(api, symbol) results = [] for b in batch(chain, TradekingOptionsQuotes.batch_size): @@ -147,4 +146,4 @@ class TradekingOptionsQuotes(MongoNoBackCreateTask): batch_results = TradekingOptionsQuotes.retrieve_quotes(api, b) results += batch_results - return results + return {'symbol': symbol, 'chain': results}