반응형
✅ 왜 자동 리포트 시스템이 필요한가요?
- 매매 결과를 기록하지 않으면 전략의 유효성 추적이 어렵습니다.
- 수동 기록은 번거롭고 누락되기 쉽습니다.
- 실행 → 기록 → 공유까지 자동화하면 운영 효율 극대화!
📊 STEP 1. Google Sheets 자동 기록 (C# + 서비스 계정)
🔸 사전 준비
- Google Cloud Console 접속
- Sheets API + Drive API 활성화
- 서비스 계정 생성 → .json 키파일 다운로드
- 구글 시트 공유 → 서비스 계정 이메일에게 편집 권한 부여
📘 참조: Google Sheets API 문서
🔸 C# 코드 (Sheets 기록용 NuGet 라이브러리 필요)
bash
Install-Package Google.Apis.Sheets.v4
Install-Package Google.Apis.Auth
C#
string[] Scopes = { SheetsService.Scope.Spreadsheets };
var credential = GoogleCredential.FromFile("credentials.json").CreateScoped(Scopes);
var service = new SheetsService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "MyAutoTrader",
});
var range = "시트1!A2";
var valueRange = new ValueRange();
valueRange.Values = new List<IList<object>> {
new List<object> { DateTime.Now.ToString("yyyy-MM-dd"), "삼성전자", "MA20 전략", "+7.25%" }
};
var appendRequest = service.Spreadsheets.Values.Append(valueRange, spreadsheetId, range);
appendRequest.ValueInputOption = SpreadsheetsResource.ValuesResource.AppendRequest.ValueInputOptionEnum.USERENTERED;
appendRequest.Execute();
📬 STEP 2. 텔레그램 자동 알림 연동
🔹 준비 사항
- @BotFather에게 봇 생성
- 봇 토큰 받기
- @userinfobot → Chat ID 확인
🔸 C# 메시지 전송 코드
C#
public void SendTelegram(string msg, string token, string chatId)
{
using (var client = new WebClient())
{
var url = $"https://api.telegram.org/bot{token}/sendMessage?chat_id={chatId}&text={Uri.EscapeDataString(msg)}";
client.DownloadString(url);
}
}
📤 실행 예시:
C#
SendTelegram("✅ 자동매매 완료!\n종목: 삼성전자\n전략: MA20\n수익률: +7.25%", token, chatId);
🧾 STEP 3. Notion 전략 리포트 연동
🔹 준비 절차
- Notion Developers에서 Integration 생성
- API 토큰 복사
- Notion Database 생성 후 Integration 공유 권한 부여
- Database ID 복사
🔸 HTTP POST (C# HttpClient 사용)
C#
var httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", "notion_secret_xxx");
var json = @"{
""parent"": { ""database_id"": ""DATABASE_ID"" },
""properties"": {
""날짜"": { ""date"": { ""start"": ""2024-04-12"" }},
""종목"": { ""title"": [{""text"": {""content"": ""삼성전자""}}]},
""전략"": { ""rich_text"": [{""text"": {""content"": ""MA20""}}]},
""수익률"": { ""number"": 7.25 }
}
}";
var content = new StringContent(json, Encoding.UTF8, "application/json");
await httpClient.PostAsync("https://api.notion.com/v1/pages", content);
📘 Notion 공식 API: https://developers.notion.com
🔁 STEP 4. 통합 리포트 실행 함수 예시
C#
void ReportAll(string code, string strategy, double profitRate)
{
SendTelegram($"✅ 전략 실행 완료: {code}\n전략: {strategy}\n수익률: {profitRate:F2}%", token, chatId);
WriteToGoogleSheets(code, strategy, profitRate);
WriteToNotion(code, strategy, profitRate);
}
✅ 전체 리포트 연동 구조 요약
📷 자동 리포트 기록 흐름도
[자동매매 실행]
↓
[전략명 / 수익률 추출]
↓
[Google Sheet 기록] → [Notion 기록] → [Telegram 알림 전송]
키워드: C# 자동매매 텔레그램 알림, 자동매매 구글 시트 기록, Notion 자동 전략 기록, 주식 자동매매 리포트, OpenAPI 백테스트 보고서 자동화
반응형