modulepackage
1.0.1
Repository: https://github.com/radovsky1/go-currencycom.git
Documentation: pkg.go.dev
# README
go-currencycom
A Go client library for the Currency.com API.
Installation
go get github.com/radovsky1/go-currencycom
Contribution
This project is fully inspired by go-binance. All other materials are taken from the official Currency.com API documentation.
Importing
import (
currencycom "github.com/radovsky1/go-currencycom"
)
REST API
Setup
Init client for API services. Get APIKey/SecretKey from your account.
var (
apiKey = "your api key"
secretKey = "your secret key"
)
currencycom.UseDemo = true // use demo server
client := currencycom.NewClient(apiKey, secretKey)
A service instance stands for a REST API endpoint and is initialized by client.NewXXXService function.
Simply call API in chain style. Call Do() in the end to send HTTP request and get response.
Create Order
order, err := client.NewCreateOrderService().
Symbol("BTC/USD_LEVERAGE").
Side(go_currencycom.SideTypeBuy).
Type(go_currencycom.OrderTypeLimit).
Quantity(0.03).
Price(15000).
Do(context.Background())
if err != nil {
panic(err)
}
println(order.OrderID)
Fetch Order
order, err := client.NewGetOrderService().
Symbol("BTC/USD_LEVERAGE").
OrderID("123456789").
Do(context.Background())
if err != nil {
panic(err)
}
println(order.OrderID)
Cancel Order
order, err := client.NewCancelOrderService().
Symbol("BTC/USD_LEVERAGE").
OrderID("123456789").
Do(context.Background())
if err != nil {
panic(err)
}
println(order.OrderID)
List Open Orders
openOrders, err := client.NewListOpenOrdersService().Do(context.Background())
if err != nil {
fmt.Println(err)
return
}
fmt.Println(openOrders)
List Trading Positions
positions, err := client.NewListTradingPositionsService().Do(context.Background())
if err != nil {
fmt.Println(err)
return
}
fmt.Println(positions)
Get Account Information
account, err := client.NewGetAccountService().Do(context.Background())
if err != nil {
fmt.Println(err)
return
}
fmt.Println(account)
There are more services available, please check the source code.
Websocket API
You don't need Client in websocket API. Just call currencycom.WsXxxServe(args, handler, errHandler).
Market Data
wsMarketDataHandler := func(event *currencycom.WsMarketDataEvent) {
fmt.Println(event)
}
errHandler := func(err error) {
fmt.Println(err)
}
doneC, stopC, err := currencycom.WsMarketDataServe("BTC/USD_LEVERAGE", wsMarketDataHandler, errHandler)
if err != nil {
fmt.Println(err)
return
}
// use stopC to exit
go func() {
time.Sleep(5 * time.Second)
stopC <- struct{}{}
}()
// remove this if you do not want to be blocked here
<-doneC
OHLC Market Data
wsOHLCMarketDataHandler := func(event *currencycom.WsOHLCMarketDataEvent) {
fmt.Println(event)
}
errHandler := func(err error) {
fmt.Println(err)
}
doneC, stopC, err := currencycom.WsOHLCMarketDataServe("BTC/USD_LEVERAGE", wsOHLCMarketDataHandler, errHandler)
if err != nil {
fmt.Println(err)
return
}
// use stopC to exit
go func() {
time.Sleep(5 * time.Second)
stopC <- struct{}{}
}()
// remove this if you do not want to be blocked here
<-doneC
Trades
wsTradesHandler := func(event *currencycom.WsTradesEvent) {
fmt.Println(event)
}
errHandler := func(err error) {
fmt.Println(err)
}
doneC, stopC, err := currencycom.WsTradesServe("BTC/USD_LEVERAGE", wsTradesHandler, errHandler)
if err != nil {
fmt.Println(err)
return
}
// use stopC to exit
go func() {
time.Sleep(5 * time.Second)
stopC <- struct{}{}
}()
// remove this if you do not want to be blocked here
<-doneC
Feedback
If you have any questions/suggestions, please feel free to contact me.
# Functions
No description provided by the author
IsAPIError check if e is an API error.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
# Constants
BaseDemoURL is the base url of currency.com demo api.
BaseURL is the base url of currency.com api.
Global enums.
Global enums.
Global enums.
Global enums.
Global enums.
Global enums.
Global enums.
Global enums.
Global enums.
Global enums.
Global enums.
Global enums.
Global enums.
Global enums.
Global enums.
Global enums.
Global enums.
Global enums.
Global enums.
Global enums.
Global enums.
Global enums.
Global enums.
Global enums.
Global enums.
Global enums.
Global enums.
Global enums.
# Variables
No description provided by the author
UseDemo is the flag to use demo api.
No description provided by the author
No description provided by the author
# Structs
No description provided by the author
APIError define API error when response status is 4xx or 5xx.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
DepthResponse define depth info with bids and asks.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Kline define kline info.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
# Type aliases
Ask is a type alias for PriceLevel.
Bid is a type alias for PriceLevel.
CandlestickInterval define interval of candlestick.
No description provided by the author
ExpireTimestampType define expire time of order.
NewOrderRespType define response JSON verbosity.
OrderStatusType define order status.
OrderType define order type.
PositionSideType define position side type of order.
No description provided by the author
RequestOption define option type for request.
SideType define side type of order.
TimeInForceType define time in force type of order.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author