A lightweight Go wrapper around the p2pb2b api endpoints.
To Install:
go get -v https://github.com/Dylan-Phoon/go_p2pb2b
Example:
import (
"context"
"fmt"
"github.com/Dylan-Phoon/GoP2PB2B/p2pb2b"
)
func main() {
// These can be blank if you are not making protected requests
apiSecret := ""
apiKey := ""
ctx := context.Background()
client := p2pb2b.NewClient("https://api.p2pb2b.io", apiSecret, apiKey, ctx)
res, err := client.Markets()
if err != nil {
fmt.Printf("Markets() error: %v", err)
}
fmt.Printf("Markets() response: %+v", res)
}
Each method follows the standard convention;
func SomeRequest(SomeRequestParams) (*SomeRequestJsonRes, err)
Public Requests
Get markets info Usage;
var res *MarketsJsonRes = client.Markets()
Returns;
type MarketsJsonRes struct {
Success bool
Message string
Result []marketsResult {
Name string
Stock string
Money string
MoneyPrec string
StockPrec string
FeePrec string
MinAmount string
}
}
Get info for a specified ticker Usage;
params := TickerParams {
Symbol: "ETHBTC"
}
var res *TickerJsonRes = client.Ticker(params)
Parameters;
type TickerParams struct {
Symbol string
}
Returns;
type TickerJsonRes struct {
Success bool
Message string
Result tickerResult {
At int
Ticker struct {
Bid string
Ask string
Low string
High string
Last string
Vol string
Change string
}
}
CacheTime float64
CurrentTime float64
}
Get info for all tickers
Usage;
var res *TickersJsonRes = client.Tickers()
Returns;
type TickersJsonRes struct {
Success bool
Message string
Result map[string]tickersResult {
At int
Ticker struct {
Bid string
Ask string
Low string
High string
Last string
Vol string
Change string
}
}
CacheTime float64
CurrentTime float64
}
Get info for an order book on a given ticker
Usage;
params := OrderBookParams {
Market: "ETHBTC",
Side: "buy",
Offset: "0",
Limit: "100"
}
var res *OrderBookJsonRes = client.OrderBook(params)
Parameters;
type OrderBookParams struct {
Market string
Side string
Offset string
Limit string
}
Returns;
type OrderBookJsonRes struct {
Success bool
Message string
Result orderBookResult {
Offset uint64
Limit uint64
Total uint64
Orders []struct {
Id uint64
Left string
Market string
Amount string
Type string
Price string
Timestamp float64
Side string
DealFee string
TakerFee string
MakerFee string
DealStock string
DealMoney string
}
}
CacheTime float64
CurrentTime float64
}
Get the last n trades up until a given trade id for a given ticker
Usage;
params := HistoryParams {
Market: "ETHBTC",
LastId: "1",
Limit: "100"
}
var res *HistoryJsonRes = client.History(params)
Parameters;
type HistoryParams struct {
Market string
LastId string
Limit string
}
Returns;
type HistoryJsonRes struct {
Success bool
Message string
Result []historyResult {
Id uint64
Type string
Time float64
Amount string
Price string
}
CacheTime float64
CurrentTime float64
}
Get the depth of an order book for a given ticker
Usage;
params := DepthParams {
Market "ETHBTC"
Limit "100"
}
var res *DepthJsonRes = client.Depth(params)
Parameters;
type DepthParams struct {
Market string
Limit string
}
Returns;
type DepthJsonRes struct {
Success bool
Message string
Result depthResult {
Asks [][2]string
Bids [][2]string
}
CacheTime float64
CurrentTime float64
}
Get all of the products
Usage;
var res *ProductsJsonRes = client.Products()
Returns;
type ProductsJsonRes struct {
Success bool
Message string
Result []productsResult {
Id string
FromSymbol string
ToSymbol string
}
CacheTime float64
CurrentTime float64
}
Get all of the symbols
Usage;
var res *SymbolJsonRes = client.Symbol()
Returns;
type SymbolJsonRes struct {
Success bool
Message string
Result []string
CacheTime float64
CurrentTime float64
}