poloniex

package module
v0.0.0-...-8b2cfdf Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2018 License: MIT Imports: 15 Imported by: 0

README

Poloniex API GO

Poloniex Push, Public and Trading APIs.

Install

$ go get 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()

For Enable Logger

ws, err := polo.NewWSClient(true)

and access Logger

ws.LogBus <- "Hello LightSide"
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"])
}
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() {
    /* If the logger is enabled, LogBus can be used */
    ws.LogBus <- "[*] Starting Unsubscribe goroutine"
    time.Sleep(time.Second * 10)
    ws.UnsubscribeMarket("usdt_btc")
}()
for {
    fmt.Println(<-ws.Subs["usdt_btc"])
}
TrollBox

TrollBox is disabled from poloniex. We will give support if it is enable.

Examples

Public Api

poloniex, err := polo.NewClient(api_key, api_secret, true)
  • Public Api Methods
    • PubReturnTicker()
    • PubReturn24hVolume()
    • PubReturnOrderBook()
    • PubReturnTradeHistory()
    • PubReturnChartData()
    • PubReturnCurrencies()
    • PubReturnLoanOrders()
Example
resp, err := poloniex.PubReturnTicker()
if err != nil{
    panic(err)
}
fmt.Println(resp)

Trading Api

const (
        api_key    = ""
        api_secret = ""
)
poloniex, err := polo.NewClient(api_key, api_secret, true)
  • Trading Api Methods
    • TradeReturnBalances()
    • TradeReturnCompleteBalances()
    • TradeReturnDepositAdresses()
    • TradeGenerateNewAddress()
    • TradeReturnOpenOrders()
    • TradeReturnAllOpenOrders()
    • TradeReturnTradeHistory()
    • TradeReturnTradeHistory()
    • TradeReturnOrderTrade()
    • TradeBuy()
    • TradeSell()
    • TradeCancelOrder()
Example
resp, err := poloniex.TradeBuy("btc_dgb", 0.00000099, 10000)
if err != nil{
    panic(err)
}
fmt.Println(resp)

License

MIT

Donations

Name Address
BTC 1JM2rchFeVtLCTMUeinUcwVc2nnd5jtawX
LTC LV46TbxeQxD9GyReQyvd5y366Nvn1MrnuF
DGB DG2R4YxAywenpkVkWS1n3szPWYgBzyxmoZ
USDT 17fGT7stxZjiREJ8ajAsdNegTRPYNW5Ao1

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"
	OrderBookError  = "[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 Buy

type Buy struct {
	OrderNumber     decimal.Decimal `json:"orderNumber"`
	ResultingTrades []ResultTrades
}

type CancelOrder

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

type CandleStick

type CandleStick struct {
	Date            decimal.Decimal `json:"date"`
	High            decimal.Decimal `json:"high"`
	Low             decimal.Decimal `json:"low"`
	Open            decimal.Decimal `json:"open"`
	Close           decimal.Decimal `json:"close"`
	Volume          decimal.Decimal `json:"volume"`
	QuoteVolume     decimal.Decimal `json:"quoteVolume"`
	WeightedAverage decimal.Decimal `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 Logger

type Logger struct {
	Lock *sync.Mutex
	// contains filtered or unexported fields
}

func (*Logger) LogRoutine

func (l *Logger) LogRoutine(bus <-chan string)

type MarginSummary

type MarginSummary struct {
	NetValue           decimal.Decimal `json:"netValue"`
	TotalBorrowedValue decimal.Decimal `json:"totalBorrowedValue"`
	CurrentMargin      decimal.Decimal `json:"currentMargin"`
	TotalValue         decimal.Decimal `json:"totalValue"`
	LendingFees        decimal.Decimal `json:"lendingFees"`
	PlusValue          decimal.Decimal `json:"pl"`
}

type MarketUpdate

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

type NewAddress

type NewAddress struct {
	Success  int
	Response string
}

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"`
}

type OpenOrder

type OpenOrder struct {
	OrderNumber decimal.Decimal `json:"orderNumber, string"`
	Type        string          `json:"type, string"`
	Rate        decimal.Decimal `json:"rate, string"`
	/*StartingAmount decimal.Decimal `json:"startingAmount, string"`*/
	Amount decimal.Decimal `json:"amount, string"`
	Total  decimal.Decimal `json:"total, string"`
}

type Order

type Order struct {
	Asks     [][]interface{} `json:"asks"`
	Bids     [][]interface{} `json:"bids"`
	IsFrozen string          `json:"isFrozen"`
}

type OrderBook

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

type OrderBookModify

type OrderBookModify OrderBook

type OrderBookRemove

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

type OrderTrade

type OrderTrade struct {
	GlobalTradeID decimal.Decimal
	TradeID       decimal.Decimal
	CurrencyPair  string
	Type          string
	Rate          decimal.Decimal
	Amount        decimal.Decimal
	Total         decimal.Decimal
	Fee           decimal.Decimal
	Date          string
}

type Poloniex

type Poloniex struct {
	LogBus chan<- string
	// contains filtered or unexported fields
}

func NewClient

func NewClient(key, secret string, timeout int32, args ...bool) (client *Poloniex, err error)

func (*Poloniex) PubReturn24hVolume

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

func (*Poloniex) PubReturnChartData

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

func (*Poloniex) PubReturnCurrencies

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

func (*Poloniex) PubReturnLoanOrders

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

func (*Poloniex) PubReturnOrderBook

func (p *Poloniex) PubReturnOrderBook(market string, depth int) (orders Order, err error)

func (*Poloniex) PubReturnTickers

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

func (*Poloniex) PubReturnTradeHistory

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

func (*Poloniex) TradeBuy

func (p *Poloniex) TradeBuy(currencyPair string, rate, amount float64) (buy Buy, err error)

func (*Poloniex) TradeCancelOrder

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

func (*Poloniex) TradeGenerateNewAddress

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

func (*Poloniex) TradeGetMarginPosition

func (p *Poloniex) TradeGetMarginPosition() (map[string]Position, error)

func (*Poloniex) TradeReturnAllOpenOrders

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

New Method Reason: different data type return when currency is 'all'

func (*Poloniex) TradeReturnAvailableAccountBalances

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

func (*Poloniex) TradeReturnBalances

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

func (*Poloniex) TradeReturnCompleteBalances

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

func (*Poloniex) TradeReturnDepositAdresses

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

func (*Poloniex) TradeReturnMarginAccountSummary

func (p *Poloniex) TradeReturnMarginAccountSummary() (MarginSummary, error)

func (*Poloniex) TradeReturnOpenOrders

func (p *Poloniex) TradeReturnOpenOrders(currency string) (openorders []OpenOrder, err error)

func (*Poloniex) TradeReturnOrderTrade

func (p *Poloniex) TradeReturnOrderTrade(orderNumber int64) (ordertrades []OrderTrade, err error)

func (*Poloniex) TradeReturnTradeHistory

func (p *Poloniex) TradeReturnTradeHistory(currency string, args ...interface{}) (tradehistory []TradeHistory2, err error)

func (*Poloniex) TradeSell

func (p *Poloniex) TradeSell(currencyPair string, rate, amount float64) (sell Sell, err error)

type Position

type Position struct {
	Type             string          `json:"type"`
	LendingFees      decimal.Decimal `json:"lendingFees"`
	Amount           decimal.Decimal `json:"amount"`
	Total            decimal.Decimal `json:"total"`
	PlusValue        decimal.Decimal `json:"pl"`
	BasePrice        decimal.Decimal `json:"basePrice"`
	LiquidationPrice decimal.Decimal `json:"liquidationPrice"`
}

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 Trade

type Trade 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 TradeHistory2

type TradeHistory2 struct {
	Date        string          `json:"date"`
	Type        string          `json:"type"`
	Buy         decimal.Decimal `json:"buy, string"`
	Rate        decimal.Decimal `json:"rate, string"`
	Amount      decimal.Decimal `json:"amount, string"`
	Total       decimal.Decimal `json:"total, string"`
	OrderNumber decimal.Decimal `json:"order_number,string"`
}

Self Trade History

type Volume

type Volume struct {
	Volumes   map[string]map[string]decimal.Decimal
	TotalBTC  float64 `json:"totalBTC, string"`
	TotalETH  float64 `json:"totalETH, 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{}
	LogBus chan<- string
	// contains filtered or unexported fields
}

func NewWSClient

func NewWSClient(args ...bool) (wsclient *WSClient, err error)

func (*WSClient) SubscribeMarket

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

func (*WSClient) SubscribeTicker

func (ws *WSClient) SubscribeTicker() error

func (*WSClient) UnsubscribeMarket

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

func (*WSClient) UnsubscribeTicker

func (ws *WSClient) UnsubscribeTicker() error

type WSTicker

type WSTicker struct {
	CurrencyPair  string  `json:"currencyPair"`
	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"`
}

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