mirror of
https://github.com/wassname/catalyst.git
synced 2026-07-06 05:14:38 +08:00
sources as classes
This commit is contained in:
@@ -18,15 +18,15 @@ def date_sorted_sources(*sources):
|
||||
"""
|
||||
|
||||
for source in sources:
|
||||
assert source.__dict__.has_key('__init__')
|
||||
assert source.__dict__.has_key('get_hash')
|
||||
assert iter(source), "Source %s not iterable" % source
|
||||
assert source.__class__.__dict__.has_key('get_hash'), "No get_hash"
|
||||
|
||||
# Get name hashes to pass to date_sort.
|
||||
names = [source.get_hash for source in sources)
|
||||
names = [source.get_hash() for source in sources]
|
||||
|
||||
# Convert the list of generators into a flat stream by pulling
|
||||
# one element at a time from each.
|
||||
stream_in = roundrobin(source_gens, names)
|
||||
stream_in = roundrobin(sources, names)
|
||||
|
||||
# Guarantee the flat stream will be sorted by date, using source_id as
|
||||
# tie-breaker, which is fully deterministic (given deterministic string
|
||||
|
||||
@@ -23,7 +23,7 @@ if __name__ == "__main__":
|
||||
'delta' : timedelta(minutes = 1),
|
||||
'filter' : filter
|
||||
}
|
||||
bundle_a = SourceBundle(SpecificEquityTrades, args_a, kwargs_a)
|
||||
source_a = SpecificEquityTrades(*args_a, **kwargs_a)
|
||||
|
||||
#Set up source b. Two minutes between events.
|
||||
args_b = tuple()
|
||||
@@ -33,12 +33,12 @@ if __name__ == "__main__":
|
||||
'delta' : timedelta(minutes = 1),
|
||||
'filter' : filter
|
||||
}
|
||||
bundle_b = SourceBundle(SpecificEquityTrades, args_b, kwargs_b)
|
||||
source_b = SpecificEquityTrades(*args_b, **kwargs_b)
|
||||
|
||||
#Set up source c. Three minutes between events.
|
||||
|
||||
sort_out = date_sorted_sources(source_a, source_b)
|
||||
|
||||
|
||||
# passthrough = TransformBundle(Passthrough, (), {})
|
||||
# mavg_price = TransformBundle(MovingAverage, (timedelta(minutes = 20), ['price']), {})
|
||||
# tnfm_bundles = (passthrough, mavg_price)
|
||||
|
||||
Reference in New Issue
Block a user