poloniex

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2019 License: MIT Imports: 15 Imported by: 4

README

Poloniex API GO

GoDoc

Poloniex Push, Public and Trading APIs.

Install

$ go get -u github.com/iowar/poloniex

APIs

import polo "github.com/iowar/poloniex"

Push Api

Create websocket client.

NewWSClient()
ws, err := polo.NewWSClient()
if err != nil {
    return
}
  • Push Api Methods
    • SubscribeTicker()
    • SubscribeMarket()
    • UnsubscribeTicker()
    • UnsubscribeMarket()
Ticker
SubscribeTicker()
err = ws.SubscribeTicker()
if err != nil {
    return
}
for {
    fmt.Println(<-ws.Subs["TICKER"])
}
UnsubscribeTicker()
err = ws.SubscribeTicker()
go func() {
    time.Sleep(time.Second * 10)
    ws.UnsubscribeTicker()
}()
for {
    fmt.Println(<-ws.Subs["TICKER"])
}
OrderDepth, OrderBook and Trades
SubscribeMarket()
err = ws.SubscribeMarket("USDT_BTC")
if err != nil {
    return
}
for {
    fmt.Println(<-ws.Subs["USDT_BTC"])
}
UnsubscribeMarket()
err = ws.SubscribeMarket("USDT_BTC")
if err != nil {
    return
}
go func() {
    time.Sleep(time.Second * 10)
    ws.UnsubscribeMarket("USDT_BTC")
}()
for {
    fmt.Println(<-ws.Subs["USDT_BTC"])
}
Examples

Public Api

poloniex, err := polo.NewClient(api_key, api_secret)
  • Public Api Methods
    • GetTickers()
    • Get24hVolumes()
    • GetOrderBook()
    • GetPublicTradeHistory()
    • GetChartData()
    • GetCurrencies()
    • GetLoanOrders()
Example
resp, err := poloniex.GetTickers()
if err != nil{
    panic(err)
}
fmt.Println(resp)

Trading Api

const (
        api_key    = ""
        api_secret = ""
)
poloniex, err := polo.NewClient(api_key, api_secret)
  • Trading Api Methods
    • GetBalances()
    • GetCompleteBalances()
    • GetAccountBalances()
    • GetDepositAddresses()
    • GenerateNewAddress()
    • GetOpenOrders()
    • GetAllOpenOrders()
    • CancelOrder()
    • GetTradeHistory()
    • GetTradesByOrderID()
    • GetOrderStat()
    • Buy()
    • Sell()
Example
resp, err := poloniex.Buy("btc_dgb", 0.00000099, 10000)
if err != nil{
    panic(err)
}
fmt.Println(resp)

License

MIT

Documentation

Index

Constants

View Source
const (
	TICKER     = 1002 // Ticker Channel Id
	SUBSBUFFER = 24   // Subscriptions Buffer
)

Variables

View Source
var (
	ConnectError     = "[ERROR] Connection could not be established!"
	RequestError     = "[ERROR] NewRequest Error!"
	SetApiError      = "[ERROR] Set the API KEY and API SECRET!"
	PeriodError      = "[ERROR] Invalid Period!"
	TimePeriodError  = "[ERROR] Time Period incompatibility!"
	TimeError        = "[ERROR] Invalid Time!"
	StartTimeError   = "[ERROR] Start Time Format Error!"
	EndTimeError     = "[ERROR] End Time Format Error!"
	LimitError       = "[ERROR] Limit Format Error!"
	ChannelError     = "[ERROR] Unknown Channel Name: %s"
	SubscribeError   = "[ERROR] Already Subscribed!"
	WSTickerError    = "[ERROR] WSTicker Parsing %s"
	WSOrderBookError = "[ERROR] MarketUpdate OrderBook Parsing %s"
	NewTradeError    = "[ERROR] MarketUpdate NewTrade Parsing %s"
	ServerError      = "[SERVER ERROR] Response: %s"
)
View Source
var ZeroTime = time.Time{}

Functions

func Error

func Error(msg string, args ...interface{}) error

Types

type Accounts

type Accounts struct {
	Margin   map[string]decimal.Decimal `json:"margin"`
	Lending  map[string]decimal.Decimal `json:"lending"`
	Exchange map[string]decimal.Decimal `json:"exchange"`
}

type Balance

type Balance struct {
	Available decimal.Decimal `json:"available, string"`
	OnOrders  decimal.Decimal `json:"onOrders, string"`
	BtcValue  decimal.Decimal `json:"btcValue, string"`
}

type Book

type Book struct {
	Price    float64 `json:"price"`
	Quantity float64 `json:"quantity"`
}

func (*Book) UnmarshalJSON

func (bk *Book) UnmarshalJSON(b []byte) error

type Buy

type Buy struct {
	OrderNumber     string `json:"orderNumber"`
	ResultingTrades []ResultTrades
}

type CancelOrder

type CancelOrder struct {
	Success int `json:"success"`
}

type CandleStick

type CandleStick struct {
	Date            int64   `json:"date"`
	High            float64 `json:"high"`
	Low             float64 `json:"low"`
	Open            float64 `json:"open"`
	Close           float64 `json:"close"`
	Volume          float64 `json:"volume"`
	QuoteVolume     float64 `json:"quoteVolume"`
	WeightedAverage float64 `json:"weightedAverage"`
}

type Currency

type Currency struct {
	Id             int             `json:"id"`
	Name           string          `json:"name"`
	TxFee          decimal.Decimal `json:"txFee"`
	MinConf        decimal.Decimal `json:"minConf"`
	DepositAddress string          `json:"depositAddress"`
	Disabled       int             `json:"disabled"`
	Delisted       int             `json:"delisted"`
	Frozen         int             `json:"frozen"`
}

type LoanOrder

type LoanOrder struct {
	Offers  []LoanOrderSc `json:"offers"`
	Demands []LoanOrderSc `json:"demands"`
}

type LoanOrderSc

type LoanOrderSc struct {
	Rate     decimal.Decimal `json:"rate, string"`
	Amount   decimal.Decimal `json:"amount, string"`
	RangeMin int             `json:"rangeMin"`
	RangeMax int             `json:"rangeMax"`
}

type MarketUpdate

type MarketUpdate struct {
	Data       interface{}
	TypeUpdate string `json:"type"`
}

for market update.

type NewAddress

type NewAddress struct {
	Success  int    `json:"success"`
	Response string `json:"response"`
}

type NewTrade

type NewTrade struct {
	TradeId   int64   `json:"tradeID,string"`
	Rate      float64 `json:"rate,string"`
	Amount    float64 `json:"amount,string"`
	Total     float64 `json:"total,string"`
	TypeOrder string  `json:"type"`
}

"t" messages.

type OpenOrder

type OpenOrder struct {
	OrderNumber    string          `json:"orderNumber"`
	Type           string          `json:"type"`
	Price          decimal.Decimal `json:"rate, string"`
	StartingAmount decimal.Decimal `json:"startingAmount, string"`
	Amount         decimal.Decimal `json:"amount, string"`
	Total          decimal.Decimal `json:"total, string"`
	Date           string          `json:"date"`
	Margin         int             `json:"margin"`
}

type OrderBook

type OrderBook struct {
	Asks     []Book `json:"asks"`
	Bids     []Book `json:"bids"`
	IsFrozen string `json:"isFrozen"`
	Seq      int    `json:"seq"`
}

type OrderDepth

type OrderDepth struct {
	Symbol    string `json:"symbol"`
	OrderBook struct {
		Asks []Book `json:"asks"`
		Bids []Book `json:"bids"`
	} `json:"orderBook"`
}

"i" messages.

type OrderStat

type OrderStat struct {
	Status         string          `json:"status"`
	Rate           decimal.Decimal `json:"rate"`
	Amount         decimal.Decimal `json:"amount"`
	CurrencyPair   string          `json:"currencyPair"`
	Date           string          `json:"date"`
	Total          decimal.Decimal `json:"total"`
	Type           string          `json:"type"`
	StartingAmount decimal.Decimal `json:"startingAmount"`
}

type OrderStat1

type OrderStat1 struct {
	Success int `json:"success"`
	Result  struct {
		Error string `json:"error"`
	} `json:"result"`
}

error result

type OrderStat2

type OrderStat2 struct {
	Success int                  `json:"success"`
	Result  map[string]OrderStat `json:"result"`
}

success result

type OrderTrade

type OrderTrade struct {
	GlobalTradeID decimal.Decimal `json:"globalTradeId"`
	TradeID       decimal.Decimal `json:"tradeId"`
	Market        string          `json:"currencyPair"`
	Type          string          `json:"type"`
	Price         decimal.Decimal `json:"rate"`
	Amount        decimal.Decimal `json:"amount"`
	Total         decimal.Decimal `json:"total"`
	Fee           decimal.Decimal `json:"fee"`
	Date          string          `json:"date"`
}

type Poloniex

type Poloniex struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(key, secret string) (client *Poloniex, err error)

func (*Poloniex) Buy

func (p *Poloniex) Buy(market string, price, amount float64) (buy Buy, err error)

func (*Poloniex) CancelOrder

func (p *Poloniex) CancelOrder(orderNumber string) (cancelorder CancelOrder, err error)

func (*Poloniex) GenerateNewAddress

func (p *Poloniex) GenerateNewAddress(currency string) (newaddress NewAddress, err error)

func (*Poloniex) Get24hVolumes

func (p *Poloniex) Get24hVolumes() (volumes Volume, err error)

func (*Poloniex) GetAccountBalances

func (p *Poloniex) GetAccountBalances() (accounts Accounts, err error)

func (*Poloniex) GetAllOpenOrders

func (p *Poloniex) GetAllOpenOrders() (openorders map[string][]OpenOrder, err error)

This method returns all open orders.

func (*Poloniex) GetBalances

func (p *Poloniex) GetBalances() (balances map[string]string, err error)

func (*Poloniex) GetChartData

func (p *Poloniex) GetChartData(market string, start, end time.Time, period string) (candles []CandleStick, err error)

func (*Poloniex) GetCompleteBalances

func (p *Poloniex) GetCompleteBalances() (completebalances map[string]Balance, err error)

func (*Poloniex) GetCurrencies

func (p *Poloniex) GetCurrencies() (currencies map[string]Currency, err error)

func (*Poloniex) GetDepositAddresses

func (p *Poloniex) GetDepositAddresses() (depositaddresses map[string]string, err error)

func (*Poloniex) GetLoanOrders

func (p *Poloniex) GetLoanOrders(currency string) (loanorders LoanOrder, err error)

func (*Poloniex) GetOpenOrders

func (p *Poloniex) GetOpenOrders(market string) (openorders []OpenOrder, err error)

Send market to get open orders.

func (*Poloniex) GetOrderBook

func (p *Poloniex) GetOrderBook(market string, depth int) (orderbook OrderBook, err error)

func (*Poloniex) GetOrderStat

func (p *Poloniex) GetOrderStat(orderNumber string) (orderstat OrderStat, err error)

func (*Poloniex) GetPublicTradeHistory

func (p *Poloniex) GetPublicTradeHistory(market string, args ...time.Time) (trades []PublicTrade, err error)

func (*Poloniex) GetTickers

func (p *Poloniex) GetTickers() (tickers map[string]Ticker, err error)

func (*Poloniex) GetTradeHistory

func (p *Poloniex) GetTradeHistory(market string, start, end time.Time, limit int) (tradehistory []TradeHistory, err error)

func (*Poloniex) GetTradesByOrderID

func (p *Poloniex) GetTradesByOrderID(orderNumber string) (ordertrades []OrderTrade, err error)

func (*Poloniex) Sell

func (p *Poloniex) Sell(market string, price, amount float64) (sell Sell, err error)

type PublicTrade

type PublicTrade struct {
	GlobalTradeID uint64          `json:"globalTradeID"`
	TradeID       uint64          `json:"tradeID"`
	Date          string          `json:"date, string"`
	Type          string          `json:"type, string"`
	Rate          decimal.Decimal `json:"rate, string"`
	Amount        decimal.Decimal `json:"amount, string"`
	Total         decimal.Decimal `json:"total, string"`
}

type ResultTrades

type ResultTrades struct {
	Amount  decimal.Decimal `json:"amount"`
	Date    string          `json:"date"`
	Rate    decimal.Decimal `json:"rate"`
	Total   decimal.Decimal `json:"total"`
	TradeID decimal.Decimal `json:"tradeId"`
	Type    string          `json:"type"`
}

type Sell

type Sell Buy

type Ticker

type Ticker struct {
	ID            int             `json:"id, int"`
	Last          decimal.Decimal `json:"last, string"`
	LowestAsk     decimal.Decimal `json:"lowestAsk, string"`
	HighestBid    decimal.Decimal `json:"highestBid, string"`
	PercentChange decimal.Decimal `json:"percentChange, string"`
	BaseVolume    decimal.Decimal `json:"baseVolume, string"`
	QuoteVolume   decimal.Decimal `json:"quoteVolume, string"`
	IsFrozen      int             `json:"isFrozen ,string"`
	High24hr      decimal.Decimal `json:"high24hr, string"`
	Low24hr       decimal.Decimal `json:"low24hr, string"`
}

type TradeHistory

type TradeHistory struct {
	GlobalTradeID int             `json:"globalTradeId"`
	TradeID       string          `json:"tradeId"`
	Date          string          `json:"date"`
	Price         decimal.Decimal `json:"rate, string"`
	Amount        decimal.Decimal `json:"amount, string"`
	Total         decimal.Decimal `json:"total, string"`
	Fee           decimal.Decimal `json:"fee,string"`
	OrderNumber   decimal.Decimal `json:"orderNumber,string"`
	Type          string          `json:"type"`
	Category      string          `json:"category"`
}

type Volume

type Volume struct {
	Volumes   map[string]map[string]decimal.Decimal
	TotalBTC  float64 `json:"totalBTC, string"`
	TotalETH  float64 `json:"totalETH, string"`
	TotalUSDC float64 `json:"totalUSDC, string"`
	TotalUSDT float64 `json:"totalUSDT, string"`
	TotalXMR  float64 `json:"totalXMR, string"`
	TotalXUSD float64 `json:"totalXUSD, string"`
}

func (*Volume) UnmarshalJSON

func (v *Volume) UnmarshalJSON(b []byte) error

type WSClient

type WSClient struct {
	Subs map[string]chan interface{} // subscriptions map

	sync.Mutex // embedded mutex
	// contains filtered or unexported fields
}

func NewWSClient

func NewWSClient() (wsClient *WSClient, err error)

Create new web socket client.

func (*WSClient) SubscribeMarket

func (ws *WSClient) SubscribeMarket(chname string) error

Subscribe to market channel. It returns nil if successful.

func (*WSClient) SubscribeTicker

func (ws *WSClient) SubscribeTicker() error

Subscribe to ticker channel. It returns nil if successful.

func (*WSClient) UnsubscribeMarket

func (ws *WSClient) UnsubscribeMarket(chname string) error

Unsubscribe from market channel. It returns nil if successful.

func (*WSClient) UnsubscribeTicker

func (ws *WSClient) UnsubscribeTicker() error

Unsubscribe from ticker channel. It returns nil if successful.

type WSOrderBook

type WSOrderBook struct {
	Rate      float64 `json:"rate,string"`
	TypeOrder string  `json:"type"`
	Amount    float64 `json:"amount,string"`
}

"o" messages

type WSOrderBookModify

type WSOrderBookModify WSOrderBook

"o" messages.

type WSOrderBookRemove

type WSOrderBookRemove struct {
	Rate      float64 `json:"rate,string"`
	TypeOrder string  `json:"type"`
}

"o" messages.

type WSTicker

type WSTicker struct {
	Symbol        string  `json:"symbol"`
	Last          float64 `json:"last"`
	LowestAsk     float64 `json:"lowestAsk"`
	HighestBid    float64 `json:"hihgestBid"`
	PercentChange float64 `json:"percentChange"`
	BaseVolume    float64 `json:"baseVolume"`
	QuoteVolume   float64 `json:"quoteVolume"`
	IsFrozen      bool    `json:"isFrozen"`
	High24hr      float64 `json:"high24hr"`
	Low24hr       float64 `json:"low24hr"`
}

for ticker update.

Directories

Path Synopsis
examples
push
the following code shows how to access NewTrade fields.
the following code shows how to access NewTrade fields.

Jump to

Keyboard shortcuts

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