【ChatGPT】AIでFX注文履歴をブログに付けていこうと思い作ったPython

目的・目標

FXの購入日記ブログを書くための補助ツールを作る。
ChatGPTで以下のようなプロンプトで指示を出してプログラムを出力してもらう。

IFDで注文をかけるので利用方法に則したプログラムを開発してもらう。

プログラム本体

プロンプト:

FXの戦略日記ブログ用のプログラムを開発したいです。基本的にIFD注文をするので以下のような条件でHTMLをかけるようにGUIで構成して下さい。GUIで構成。通貨選択(チェックリスト)(デフォルトはドル円)一般的な通貨を表示させてください、IFD注文(新規)金額 円、買い売りポジション選択(チェックリスト)、指値or逆指値選択(チェックリスト)、決済注文金額 金額 円、考察(入力欄)。生成しますか?OKボタン はい:入力した内容からちそれぞれの項目を分析してブログ用のHTMLを生成する。日付と時間を記載するようにする。

出力:

import tkinter as tk
from tkinter import ttk, messagebox
from datetime import datetime # 追加

# 通貨のリスト(代表的なもの)
currency_options = [
"USD/JPY", "EUR/JPY", "GBP/JPY", "AUD/JPY", "NZD/JPY",
"EUR/USD", "GBP/USD", "USD/CHF", "USD/CAD", "AUD/USD"
]

# GUIアプリの構築
class FXBlogGUI:
def __init__(self, root):
self.root = root
self.root.title("FX戦略日記HTMLジェネレーター")

# 通貨選択
ttk.Label(root, text="通貨ペア:").grid(row=0, column=0, sticky="w")
self.currency_var = tk.StringVar(value="USD/JPY")
self.currency_menu = ttk.Combobox(root, textvariable=self.currency_var, values=currency_options, state="readonly")
self.currency_menu.grid(row=0, column=1)

# 新規注文金額
ttk.Label(root, text="新規注文金額(円):").grid(row=1, column=0, sticky="w")
self.entry_amount = ttk.Entry(root)
self.entry_amount.grid(row=1, column=1)

# 買い/売りポジション
ttk.Label(root, text="ポジション:").grid(row=2, column=0, sticky="w")
self.position_var = tk.StringVar()
ttk.Radiobutton(root, text="買い", variable=self.position_var, value="買い").grid(row=2, column=1, sticky="w")
ttk.Radiobutton(root, text="売り", variable=self.position_var, value="売り").grid(row=2, column=1)

# 指値/逆指値
ttk.Label(root, text="注文タイプ:").grid(row=3, column=0, sticky="w")
self.order_type_var = tk.StringVar()
ttk.Radiobutton(root, text="指値", variable=self.order_type_var, value="指値").grid(row=3, column=1, sticky="w")
ttk.Radiobutton(root, text="逆指値", variable=self.order_type_var, value="逆指値").grid(row=3, column=1)

# 決済注文金額
ttk.Label(root, text="決済注文金額(円):").grid(row=4, column=0, sticky="w")
self.entry_settlement = ttk.Entry(root)
self.entry_settlement.grid(row=4, column=1)

# 考察欄
ttk.Label(root, text="考察:").grid(row=5, column=0, sticky="nw")
self.text_thoughts = tk.Text(root, width=40, height=5)
self.text_thoughts.grid(row=5, column=1)

# OKボタン
self.ok_button = ttk.Button(root, text="生成しますか?", command=self.generate_html)
self.ok_button.grid(row=6, column=1, pady=10)

def generate_html(self):
# 入力内容を取得
currency = self.currency_var.get()
amount = self.entry_amount.get()
position = self.position_var.get()
order_type = self.order_type_var.get()
settlement = self.entry_settlement.get()
thoughts = self.text_thoughts.get("1.0", "end").strip()

if not all([currency, amount, position, order_type, settlement]):
messagebox.showerror("エラー", "すべての項目を入力してください。")
return

# 現在の日付と時間を取得
now = datetime.now()
date_str = now.strftime("%Y年%m月%d日 %H:%M")

# HTML生成
html_output = f"""
<div class="fx-diary-entry">
<h2>本日のFX戦略({currency})</h2>
<p><strong>記録日時:</strong> {date_str}</p>
<ul>
<li>新規注文金額: {amount} 円</li>
<li>ポジション: {position}</li>
<li>注文タイプ: {order_type}</li>
<li>決済注文金額: {settlement} 円</li>
</ul>
<h3>考察</h3>
<p>{thoughts}</p>
</div>
"""

# 結果を表示
result_window = tk.Toplevel(self.root)
result_window.title("生成されたHTML")
text = tk.Text(result_window, wrap="word")
text.insert("1.0", html_output)
text.pack(expand=True, fill="both")

# 実行
if __name__ == "__main__":
root = tk.Tk()
app = FXBlogGUI(root)
root.mainloop()

改善

CSSが指定されていたのでCSSも出力してもらう

CSSはワードプレスなのでカスタマイズから入力することを想定してもらっています。

CSS本体

プロンプト:

<div class="fx-diary-entry"> fx-diary-entryをブログ用CSSで生成してください。グレー基調で記載のHTMLの内容に即したスタイルにしてください。

出力:

.fx-diary-entry {
background-color: #f6f6f6;
border-left: 6px solid #999;
padding: 1.5em;
margin: 2em 0;
font-family: 'Helvetica Neue', sans-serif;
color: #333;
box-shadow: 2px 2px 10px rgba(0, 0, 0, 0.05);
border-radius: 12px;
}

.fx-diary-entry h2 {
margin-top: 0;
font-size: 1.5em;
color: #444;
border-bottom: 2px solid #ccc;
padding-bottom: 0.2em;
}

.fx-diary-entry p {
margin: 0.5em 0;
line-height: 1.6;
}

.fx-diary-entry ul {
padding-left: 1.2em;
margin: 1em 0;
list-style-type: square;
color: #555;
}

.fx-diary-entry ul li {
margin-bottom: 0.5em;
font-weight: 500;
}

.fx-diary-entry h3 {
font-size: 1.2em;
margin-top: 1.5em;
color: #666;
border-bottom: 1px solid #bbb;
padding-bottom: 0.2em;
}

生成したHTML

本日のFX戦略(USD/JPY)

記録日時: 2025年04月24日 06:58

  • 新規注文金額: 150 円
  • ポジション: 売り
  • 注文タイプ: 逆指値
  • 決済注文金額: 150.5 円

考察

150円で買う。50pipsで逆指値。