本文整理汇总了Python中marketsim.context.bind函数的典型用法代码示例。如果您正苦于以下问题:Python bind函数的具体用法?Python bind怎么用?Python bind使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了bind函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: send
def send(self, order):
if order is not None:
if isinstance(order, types.IOrder):
order.owner = self
context.bind(order, self._ctx)
self._book.process(order)
return order
示例2: update
def update():
w = current_user_workspace()
parsed = request_parsed()
metaToCreate = dict([(int(Id), (meta[0], meta[1], meta[2])) for (Id, meta) in parsed['created']])
with w.world:
w.registry.createNewObjects(metaToCreate)
# changing fields for existing ones
for (Id, field, value) in parsed['updates']:
w.registry.setAttr(Id, field, value)
context.bind(w.registry.get(w.root), { "world" : w.world })
save_state_before_changes(w.registry)
save_current_workspace()
if 'limitTime' in parsed:
limitTime = parsed['limitTime']
timeout = parsed["timeout"]
run(w.world, timeout, limitTime)
save_current_workspace()
return changes(w)
示例3: run
def run(name, constructor):
with scheduler.create() as world:
ctx = Context(world, veusz.Graph)
traders = constructor(ctx)
books = orderBooksToRender(ctx, traders)
for t in traders + books:
for ts in t.timeseries:
ts.graph.addTimeSerie(ts)
r = registry.create()
root = registry.Simulation(traders, list(ctx.books.itervalues()), ctx.graphs)
r.insert(root)
r.pushAllReferences()
context.bind(root, {'world' : world })
world.workTill(500)
non_empty_graphs = [g for g in ctx.graphs if len(g._datas)]
veusz.render(name, non_empty_graphs)
world._reset()
context.reset(root)
if runTwoTimes:
world.workTill(500)
veusz.render(name, non_empty_graphs)
示例4: createSimulation
def createSimulation(name='All'):
with scheduler.create() as world:
myRegistry = registry.create()
myRegistry.insert(Side.Sell)
myRegistry.insert(Side.Buy)
ctx = Context(world, js.Graph)
dependency = strategy.v0.Dependency(ctx.book_B)
dependency_ex = strategy.Dependency(event.Every(mathutils.rnd.expovariate(1.)),
order.factory.side.Market(),
ctx.book_B)
def register(annotated_objects):
for obj, alias in annotated_objects:
if alias is not None:
obj._alias = alias
myRegistry.insert(obj)
register([
(dependency, ["Basic", "Dependency"]),
(dependency_ex, None),
])
myRegistry.pushAllReferences()
def process(name):
constructor = predefined[name]
traders = constructor(ctx)
books = orderBooksToRender(ctx, traders)
for t in traders + list(ctx.books.itervalues()) + ctx.graphs:
myRegistry.insert(t)
if name != 'All':
process(name)
else:
for n in predefined.iterkeys():
process(n)
myRegistry.insert(world)
root = myRegistry.insert(registry.createSimulation(myRegistry))
context.bind(myRegistry.get(root), { "world" : world })
if name != 'All':
current_dir = current_user_dir()
ensure_dir_ex(current_dir)
if os.path.exists(os.path.join(current_dir, name)):
i = 0
while os.path.exists(os.path.join(current_dir, name + "." + str(i))):
i += 1
name += '.' + str(i)
return name, root, myRegistry, world
示例5: send
def send(self, order):
from marketsim.gen._out._iorder import IOrder
if order is not None:
if isinstance(order, IOrder):
order.owner = self
context.bind(order, self._ctx)
self._book.process(order)
return order
示例6: run
def run(name, constructor, only_veusz):
with scheduler.create() as world:
ctx = Context(world, veusz.Graph)
traders = constructor(ctx)
if config.useMinorTraders:
traders.extend([
ctx.makeMinorTrader(strategy.RSI_linear(k = const(0.07)), "RSI 0.07"),
ctx.makeMinorTrader(strategy.RSI_linear(k = const(-0.07)), "RSI -0.07"),
ctx.makeMinorTrader(strategy.Bollinger_linear(alpha=0.15, k = const(-0.5)), "Bollinger -0.5"),
ctx.makeMinorTrader(strategy.Bollinger_linear(alpha=0.15, k = const(+0.5)), "Bollinger +0.5"),
])
books = orderBooksToRender(ctx, traders)
for t in traders + books:
for ts in t.timeseries:
ts.graph.addTimeSerie(ts)
r = registry.create()
root = registry.Simulation(traders, list(ctx.books.itervalues()), ctx.graphs)
r.insert(root)
r.pushAllReferences()
context.bind(root, {'world' : world })
if False:
req = request.EvalMarketOrder(Side.Sell, 500, _print)
world.schedule(10, _(ctx.remote_A, req).process)
def checks():
if not only_veusz and config.checkConsistency:
r.typecheck()
try:
dumped = pickle.dumps(r)
pickle.loads(dumped)
except Exception, err:
print err
checks()
stat = world.workTill(500)
checks()
if config.showTiming:
print "\n", stat
non_empty_graphs = [g for g in ctx.graphs if len(g._datas)]
veusz.render(name, non_empty_graphs)
world._reset()
context.reset(root)
if False and config.runTwoTimes:
world.workTill(500)
veusz.render(name, non_empty_graphs)
示例7: send
def send(self, book, order):
""" Sends 'order' to 'book'
After having the order sent notifies listeners about it
"""
context.bind(order, self._ctx)
if isinstance(order, types.IOrder):
order = self._makeSubscribedTo(order)
book.process(order)
if isinstance(order, types.IOrder):
self.on_order_sent.fire(order)
示例8: send
def send(self, book, order):
""" Sends 'order' to 'book'
After having the order sent notifies listeners about it
"""
from marketsim.gen._out._iorder import IOrder
context.bind(order, self._ctx)
if isinstance(order, IOrder):
order = self._makeSubscribedTo(order)
book.process(order)
if isinstance(order, IOrder):
self.on_order_sent.fire(order)
示例9: subscribe
def subscribe(event, listener, target = None, ctx = None):
subscription = Subscription(event, listener)
if target is not None:
if '_subscriptions' not in dir(target):
target._subscriptions = []
target._subscriptions.append(subscription)
if 'dispose' not in dir(target):
target.dispose = bind.Callable(dispose, target)
if ctx is not None:
context.bind(subscription, ctx)
return subscription
示例10: reset
def reset(self):
self.impl = self.getImpl()
ctx = getattr(self, '_ctx', None)
if ctx: context.bind(self.impl, ctx)
示例11: bind
def bind(self, ctx):
from marketsim import event, _, context
event.subscribe(self.queue.bestPrice, _(self).fire, self)
context.bind(self._subscriptions, ctx)