栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

【python量化】Python自动化操作钉钉发送量化交易信息

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

【python量化】Python自动化操作钉钉发送量化交易信息

钉钉实现效果 工具模块

dingdingtalk / utils / tools001.py

import time

# 001-打印时间
def get_now_time(bool_value = 1):
    """ 默认bool_value为true表示打印当前时分秒"""
    if bool_value:
        return time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))
    else:
        return time.strftime('%Y-%m-%d',time.localtime(time.time()))
消息发送封装模块
import json
import requests
from utils import tools001

# 1、结合 requests 发送消息
HEADERS = {"Content-Type": "application/json;charset=utf-8"}

# 加密方式1
secret_key_words = "【量化推送】"

## 钉钉群地址
url = "https://oapi.dingtalk.com/robot/send?access_token=2d4e5bc62254d55c69f0cd055a9087604abceb456bfd0e0wedb02df5a30bea2d4"

# 推送标的交易信息
def send_finance_info(bool_value, buy_sell_signal, fin_name, fin_code, trade_num, trade_price, reason):
    '''
        bool_value: 是否打印出时分秒,默认已打印
        buy_sell_signal: 买卖信号, 做多为1, 做空为0, 其他无操作
        fin_name: 标的名称
        fin_code: 标的代码
        trade_num: 交易数量
        trade_price: 交易价位
        reason: 推荐理由
    '''
    if buy_sell_signal == 1:
        buy_sell_direction = 'buy(买入)'
    elif buy_sell_signal == 0:
        buy_sell_direction = 'sell(卖出)'
    else:
        buy_sell_direction = 'error(无操作)'


    now_date_time = tools001.get_now_time(bool_value)
    content00 = '******************************************************'
    content01 = 'n' + secret_key_words + now_date_time + 'n'
    content02 = '  交易时间: ' + now_date_time + 'n'
    content03 = '  标的名称: ' + fin_name + 'n'
    content04 = '  标的编码: ' + fin_code + 'n'
    content05 = '  头寸方向: ' + buy_sell_direction + 'n'
    content06 = '  交易数量: ' + str(trade_num) + ' (手数) n'
    content07 = '  交易价位: ' + str(trade_price[0]) + '至' + str(trade_price[1]) + ' (元) n'

    content08 = '  推荐理由: ' + reason + 'n'
    content09 = '******************************************************' + 'n'

    content = content00 + content01 + content02 + content03 + content04 + content05  + content06 + content07 + content08 + content09
    return content

content = send_finance_info(True, 1, '平安银行', '000001', 20, [14.35,14.45] ,'该支标的目前已经跌倒低谷建议抄底入手')

data = {
    "msgtype": "text",  # sgtype 为消息类型,“text” 为普通文本
    "text": {
        "content": content
    },
    "isAtAll": True     # isAtAll 为布尔值,是否 @ 所有人,如果设置为 False,可以通过 atMobiles,@指定人(atMobiles 处配置手机号码)
}

response = requests.post(url, json.dumps(data), headers=HEADERS)

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/961598.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号