AI 모델 API

학습한 모델을 API 로 씁니다. 사용하려면 관리자에게 client_id · client_secret 을 발급받으세요.

1. 토큰 받기

curl -X POST https://이 주소/oauth/token \
  -H 'Content-Type: application/json' \
  -d '{"grant_type":"client_credentials","client_id":"mc_…","client_secret":"ms_…"}'

→ {"access_token":"…","token_type":"Bearer","expires_in":3600}

토큰은 1시간 동안 씁니다. 만료되면(401) 다시 받습니다.

2. 모델 목록

curl https://이 주소/v1/models -H 'Authorization: Bearer <access_token>'

3. 예측 — candlegpt (업비트 원화 5분봉 다음 1시간)

curl -X POST https://이 주소/v1/models/candlegpt/predict \
  -H 'Authorization: Bearer <access_token>' -H 'Content-Type: application/json' \
  -d '{"market":"KRW-XRP","paths":100}'
응답 항목뜻
direction5m·15m·30m·60m 뒤 지금 종가보다 오를(up)·내릴(down)·그대로(flat) 확률
range_1h다음 1시간 고가·저가가 지금 종가 대비 몇 % 인지 (q10·q50·q90)
candles_median다음 12봉(5분×12) 예측 캔들 — 경로 n개의 가운데 값, 호가 단위
close_band봉마다 종가 80% 범위 (q10·q90)
history지난 48봉(실제)
now_utc · last_close'지금' 봉(완성된 마지막 5분 봉)과 그 종가

시세를 직접 넘길 수도 있습니다(서버는 외부 호출 없음): {"market":"KRW-XRP","now_utc":"…Z","candles":[[ts,open,high,low,close,value],…],"btc":[…]} — 빈 봉 없는 업비트 5분봉 최근 800개 이상.

버전 지정: ?version=1. 없으면 기본 버전.

4. 오류

코드뜻
400요청 형식이 틀림 (오류 문구에 이유)
401토큰 없음·만료·틀림 → 토큰 다시 받기
403중지된 클라이언트이거나 그 모델 권한이 없음
429분당 호출 수 초과
503그 모델 버전이 자기 검사를 통과하지 못해 막힘

5. Python 예

import requests, time
BASE, CID, SEC = 'https://이 주소', 'mc_…', 'ms_…'
_tok = {'t': None, 'exp': 0}
def token():
    if time.time() > _tok['exp'] - 60:
        j = requests.post(f'{BASE}/oauth/token', json={'grant_type': 'client_credentials', 'client_id': CID, 'client_secret': SEC}, timeout=10).json()
        _tok.update(t=j['access_token'], exp=time.time() + j['expires_in'])
    return _tok['t']
r = requests.post(f'{BASE}/v1/models/candlegpt/predict', json={'market': 'KRW-BTC'},
                  headers={'Authorization': f'Bearer {token()}'}, timeout=30).json()
print(r['direction']['60m'])