当前位置: 首页 > 工具软件 > Chart-GPT > 使用案例 >

chat-gpt写的5分钟macd顶底背离监测

弘承业
2023-12-01

# -*- coding: utf-8 -*-
import time
import requests
import json
import talib

# 币安交易所API
url = 'https://fapi.binance.com/fapi/v1/klines?symbol=BTCUSDT&interval=5m&limit=1000'

while True:
    try:
        # 获取K线数据
        response = requests.get(url).text
        klines = json.loads(response)
        # 计算macd
        close = [float(x[4]) for x in klines]
        macd, signal, hist = talib.MACD(close, fastperiod=12, slowperiod=26, signalperiod=9)
        # 判断顶背离
        if macd[-1] > signal[-1] and macd[-2] < signal[-2]:
            print('发现顶背离!')
        # 判断底背离
        if macd[-1] < signal[-1] and macd[-2] > signal[-2]:
            print('发现底背离!')
        # 每5分钟检测一次
        time.sleep(300)
    except Exception as e:
        print(e)
里插入代码片
 类似资料: