flask
bianlidou
这个作者很懒,什么都没留下…
展开
-
flask sqlalchemy查询多个不确定条件
如下图:用户手机号,策略类型等等都是可选,有可能只筛选一个或多个条件,这时候是不能用枚举法去写代码的,这样太多了。然后开始找答案,有人是这样说的:链接然后照着做了,然后就是在filter_by的时候把引号去掉然后,报错了。。如果是直接写进去就不会报错,也就是直接.filter_by(phone=13012345678,api_type=4001), 这样就不会报错,真是百思不得其解最后其实很简单,就是用sqlalchemy的**or_**即可,把所有的条件的都写进去,它会帮我们筛选出有值原创 2021-12-09 19:22:34 · 2458 阅读 · 6 评论 -
flask + gunicorn + nginx 运行一段时间后明显很卡
a原创 2021-08-03 09:26:49 · 981 阅读 · 0 评论 -
flask项目多进程出现 ‘Broken pipe’ “Command out of sync” ”gone away“等问题及解决
最近的项目需求是对量化策略进行回测,由于是cpu密集型操作,由于python GIL锁机制,使用多线程不适合,协程的话也不能。因此考虑多进程,代码里开的进程池只要是2及2以上,一定会出现 ‘Broken pipe’ “Command out of sync” ”gone away"等问题,由于涉及到与mysql数据库的ORM操作,上网查找这个(pymysql.err.OperationalError) (2006, “MySQL server has gone away (BrokenPipeError(原创 2021-08-02 19:56:18 · 984 阅读 · 0 评论 -
(pymysql.err.OperationalError) (2006, “MySQL server has gone away (BrokenPipeError(32, ‘Broken pipe‘
flask 项目运行了一段时间,mysql报错 (pymysql.err.OperationalError) (2006, “MySQL server has gone away (BrokenPipeError(32, ‘Broken pipe’))”),根据查询资料 https://dev.mysql.com/doc/refman/5.7/en/gone-away.html,原因是服务器超时并关闭了连接,所以再去操作的时候就连接不上了。根据官方说法,我们可以设置wait_timeout时间长一点,通原创 2021-06-15 12:36:12 · 1932 阅读 · 0 评论 -
flask orm 查询多张无关联的表
如图,由于网格量化,抄底策略,合约策略等等,不在同一张数据表里,它们都是各自互不关联的表,如何按照时间倒叙排序呢,这里用到 union_all 这个用法,代码如下:result1 = db.session.query(BottomStrategy.id, BottomStrategy.strategy_type,BottomStrategy.status, BottomStrategy.strategy_name, B.原创 2021-06-10 09:40:28 · 249 阅读 · 0 评论 -
flask 后台新增或修改交易币对触发自动获取各个平台的交易对价格
需求:当后台新增或修改交易币对时,触发自动获取各个平台的交易对价格如下图,在flask视图中新增或者修改了交易币对,就调用restart_get_new_price()这个函数即可def get_process_id(name): import subprocess child = subprocess.Popen(["pgrep", "-f", name], stdout=subprocess.PIPE, shell=False) response = child.comm原创 2021-05-12 16:28:07 · 132 阅读 · 0 评论 -
flask sqlachemy 查询 先分组再排序
需求:根据交易币对,回测时间提取出年化收益率最高的出来,放到最优策略参数那里,如下图效果如下图:我心想,这还不简单,先来个group_by 交易币对,回测时间,再来个order_by 年化收益率,分分钟搞出来,事实证明,我有点年轻,先看这样写的效果best_param = db.session.query(BottomBacktestStrategy).group_by(BottomBacktestStrategy.symbol,原创 2021-05-08 10:13:34 · 859 阅读 · 3 评论 -
flask orm 查询2个时间段内的值
from datetime import datetimestart_time = datetime(2021,4,10,0,0,1) # 指的是2021/4/10 00:00:01end_time = datetime(2021,4,10,1,1,1)datas = HistoryTrades.query.filter(start_time <= HistoryTrades.create_time_stamp,HistoryTrades.create_time_stamp <= end_原创 2021-04-14 20:05:39 · 801 阅读 · 0 评论 -
Postman Collection Format v1 is no longer supported and can not be imported directly. You may conver
1 invalid import format(s)Postman Collection Format v1 is no longer supported and can not be imported directly. You may convert your collection to Format v2and try importing again.如图,导入json数据到postman的时候报错原因是我的gtrading.json格式是v1版本,postman已经不再支持了,需要转成v2原创 2021-03-29 14:09:10 · 4459 阅读 · 0 评论 -
AttributeError: module ‘sqlalchemy‘ has no attribute ‘NullType‘
flask框架在执行数据库迁移命令migrate之后upgrade,报这个错,将这个表删掉再从头开始迁移数据库即可,先删掉migrations目录,再依次init, migrate,upgrade原创 2021-03-11 18:07:33 · 3935 阅读 · 1 评论 -
解决flask报错:RuntimeError: Working outside of application context.
先看报错:RuntimeError: Working outside of application context.This typically means that you attempted to use functionality thatneeded to interface with the current application object in some way.To solve this, set up an application context with app.app_con原创 2021-01-04 14:31:14 · 19873 阅读 · 3 评论