mirror of
https://git.hmsn.ink/coin/bot.git
synced 2026-03-20 00:02:16 +09:00
119 lines
5.0 KiB
JavaScript
119 lines
5.0 KiB
JavaScript
// strategy.js
|
||
import logger from './logger.js';
|
||
import {OpenAI} from "openai";
|
||
|
||
const prompts = {
|
||
"1h": `You are a BTC/USDT 1-hour swing-trading engine.
|
||
- Timeframe: 1h candles only.
|
||
- Daily trade frequency target: ≥ 3 valid setups.
|
||
- Risk per trade: 1 % of account or less.
|
||
- Reward-to-Risk: minimum 2.0, target 2.5.
|
||
- Never hold more than 1 concurrent position.
|
||
- Do not add commentary outside the final JSON.
|
||
|
||
[INPUT]
|
||
Exactly 50 recent 1-hour candles, newest last, format:
|
||
[{"t":<Unix ts>,"o":<float>,"h":<float>,"l":<float>,"c":<float>,"v":<float>}, …]
|
||
|
||
LONG:
|
||
- 9-EMA > 21-EMA (both rising).
|
||
- RSI14 between 40 and 60, and increasing versus previous candle.
|
||
- Close ≥ VWAP.
|
||
- Close ≤ Swing High - ATR14×0.5 (small pullback zone).
|
||
|
||
SHORT:
|
||
- 9-EMA < 21-EMA (both falling).
|
||
- RSI14 between 40 and 60, and decreasing versus previous candle.
|
||
- Close ≤ VWAP.
|
||
- Close ≥ Swing Low + ATR14×0.5 (small pullback zone).
|
||
|
||
HOLD:
|
||
- If neither LONG nor SHORT conditions are met.
|
||
|
||
Return JSON only, no spaces after colons:
|
||
{"side":"LONG|SHORT|HOLD","price":<float>,"sl":<float>,"tp":<float>,"reason":"<max 200 words>"}
|
||
|
||
Entry Price (limit) = current candle close.
|
||
Stop-Loss (SL) = Entry ± ATR14 × 1.0.
|
||
Take-Profit (TP) = Entry ± ATR14 × 2.5.
|
||
Round all prices to the nearest 0.1 USDT.
|
||
|
||
reason 은 한국어로 대답해줘.`,
|
||
'15m': `당신은 2025년 기준 코인 선물 **15분봉 전문 트레이더**입니다. 15분 단위로 신속한 진입/청산이 필수적이며, **2~3배 레버리지**로 고빈도 수익을 추구합니다. 다음 규칙을 철저히 적용하세요.
|
||
### 📌 핵심 분석 지표 (15분봉 최적화)
|
||
- **롱 진입 조건** (2가지 충족 시):
|
||
1. EMA9 > EMA21 정배열 + 가격이 **15분 VWAP 상향 돌파** (2회 재테스트 성공)
|
||
2. RSI(9) 30 이하에서 **역다이버전스** + 양봉 체인 2연속
|
||
3. Funding Rate < -0.03% + Liquidation Cluster(0.2% 구간) 형성
|
||
|
||
- **숏 진입 조건** (2가지 충족 시):
|
||
1. 볼린저 밴드(14,1.5σ) 상단 **3회 테스트 실패** + MACD(6,13,9) 히스토그램 급감
|
||
2. OVM에서 **롱 리퀴 헌팅 구간** (Coinalyze 기준 5분 내 집중)
|
||
3. Funding Rate 15분 이동평균 > 0.07%
|
||
|
||
### ⚙️ 15분봉 특화 리스크 관리 (!!!!꼭 지겨야 하는 조건)
|
||
- **스탑로스**: 최근 3봉 저점(롱)/고점(숏) ± 0.3% or ATR(7)*1.2
|
||
- **테이크프로핏**: 1:2 비율 (예: SL 0.5% → TP 1.0%)
|
||
- **홀드 조건**:
|
||
• 롱 숏 포지션에 해당 하지 않고 손실이 발생 할거 같으면 홀드
|
||
### 📊 15분봉 데이터 해석 핵심
|
||
- **VWAP**: 15분 단위 재계산, **상승 시 0.15% 이내 재테스트** 필수
|
||
- **다이버전스**: RSI/MACD 신호 지속시간 **3봉 이내**만 유효
|
||
- **OVM**: Liquidation Cluster **0.2% 미만 밀집 구간**에만 반응
|
||
### 📝 출력 형식 (순수 JSON, 추가 설명 금지, !!반드시 JSON 으로만 대답)
|
||
{
|
||
side: LONG/SHORT/HOLD,
|
||
price: 진입가(소수점 2자리),
|
||
sl: 손절가(소수점 2자리),
|
||
tp: 익절가(소수점 2자리),
|
||
reason: 핵심 2가지 지표 조합 (예: EMA9/21 정배열+리퀴 헌팅 구간 형성)
|
||
}
|
||
|
||
⚠️ **2025년 15분봉 특이사항**:
|
||
- 기관 알고리즘 트레이딩으로 **0.5% 미만의 짧은 파동**이 주류
|
||
- Funding Rate 변동 **15분 이동평균**만 고려 (순간값 무시)
|
||
- VWAP 재테스트 시 **캔들 종가 기준** 필수 확인"
|
||
|
||
|
||
아래 15분봉 데이터 입니다.
|
||
[데이터 타입]
|
||
[{"t":<Unix ts>,"o":<float>,"h":<float>,"l":<float>,"c":<float>,"v":<float>}, …]
|
||
|
||
캔들스틱 데이터 15분봉 :
|
||
`
|
||
}
|
||
|
||
const openai = new OpenAI({
|
||
baseURL: 'https://openrouter.ai/api/v1',
|
||
apiKey: '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',
|
||
});
|
||
|
||
|
||
|
||
export async function aiSignal(bars) {
|
||
if (bars.length < 20) return null;
|
||
console.log(Date.now())
|
||
const content = `
|
||
${prompts["1h"]}
|
||
|
||
${JSON.stringify(bars)}
|
||
`;
|
||
const completion = await openai.chat.completions.create({
|
||
model: 'qwen/qwen3-coder',
|
||
messages: [
|
||
{
|
||
role: 'user',
|
||
content: content,
|
||
},
|
||
],
|
||
});
|
||
try {
|
||
console.log(Date.now())
|
||
const msg = completion.choices[0].message.content
|
||
logger.debug(msg);
|
||
const sig = JSON.parse(msg)
|
||
return sig;
|
||
} catch(e) {
|
||
return {side : 'HOLD'}
|
||
}
|
||
} |