crypto_exchange

package module
v0.0.0-...-c6bed12 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 30, 2022 License: MIT Imports: 17 Imported by: 0

README

Cryptocurrency Exchange APIs in Go

TBD

Installation

go get -u github.com/dojinkimm/cryptoexchange-go

Usage

Public Information
cryptoClient := crypto_exchange.NewClient(nil)

// list current prices for given market codes
currPrices, err := cryptoClient.UpbitService.ListCurrentPriceByMarketCodes([]string{"KRW-BTC", "KRW-ETH", "BTC-ETH"})
if err != nil {
    logrus.Error(err)
}
Private Information
accessKey := "<--Add Your Access Key Here-->"
secretKey := "<--Add Your Secret Key Here-->"

cryptoClient := crypto_exchange.NewClient(
    nil,
    crypto_exchange.WithAccessKey(accessKey),
    crypto_exchange.WithSecretKey(secretKey),
)

// list account information for given accessKey and secretKey user
accounts, err := cryptoClient.UpbitService.ListAccounts()
if err != nil {
    logrus.Error(err)
}

Supported Cryptocurrency Exchanges

Cryptocurrency Exchange REST Supported Websocket Support
Upbit Yes No

Supported APIs

APIs Upbit
List All Accounts
List Tradable Market Codes
Get Current Price of Market Code
Order

Documentation

Index

Constants

View Source
const (
	Buy  BuyOrSell = "bid"
	Sell BuyOrSell = "ask"

	// Limit 지정가 주문
	Limit OrderType = "limit"
	// MarketPriceBuy 시장가 매수
	MarketPriceBuy OrderType = "price"
	// MarketPriceSell 시장가 매도
	MarketPriceSell OrderType = "market"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BuyOrSell

type BuyOrSell string

type CryptoExchange

type CryptoExchange int

type DefaultCryptoExchangeClient

type DefaultCryptoExchangeClient struct {
	UpbitService *UpbitService
	// contains filtered or unexported fields
}

func NewClient

func NewClient(httpClient *http.Client, opts ...Option) *DefaultCryptoExchangeClient

NewClient returns a new http client and cryptocurrency exchange services. In order to use APIs that need authentication, AccessKey and SecretKey must be provided.

type MarketCode

type MarketCode struct {
	// ex) KRW-BTC, BTC-ETC
	Market      string `json:"market,omitempty"`
	KoreanName  string `json:"korean_name,omitempty"`
	EnglishName string `json:"english_name,omitempty"`
	// NONE (해당 사항 없음), CAUTION(투자유의)
	MarketWarning string `json:"market_warning,omitempty"`
}

type MarketCurrentPrice

type MarketCurrentPrice struct {
	// ex) KRW-BTC, BTC-ETC
	Market             string  `json:"market,omitempty"`
	TradeDate          string  `json:"trade_date,omitempty"`
	TradeTime          string  `json:"trade_time,omitempty"`
	TradeDateKst       string  `json:"trade_date_kst,omitempty"`
	TradeTimeKst       string  `json:"trade_time_kst,omitempty"`
	TradeTimestamp     int64   `json:"trade_timestamp,omitempty"`
	OpeningPrice       float64 `json:"opening_price,omitempty"`
	HighPrice          float64 `json:"high_price,omitempty"`
	LowPrice           float64 `json:"low_price,omitempty"`
	TradePrice         float64 `json:"trade_price,omitempty"`
	PrevClosingPrice   float64 `json:"prev_closing_price,omitempty"`
	Change             string  `json:"change,omitempty"`
	ChangePrice        float64 `json:"change_price,omitempty"`
	ChangeRate         float64 `json:"change_rate,omitempty"`
	SignedChangePrice  float64 `json:"signed_change_price,omitempty"`
	SignedChangeRate   float64 `json:"signed_change_rate,omitempty"`
	TradeVolume        float64 `json:"trade_volume,omitempty"`
	AccTradePrice      float64 `json:"acc_trade_price,omitempty"`
	AccTradePrice24H   float64 `json:"acc_trade_price_24h,omitempty"`
	AccTradeVolume     float64 `json:"acc_trade_volume,omitempty"`
	AccTradeVolume24H  float64 `json:"acc_trade_volume_24h,omitempty"`
	Highest52WeekPrice float64 `json:"highest_52_week_price,omitempty"`
	Highest52WeekDate  string  `json:"highest_52_week_date,omitempty"`
	Lowest52WeekPrice  float64 `json:"lowest_52_week_price,omitempty"`
	Lowest52WeekDate   string  `json:"lowest_52_week_date,omitempty"`
	Timestamp          int64   `json:"timestamp,omitempty"`
}

type Option

type Option func(*DefaultCryptoExchangeClient)

func WithAccessKey

func WithAccessKey(accessKey string) Option

func WithSecretKey

func WithSecretKey(secretKey string) Option

type OrderResp

type OrderResp struct {
	Uuid            string    `json:"uuid,omitempty"`
	Side            string    `json:"side,omitempty"`
	OrdType         string    `json:"ord_type,omitempty"`
	Price           string    `json:"price,omitempty"`
	AvgPrice        string    `json:"avg_price,omitempty"`
	State           string    `json:"state,omitempty"`
	Market          string    `json:"market,omitempty"`
	CreatedAt       time.Time `json:"created_at,omitempty"`
	Volume          string    `json:"volume,omitempty"`
	RemainingVolume string    `json:"remaining_volume,omitempty"`
	ReservedFee     string    `json:"reserved_fee,omitempty"`
	RemainingFee    string    `json:"remaining_fee,omitempty"`
	PaidFee         string    `json:"paid_fee,omitempty"`
	Locked          string    `json:"locked,omitempty"`
	ExecutedVolume  string    `json:"executed_volume,omitempty"`
	TradesCount     int       `json:"trades_count,omitempty"`
}

type OrderType

type OrderType string

type UpbitAccount

type UpbitAccount struct {
	Currency            string `json:"currency,omitempty"`
	Balance             string `json:"balance,omitempty"`
	Locked              string `json:"locked,omitempty"`
	AvgBuyPrice         string `json:"avg_buy_price,omitempty"`
	AvgBuyPriceModified bool   `json:"avg_buy_price_modified,omitempty"`
	UnitCurrency        string `json:"unit_currency,omitempty"`
}

type UpbitError

type UpbitError struct {
	Error UpbitErrorBody `json:"error,omitempty"`
}

type UpbitErrorBody

type UpbitErrorBody struct {
	Message string `json:"message,omitempty"`
	Name    string `json:"name,omitempty"`
}

type UpbitService

type UpbitService service

func (*UpbitService) CreateOrder

func (s *UpbitService) CreateOrder(
	marketCode string,
	side BuyOrSell,
	volume float64,
	price float64,
	orderType OrderType,
) (*OrderResp, error)

func (*UpbitService) ListAccounts

func (s *UpbitService) ListAccounts() ([]UpbitAccount, error)

func (*UpbitService) ListCurrentPriceByMarketCodes

func (s *UpbitService) ListCurrentPriceByMarketCodes(marketCodes []string) ([]MarketCurrentPrice, error)

func (*UpbitService) ListMarketCodes

func (s *UpbitService) ListMarketCodes() ([]MarketCode, error)

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL