glupbit

Package Version Hex Docs

Upbit API를 Gleam으로 쓸 수 있게 해주는 라이브러리야~! REST랑 WebSocket 둘 다 되고, 타입 시스템이 잘못된 호출을 막아주니까 안심이야!

설치하기

gleam add glupbit@1

이거 한 줄이면 끝이야! 진짜 쉽지?!

써보기

Quotation (인증 안 해도 돼!)

import gleam/io
import gleam/option.{None, Some}
import glupbit

pub fn main() {
  let client = glupbit.new()
  let assert Ok(market) = glupbit.market("KRW-BTC")

  // 거래 가능한 마켓 전부 가져오기
  let assert Ok(response) = glupbit.quotation.market.list_all(client)
  io.debug(response.data)

  // 비트코인 현재가 조회!
  let assert Ok(response) = glupbit.quotation.ticker.get_tickers(client, [market])
  io.debug(response.data)

  // 1분봉 캔들 10개 가져오기
  let assert Ok(response) =
    glupbit.quotation.candle.get_minutes(client, glupbit.quotation.candle.Min1, market, None, Some(10))
  io.debug(response.data)
}

Exchange (잔고 조회, 주문 같은 거!)

import gleam/io
import glupbit

pub fn main() {
  // 방법 1: key를 직접 넣어주기
  let creds =
    glupbit.credentials(
      glupbit.access_key("여기에-access-key"),
      glupbit.secret_key("여기에-secret-key"),
    )
  let client = glupbit.new_auth(creds)

  // 방법 2: 환경변수에서 읽어오기 (UPBIT_ACCESS_KEY, UPBIT_SECRET_KEY)
  let assert Ok(client) = glupbit.new_from_env()

  // 내 잔고 확인하기!
  let assert Ok(response) = glupbit.exchange.account.get_balances(client)
  io.debug(response.data)
}

WebSocket (실시간 데이터!)

import gleam/io
import gleam/option.{None}
import glupbit
import glupbit/websocket/connection
import glupbit/websocket/subscription.{TickerSub, Default}

pub fn main() {
  let assert Ok(market) = glupbit.market("KRW-BTC")

  let assert Ok(ws) =
    connection.connect_public(Nil, fn(_state, msg) {
      io.debug(msg)
      Nil
    })

  connection.subscribe(ws, [TickerSub([market], None, None)], Default)
}

실시간으로 시세가 쏟아져 나와!! 너무 신기하지 않아?!

할 수 있는 것들

Quotation API (누구나 쓸 수 있어!)

모듈endpoint함수
marketGET /market/alllist_all, list_all_detailed
tickerGET /tickerget_tickers, get_all_tickers
candleGET /candles/*get_seconds, get_minutes, get_days, get_weeks, get_months, get_years
tradeGET /trades/ticksget_recent_trades
orderbookGET /orderbookget_orderbooks, get_supported_levels

Exchange API (인증 필요해!)

모듈endpoint함수
accountGET /accountsget_balances
orderPOST /orderscreate_order, test_order
orderGET /orderget_order, get_order_by_identifier
orderGET /orders/openlist_open_orders
orderGET /orders/closedlist_closed_orders
orderDELETE /ordercancel_order, cancel_order_by_identifier
orderDELETE /orders/openbatch_cancel_orders
orderGET /orders/chanceget_order_chance
withdrawPOST /withdraws/coinwithdraw_coin
withdrawPOST /withdraws/krwwithdraw_krw
serviceGET /status/walletget_wallet_status
serviceGET /api_keyslist_api_keys
serviceTravel Rulelist_travelrule_vasps, verify_travelrule_by_uuid, verify_travelrule_by_txid

WebSocket (실시간!)

connect_public으로는 공개 데이터를, connect_private로는 내 주문이랑 내 자산을 실시간으로 볼 수 있어!

구독 종류: TickerSub, TradeSub, OrderbookSub, CandleSub, MyOrderSub, MyAssetSub

이 라이브러리의 좋은 점!

에러 처리

API 호출은 전부 Result(ApiResponse(a), ApiError)를 돌려줘! ApiError 종류는 이거야:

개발

gleam build           # 빌드하기
gleam test            # 테스트 돌리기
gleam format src test # 코드 예쁘게 정리하기

문서

자세한 API 문서는 hexdocs.pm/glupbit에 있어!

라이선스

Blue Oak Model License 1.0.0

Search Document