def __getstate__(self): file_path, module_name = None, None instance, callable_name, cls_name = None, None, None if inspect.isfunction(self._callable): callable_name = self._callable.__name__ file_path = inspect.getsourcefile(self._callable) module_name = os.path.splitext(os.path.basename(file_path))[0] elif inspect.isbuiltin(self._callable): callable_name = self._callable.__name__ module_name = 'builtin' elif inspect.ismethod(self._callable): file_path = inspect.getsourcefile(self._callable) module_name = os.path.splitext(os.path.basename(file_path))[0] cls_name = self._callable.__self__.__class__.__name__ instance = dumps(self._callable.__self__) callable_name = self.callable.__name__ # instance callable elif (not inspect.isclass(self._callable) and hasattr(self._callable, '__call__')): file_path = inspect.getsourcefile(self._callable.__call__) module_name = os.path.splitext(os.path.basename(file_path))[0] cls_name = self._callable.__class__.__name__ instance = dumps(self._callable) callable_name = '__call__' return (self._tid, file_path, module_name, cls_name, instance, callable_name, self._args, self._kwargs, self._created)
def getProgressLog(request): progressId = request.GET.get('id') cmdTypeName = request.GET.get('cmd') progressList = ProgressRateData.objects.order_by('created').filter(progressId=progressId,cmdTypeName=cmdTypeName) context['progressData'] = dumps(progressList) print dumps(progressList) return render_to_response('restApi/progressInfo.html',context)
def dump(self, fname): items = [] for item in self.items(self.get_table()): items.append(item) f = open(fname, "w") f.write(utils.dumps(items)) f.close()
async def add_message(*, chat_id, message='', action_type=None, request, db): values = { 'user': request['user'].id, 'chat': chat_id, 'message': message, } if action_type: values['action_type'] = action_type query = sa.insert(Message).values(**values).returning( Message.id, Message.message, Message.datetime, Message.action_type, ) message = await (await db.execute(query)).fetchone() message = dict(message) message['login'] = request['user'].login msg = dumps(message) if chat_id in request.app['websockets']: # pragma: no cover for ws in request.app['websockets'][chat_id]: # pragma: no cover ws.send_str(msg)
def create(user, **kwargs): position = Position( user=user, trading_account_username=user.trading_account_username, ) try: position.save() except Exception as e: position.logger.error('Error on saving doc') position.logger.error(e) position.logger.error(utils.dumps(kwargs)) position.edit(**kwargs) return position
def to_queue(value): if not value or type(value) != dict or "type" not in value: return False try: with queue_conn.connect(): with queue_conn.SimpleQueue(message_queue) as queue: value_str = utils.dumps(value) queue.put(value_str) #logger.error("enter queue: %s" % value_str) except: logger.error("%s" % traceback.format_exc()) return True
def vm_create(self, image, vlan, name=None, cpu=None, memory=None, increase=None, metadata={}): if image not in self.images(): raise ImageNotExist(image) if vlan not in self.vlans(): raise VlanNotExist(vlan) data = {'exec': 'launch_vm', 'image': image, 'vlan': vlan, 'name': name, 'cpu': cpu, 'memory': memory, 'disk_inc': increase, 'metadata': utils.dumps(metadata)} r = self.post(data=data) return r.text.strip()
def increase(self): underlying = {} for position in self.positions: for field in [ 'price', 'delta', 'gamma', 'vega', 'theta', 'daily_pnl', 'value' ]: if position.get(field) and position['security_type'] == 'OPT': position[field] *= random.uniform(.9, 1.1) position[field] = round(position[field], 2) underlying_price = position.get('underlying_price') symbol = position.get('symbol') if position['security_type'] != 'AGG': if not underlying.get(symbol): underlying[symbol] = underlying_price * random.uniform( 1 - .0001, 1 + .0001) position['underlying_price'] = round(underlying[symbol], 2) if position['security_type'] == 'STK': position['price'] = position['underlying_price'] multiplier = position.get('multiplier', 1) print(utils.dumps(position))
def dump(self, fname): response = self.get_table().scan() items = response['Items'] f = open(fname, "w") f.write(utils.dumps(items)) f.close()
# RUN APP # set routes of app app.router.add_routes(routes) # dev mode if "--dev" in sys.argv: logging.basicConfig(level=logging.DEBUG) logging.info("Developer mode (serving static content)") # Redirect / to /index.html (/ does not work) app.router.add_get("/", lambda _: web.HTTPFound('/index.html')) # Serve static content (order is important: files always last) app.add_routes([ web.get( "/version", lambda _: utils.dumps({ "commit_sha": "dev", "timestamp": utils.time_day() })) ]) app.router.add_get( "/version.json", lambda _: utils.dumps({ "commit_sha": f"{utils.time()}", "timestamp": f"{utils.time()}" })) app.router.add_static("/", "./frontend") web.run_app(app, port=80)
def edit(self, **kwargs): account_id = kwargs.get('account_id') position_id = kwargs.get('position_id') symbol = kwargs.get('symbol') daily_pnl = kwargs.get('daily_pnl') unrealized_pnl = kwargs.get('unrealized_pnl') security_type = kwargs.get('security_type') expiration_date = kwargs.get('expiration_date') multiplier = kwargs.get('mutliplier') strike = kwargs.get('strike') right = kwargs.get('right') delta = kwargs.get('delta') gamma = kwargs.get('gamma') vega = kwargs.get('vega') value = kwargs.get('value') theta = kwargs.get('theta') underlying_price = kwargs.get('underlying_price') price = kwargs.get('price') position = kwargs.get('position') underlying_pct_change = kwargs.get('underlying_pct_change') unrealized_pct_change = kwargs.get('unrealized_pct_change') pnl_pct_change = kwargs.get('pnl_pct_change') self.symbol = symbol self.security_type = security_type self.multiplier = multiplier self.right = right self.strike = strike self.account_id = account_id self.position_id = position_id self.expiration_date = expiration_date # for data that changes we only want # to update the fields if in fact there is data # and sometimes the pricing server if is_number(daily_pnl): self.daily_pnl = float(daily_pnl) if is_number(unrealized_pnl): self.unrealized_pnl = float(unrealized_pnl) if is_number(delta): self.delta = float(delta) if is_number(value): self.value = float(value) if is_number(gamma): self.gamma = float(gamma) if is_number(vega): self.vega = float(vega) if is_number(theta): self.theta = float(theta) if is_number(underlying_price): self.underlying_price = float(underlying_price) if is_number(price): self.price = float(price) if is_number(position): self.position = float(position) if is_number(underlying_pct_change): self.underlying_pct_change = float(underlying_pct_change) if is_number(unrealized_pct_change): self.unrealized_pct_change = float(unrealized_pct_change) if is_number(pnl_pct_change): self.pnl_pct_change = float(pnl_pct_change) self.updated_date = datetime.datetime.utcnow() try: self.save() except Exception as e: self.logger.error('Error on saving doc') self.logger.error(e) self.logger.error(utils.dumps(kwargs))
def enqueue(self, callable, args=None, kwargs=None, expire=None): task = Task(callable, args, kwargs) task_id = task.id self._conn.set(self.queue_item_key(task_id), dumps(task), ex=expire) self._conn.rpush(self.queue_key(), task_id) return task_id
def enqueue(self, task_id, result): self._conn.rpush(self.queue_key(), task_id) self._conn.set(self.queue_item_key(task_id), dumps(result))