bitopro-api-go

module
v1.3.9 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2023 License: MIT

README

BitoPro API Client for Go

Requirement

Requires minimum of Go 1.11.

Installation

$ go get github.com/bitoex/bitopro-api-go
Limitations
Rate Limit

There is rate limits applied to each API, please check API documentation for more detail.

Precisions

Both price and amount are subject to decimal restrictions, please check official settings for more detail.

Minimum order amount

Checkout the official settings of minimum amount.

Getting Started

Public API

Methods for public APIs are packaged in PubAPI struct which can be created through GetPubClient.

import "github.com/bitoex/bitopro-api-go/pkg/bitopro"

pubClient := bitopro.GetPubClient()
Authenticated API

Methods for authenticated APIs are packaged in AuthAPI struct which can be created in various ways through GetAuthClient depends on how you setup your authenticate information. To use the authenticated APIs, you need the following information, API Key, API Secret, Identity (Account Email). You can create an API key here.

Basic
import "github.com/bitoex/bitopro-api-go/pkg/bitopro"

authClient := bitopro.GetAuthClient("your identity (email)", "your key", "your secret")
From Viper
# secret.yml
identity: <<your email>>
key: <<your key>>
secret: <<your secret>>
import (
  "github.com/spf13/viper"
  
  "github.com/bitoex/bitopro-api-go/pkg/bitopro"
)

viper.AddConfigPath(".")
viper.SetConfigName("secret")
viper.ReadInConfig()

authAPI := GetAuthClient(viper.GetString("identity"), viper.GetString("key"), viper.GetString("secret"))
Public REST Endpoints
GetOrderBook

example

pubClient.GetOrderBook("btc_twd")
//or
authClient.GetOrderBook("btc_twd")
JSON Response
{
  "bids": [
    {
      "price": "180500",
      "amount": "0.12817687",
      "count": 1,
      "total": "0.12817687"
    },
    {
      "price": "180010",
      "amount": "0.32292",
      "count": 2,
      "total": "0.45109687"
    },
    {
      "price": "180000",
      "amount": "0.24236",
      "count": 3,
      "total": "0.69345687"
    }
  ],
  "asks": [
    {
      "price": "180599",
      "amount": "0.00326056",
      "count": 1,
      "total": "0.00326056"
    },
    {
      "price": "180600",
      "amount": "0.04202575",
      "count": 1,
      "total": "0.04528631"
    }
  ]
}
GetTicker

example

pubClient.GetTicker("btc_twd")
//or
authClient.GetTicker("btc_twd")
JSON Response
{
  "data": {
    "pair": "btc_twd",
    "lastPrice": "0.00010800",
    "isBuyer": false,
    "priceChange24hr": "0",
    "volume24hr": "0.00000000",
    "high24hr": "0.00010800",
    "low24hr": "0.00010800"
  }
}
GetTickers

example

pubClient.GetTickers()
//or
authClient.GetTickers()
JSON Response
{
  "data": [
    {
      "pair": "xem_btc",
      "lastPrice": "0.00000098",
      "isBuyer": false,
      "priceChange24hr": "0",
      "volume24hr": "0.00000000",
      "high24hr": "0.00000098",
      "low24hr": "0.00000098"
    },
    {
      "pair": "bch_eth",
      "lastPrice": "0.60010000",
      "isBuyer": false,
      "priceChange24hr": "0",
      "volume24hr": "0.00000000",
      "high24hr": "0.60010000",
      "low24hr": "0.60010000"
    },
    {
      "pair": "eth_usdt",
      "lastPrice": "179.22000000",
      "isBuyer": true,
      "priceChange24hr": "10.85",
      "volume24hr": "925.14654180",
      "high24hr": "182.30000000",
      "low24hr": "159.94000000"
    }
  ]
}
GetTrades

example

pubClient.GetTrades("btc_twd")
//or
authClient.GetTrades("btc_twd")
JSON Response
{
  "data": [
    {
      "timestamp": 1557203407,
      "price": "180500.00000000",
      "amount": "0.07717687",
      "isBuyer": false
    },
    {
      "timestamp": 1557203187,
      "price": "180500.00000000",
      "amount": "0.05100000",
      "isBuyer": false
    },
    {
      "timestamp": 1557203053,
      "price": "180500.00000000",
      "amount": "0.01860000",
      "isBuyer": false
    },
    {
      "timestamp": 1557202804,
      "price": "180500.00000000",
      "amount": "0.04781533",
      "isBuyer": false
    },
    {
      "timestamp": 1557202804,
      "price": "180500.00000000",
      "amount": "0.06000000",
      "isBuyer": false
    }
  ]
}
Authenticated REST Endpoints
GetAccountBalance

example

authClient.GetAccountBalance()
JSON Response
{
  "data": [
    {
      "amount": "10001",
      "available": "1.0",
      "currency": "bito",
      "stake": "10000"
    },
    {
      "amount": "0.0",
      "available": "1.0",
      "currency": "btc",
      "stake": "0"
    },
    {
      "amount": "3.0",
      "available": "0.01",
      "currency": "eth",
      "stake": "0"
    },
    {
      "amount": "30000",
      "available": "2500",
      "currency": "twd",
      "stake": "0"
    }
  ]
}
GetOrderHistory

example

authClient.GetOrderHistory()
JSON Response
{
  "data": [
    {
      "action": "buy",
      "avgExecutionPrice": "100000.00000000",
      "bitoFee": "0.00000000",
      "executedAmount": "1.00000000",
      "fee": "0.00100000",
      "feeSymbol": "BTC",
      "id": "123",
      "originalAmount": "1.00000000",
      "pair": "btc_twd",
      "price": "100000.00000000",
      "remainingAmount": "0.00000000",
      "status": 2,
      "timestamp": 1508753757000,
      "type": "limit"
    },
    {
      "action": "buy",
      "avgExecutionPrice": "100000.00000000",
      "bitoFee": "0.00000000",
      "executedAmount": "1.00000000",
      "fee": "0.00200000",
      "feeSymbol": "BTC",
      "id": "456",
      "originalAmount": "1.00000000",
      "pair": "btc_twd",
      "price": "100000.00000000",
      "remainingAmount": "0.00000000",
      "status": 2,
      "timestamp": 1508753787000,
      "type": "limit"
    }
  ]
}
GetOrderList

example

authClient.GetOrderList("btc_twd", false, 1)
JSON Response
{
  "data": [
    {
      "action": "buy",
      "avgExecutionPrice": "100000.00000000",
      "bitoFee": "0.00000000",
      "executedAmount": "1.00000000",
      "fee": "0.00100000",
      "feeSymbol": "BTC",
      "id": "123",
      "originalAmount": "1.00000000",
      "pair": "btc_twd",
      "price": "100000.00000000",
      "remainingAmount": "0.00000000",
      "status": 2,
      "timestamp": 1508753757000,
      "type": "limit"
    },
    {
      "action": "buy",
      "avgExecutionPrice": "100000.00000000",
      "bitoFee": "0.00000000",
      "executedAmount": "1.00000000",
      "fee": "0.00200000",
      "feeSymbol": "BTC",
      "id": "456",
      "originalAmount": "1.00000000",
      "pair": "btc_twd",
      "price": "100000.00000000",
      "remainingAmount": "0.00000000",
      "status": 2,
      "timestamp": 1508753787000,
      "type": "limit"
    }
  ],
  "page": 1,
  "totalPages": 10
}
CreateOrderLimitBuy/CreateOrderLimitSell/CreateOrderMarketBuy/CreateOrderMarketSell

example

// create limit buy order
authClient.CreateOrderLimitBuy("eth_twd", "0.1", "1")
// create limit sell order
authClient.CreateOrderLimitSell("eth_twd", "0.1", "1")
// create market buy order
authClient.CreateOrderMarketBuy("eth_twd", "1")
// create market sell order
authClient.CreateOrderMarketSell("eth_twd", "1")
JSON Response
{
  "action": "buy",
  "amount": "0.235",
  "orderId": "11233456",
  "price": "1.0",
  "timestamp": 1504262258000
}
CancelOrder

example

authClient.CancelOrder("eth_twd", 7517762903)
JSON Response
{
  "action": "buy",
  "amount": 2.3,
  "orderId": "7517762903",
  "price": 1.2,
  "timestamp": 1504262258000
}
GetOrder

example

authClient.GetOrder("btc_twd", 2640904509)
JSON Response
{
  "action": "sell",
  "avgExecutionPrice": "112000.00000000",
  "bitoFee": "103.70370360",
  "executedAmount": "1.00000000",
  "fee": "0.00000000",
  "feeSymbol": "TWD",
  "id": "2640904509",
  "originalAmount": "1.00000000",
  "pair": "btc_twd",
  "price": "112000.00000000",
  "remainingAmount": "0.00000000",
  "status": 2,
  "timestamp": 1508753757000,
  "type": "limit"
}
Websocket
publicWs := ws.NewPublicWs()
privateWs := ws.NewPrivateWs("email", "api_key", "api_secret")
Ticker Stream

example

tickers, closeCh := publicWs.RunTickerWsConsumer(ctx, []string{"BTC_TWD"})
defer close(closeCh)

for {
  ticker <- tickers
  if ticker.Err != nil {
    fmt.Printf("%+v\n", err)
    return
  }
  fmt.Printf("%+v\n", ticker)
}

OrderBook Stream

example

orderBooks, closeCh := publicWs.RunOrderbookWsConsumer(ctx, []string{"BTC_TWD:30"})
defer close(closeCh)

for {
  orderBook <- orderBooks
  if orderBook.Err != nil {
    fmt.Printf("%+v\n", err)
    return
  }
  fmt.Printf("%+v\n", orderBook)
  fmt.Printf("%+v\n", len(orderBook.Bids)) // => 30
  fmt.Printf("%+v\n", len(orderBook.Asks))  // => 30
}

Trade Stream

example

trades, closeCh := publicWs.RunTradesWsConsumer(ctx, []string{"BTC_TWD"})
defer close(closeCh)

for {
  trade <- trades
  if trade.Err != nil {
    fmt.Printf("%+v\n", err)
    return
  }
  fmt.Printf("%+v\n", trade)
}
AccountBalance Stream

example

accBalances, closeCh := privateWs.RunAccountBalancesWsConsumer(ctx)
defer close(closeCh)

for {
  accBalance <- accBalances
  if accBalance.Err != nil {
    fmt.Printf("%+v\n", err)
    return
  }
  fmt.Printf("%+v\n", accBalance)
}
UserOrders Stream

example

ordersList, closeCh := privateWs.RunOrdersWsConsumer(ctx)
defer close(closeCh)

for {
  orders <- ordersList
  if orders.Err != nil {
    fmt.Printf("%+v\n", err)
    return
  }
  fmt.Printf("%+v\n", orders)
}

Contributing

Bug reports and pull requests are welcome on GitHub at bitopro-api-go and this project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

  1. Fork it.
  2. Create your feature branch (git checkout -b my-new-feature).
  3. Commit your changes (git commit -am 'Added some feature').
  4. Push to the branch (git push origin my-new-feature).
  5. Create new Pull Request.

License

The SDK is available as open source under the terms of the MIT License.

Directories

Path Synopsis
pkg
ws

Jump to

Keyboard shortcuts

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