poloniex

package module
v0.0.0-...-c57e4fb Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2018 License: MIT Imports: 21 Imported by: 0

README

Go Poloniex API wrapper

This API should be a complete wrapper for the Poloniex api, including the public, private and websocket APIs.

Install

go get -u github.com/pharrisee/poloniex-api

Usage

To use create a copy of config-example.json and fill in your API key and secret.

{
    "key":"put your key here",
    "secret":"put your secret here"
}

You can also pass your key/secret pair in code rather than creating a config.json.

Examples

Public API
package main

import (
    "log"

    "github.com/k0kubun/pp"
    "github.com/pharrisee/poloniex-api"
)

func main() {
    p := poloniex.NewPublicOnly()
    ob, err := p.OrderBook("BTC_ETH")
    if err != nil {
        log.Fatalln(err)
    }
    pp.Println(ob.Asks[0], ob.Bids[0])
}
Private API
package main

import (
    "fmt"
    "log"

    "github.com/pharrisee/poloniex-api"
)

func main() {
    p := poloniex.New("config.json")
    balances, err := p.Balances()
    if err != nil {
        log.Fatalln(err)
    }
    fmt.Printf("%+v\n", balances)
}
Websocket API
package main

import (
    "log"

    poloniex "github.com/pharrisee/poloniex-api"

    "github.com/k0kubun/pp"
)

func main() {
	p := poloniex.NewWithCredentials("Key goes here", "secret goes here")
	p.Subscribe("ticker")
	p.Subscribe("USDT_BTC")
	p.StartWS()

	p.On("ticker", func(m poloniex.WSTicker) {
		pp.Println(m)
	}).On("USDT_BTC-trade", func(m poloniex.WSOrderbook) {
		pp.Println(m)
	})

	for _ = range time.Tick(1 * time.Second) {

	}
}

Documentation

Index

Examples

Constants

View Source
const (
	// PUBLICURI is the address of the public API on Poloniex
	PUBLICURI = "https://poloniex.com/public"
	// PRIVATEURI is the address of the public API on Poloniex
	PRIVATEURI = "https://poloniex.com/tradingApi"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AccountBalances

type AccountBalances struct {
	Exchange map[string]float64
	Margin   map[string]float64
	Lending  map[string]float64
}

Account holds the balances in the various wallet accounts

type ActiveLoan

type ActiveLoan struct {
	ID        int64 `json:"id"`
	Currency  string
	Rate      float64 `json:",string"`
	Amount    float64 `json:",string"`
	Range     int64
	Renewable bool
	AutoRenew int64 `json:"autoRenew"`
	Date      string
	DateTaken time.Time
	Fees      float64 `json:",string"`
}

type ActiveLoans

type ActiveLoans struct {
	Provided []ActiveLoan
}

type Addresses

type Addresses map[string]string

Addresses holds the various deposit addresses foreach coin

type AvailableAccountBalances

type AvailableAccountBalances struct {
	Exchange map[string]float64
	Margin   map[string]float64
	Lending  map[string]float64
}

type AvailableAccountBalancesTemp

type AvailableAccountBalancesTemp struct {
	Exchange map[string]json.Number
	Margin   map[string]json.Number
	Lending  map[string]json.Number
}

type Balance

type Balance struct {
	Available float64 `json:",string"`
	OnOrders  float64 `json:"onOrders,string"`
	BTCValue  float64 `json:"btcValue,string"`
}

Balance is a single balance entry used in the Balances map

Example
p := New("config.json")
balances, err := p.Balances()
if err != nil {
	log.Fatalln(err)
}
fmt.Printf("%+v\n", balances)

type Balances

type Balances map[string]Balance

Balances are the complete balance map returned by the poloniex API

type Base

type Base struct {
	Error    string
	Success  int64
	Response string
}

Base is the common fields returned by a call tothepoloniex API

type Buy

type Buy struct {
	OrderNumber int64 `json:",string"`
}

type ChartData

type ChartData []ChartDataEntry

type ChartDataEntry

type ChartDataEntry struct {
	Date            int64
	High            float64
	Low             float64
	Open            float64
	Close           float64
	Volume          float64
	QuoteVolume     float64
	WeightedAverage float64
}

type Currencies

type Currencies map[string]Currency

type Currency

type Currency struct {
	Name           string
	TxFee          float64 `json:",string"`
	MinConf        float64
	DepositAddress string
	Disabled       int64
	Delisted       int64
	Frozen         int64
}

type DailyVolume

type DailyVolume map[string]DailyVolumeEntry

type DailyVolumeEntry

type DailyVolumeEntry map[string]float64

type DailyVolumeEntryTemp

type DailyVolumeEntryTemp map[string]interface{}

type DailyVolumeTemp

type DailyVolumeTemp map[string]interface{}

type DepositsWithdrawals

type DepositsWithdrawals struct {
	Deposits    []deposit
	Withdrawals []withdrawal
}

DepositsWithdrawals holds the history of deposit and withdrawal

type FeeInfo

type FeeInfo struct {
	MakerFee        float64 `json:"makerFee,string"`
	TakerFee        float64 `json:"takerFee,string"`
	ThirtyDayVolume float64 `json:"thirtyDayVolume,string"`
	NextTier        float64 `json:"nextTier,string"`
}

type LoanOffer

type LoanOffer struct {
	Base
	OrderID int64 `json:"orderID"`
}

type LoanOrder

type LoanOrder struct {
	Rate     float64 `json:",string"`
	Amount   float64 `json:",string"`
	RangeMin float64
	RangeMax float64
}

type LoanOrders

type LoanOrders struct {
	Offers  []LoanOrder
	Demands []LoanOrder
}

type MarginAccountSummary

type MarginAccountSummary struct {
	TotalValue         float64 `json:"totalValue,string"`
	ProfitLoss         float64 `json:"pl,string"`
	LendingFees        float64 `json:"lendingFees,string"`
	NetValue           float64 `json:"netValue,string"`
	TotalBorrowedValue float64 `json:"totalBorrowedValue,string"`
	CurrentMargin      float64 `json:"currentMargin,string"`
}

type MoveOrder

type MoveOrder struct {
	Base
	OrderNumber int64 `json:",string"`
}

type OpenLoanOffer

type OpenLoanOffer struct {
	ID        int64   `json:"id"`
	Rate      float64 `json:",string"`
	Amount    float64 `json:",string"`
	Duration  int64
	Renewable bool
	AutoRenew int64 `json:"autoRenew"`
	Date      string
	DateTaken time.Time
}

type OpenLoanOffers

type OpenLoanOffers map[string][]OpenLoanOffer

type OpenOrder

type OpenOrder struct {
	OrderNumber int64 `json:",string"`
	Type        string
	Rate        float64 `json:",string"`
	Amount      float64 `json:",string"`
	Total       float64 `json:",string"`
}

OpenOrder is a singular entry used in the OpenOrders type

type OpenOrders

type OpenOrders []OpenOrder

OpenOrders is the list of open orders for the pair specified

type OpenOrdersAll

type OpenOrdersAll map[string]OpenOrders

OpenOrdersAll is used for all pairs

type Order

type Order struct {
	Rate   float64
	Amount float64
}

type OrderBook

type OrderBook struct {
	Asks     []Order
	Bids     []Order
	IsFrozen bool
}
Example
p := NewPublicOnly()
ob, err := p.OrderBook("BTC_ETH")
if err != nil {
	log.Fatalln(err)
}
pp.Println(ob.Asks[0], ob.Bids[0])

type OrderBookAll

type OrderBookAll map[string]OrderBook

type OrderBookAllTemp

type OrderBookAllTemp map[string]OrderBookTemp

type OrderBookTemp

type OrderBookTemp struct {
	Asks     []OrderTemp
	Bids     []OrderTemp
	IsFrozen interface{}
}

type OrderTemp

type OrderTemp []interface{}

type OrderTrade

type OrderTrade struct {
	GlobalTradeID int64   `json:"globalTradeID"`
	TradeID       int64   `json:"tradeID"`
	CurrencyPair  string  `json:"currencyPair"`
	Type          string  `json:"type"`
	Rate          float64 `json:"rate,string"`
	Amount        float64 `json:"amount,string"`
	Total         float64 `json:"total,string"`
	Fee           float64 `json:"fee,string"`
	Date          string  `json:"date"`
}

type OrderTrades

type OrderTrades []OrderTrade

type Poloniex

type Poloniex struct {
	Key    string
	Secret string

	ByID   map[string]string
	ByName map[string]string
	// contains filtered or unexported fields
}

Poloniex describes the API

func New

func New(configfile string) *Poloniex

New is the legacy way to create a new client, here just to maintain api

func NewPublicOnly

func NewPublicOnly() *Poloniex

NewPublicOnly allows the use of the public and websocket api only

func NewWithConfig

func NewWithConfig(configfile string) *Poloniex

NewWithConfig is the replacement function for New, pass in a configfile to use

func NewWithCredentials

func NewWithCredentials(key, secret string) *Poloniex

NewWithCredentials allows to pass in the key and secret directly

func (*Poloniex) AccountBalances

func (p *Poloniex) AccountBalances() (balances AccountBalances, err error)

func (*Poloniex) ActiveLoans

func (p *Poloniex) ActiveLoans() (activeLoans ActiveLoans, err error)

func (*Poloniex) Addresses

func (p *Poloniex) Addresses() (addresses Addresses, err error)

func (*Poloniex) AvailableAccountBalances

func (p *Poloniex) AvailableAccountBalances() (aab AvailableAccountBalances, err error)

func (*Poloniex) Balances

func (p *Poloniex) Balances() (balances Balances, err error)

func (*Poloniex) Buy

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

func (*Poloniex) BuyFillKill

func (p *Poloniex) BuyFillKill(pair string, rate, amount float64) (buy Buy, err error)

func (*Poloniex) BuyPostOnly

func (p *Poloniex) BuyPostOnly(pair string, rate, amount float64) (buy Buy, err error)

func (*Poloniex) CancelLoanOffer

func (p *Poloniex) CancelLoanOffer(orderNumber int64) (success bool, err error)

func (*Poloniex) CancelOrder

func (p *Poloniex) CancelOrder(orderNumber int64) (success bool, err error)

func (*Poloniex) ChartData

func (p *Poloniex) ChartData(pair string) (chartData ChartData, err error)

func (*Poloniex) ChartDataCurrent

func (p *Poloniex) ChartDataCurrent(pair string) (chartData ChartData, err error)

func (*Poloniex) ChartDataPeriod

func (p *Poloniex) ChartDataPeriod(pair string, start, end time.Time, period ...int) (chartData ChartData, err error)

func (*Poloniex) Currencies

func (p *Poloniex) Currencies() (currencies Currencies, err error)

func (*Poloniex) DailyVolume

func (p *Poloniex) DailyVolume() (dailyVolume DailyVolume, err error)

func (*Poloniex) Debug

func (p *Poloniex) Debug()

Debug turns on debugmode, which basically dumps all responses from the poloniex API REST server

func (*Poloniex) DepositsWithdrawals

func (p *Poloniex) DepositsWithdrawals() (depositsWithdrawals DepositsWithdrawals, err error)

func (*Poloniex) Emit

func (p *Poloniex) Emit(event interface{}, arguments ...interface{}) *emission.Emitter

func (*Poloniex) FeeInfo

func (p *Poloniex) FeeInfo() (fi FeeInfo, err error)

func (*Poloniex) GenerateNewAddress

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

func (*Poloniex) LoanOffer

func (p *Poloniex) LoanOffer(currency string, amount float64, duration int, renew bool, lendingRate float64) (loanOffer LoanOffer, err error)

func (*Poloniex) LoanOrders

func (p *Poloniex) LoanOrders(currency string) (loanOrders LoanOrders, err error)

func (*Poloniex) MarginAccountSummary

func (p *Poloniex) MarginAccountSummary() (mas MarginAccountSummary, err error)

func (*Poloniex) Move

func (p *Poloniex) Move(orderNumber int64, rate float64) (moveOrder MoveOrder, err error)

func (*Poloniex) MovePostOnly

func (p *Poloniex) MovePostOnly(orderNumber int64, rate float64) (moveOrder MoveOrder, err error)

func (*Poloniex) Off

func (p *Poloniex) Off(event interface{}, listener interface{}) *emission.Emitter

func (*Poloniex) On

func (p *Poloniex) On(event interface{}, listener interface{}) *emission.Emitter

func (*Poloniex) OpenLoanOffers

func (p *Poloniex) OpenLoanOffers() (openLoanOffers OpenLoanOffers, err error)

func (*Poloniex) OpenOrders

func (p *Poloniex) OpenOrders(pair string) (openOrders OpenOrders, err error)

func (*Poloniex) OpenOrdersAll

func (p *Poloniex) OpenOrdersAll() (openOrders OpenOrdersAll, err error)

func (*Poloniex) OrderBook

func (p *Poloniex) OrderBook(pair string) (orderBook OrderBook, err error)

func (*Poloniex) OrderBookAll

func (p *Poloniex) OrderBookAll() (orderBook OrderBookAll, err error)

func (*Poloniex) OrderTrades

func (p *Poloniex) OrderTrades(orderNumber int64) (ot OrderTrades, err error)

func (*Poloniex) PrivateTradeHistory

func (p *Poloniex) PrivateTradeHistory(in ...interface{}) (history PrivateTradeHistory, err error)

PrivateTradeHistory takes a string pair and 2 unix timestamps as the start and end date period for the request.

func (*Poloniex) PrivateTradeHistoryAll

func (p *Poloniex) PrivateTradeHistoryAll(in ...interface{}) (history PrivateTradeHistoryAll, err error)

PrivateTradeHistoryAll takes 2 unix timestamps as the start and end date period for the request.

func (*Poloniex) Sell

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

func (*Poloniex) SellFillKill

func (p *Poloniex) SellFillKill(pair string, rate, amount float64) (sell Sell, err error)

func (*Poloniex) SellPostOnly

func (p *Poloniex) SellPostOnly(pair string, rate, amount float64) (sell Sell, err error)

func (*Poloniex) StartWS

func (p *Poloniex) StartWS()

func (*Poloniex) Subscribe

func (p *Poloniex) Subscribe(chid string) error

func (*Poloniex) Ticker

func (p *Poloniex) Ticker() (ticker Ticker, err error)

func (*Poloniex) ToggleAutoRenew

func (p *Poloniex) ToggleAutoRenew(orderNumber int64) (success bool, err error)

func (*Poloniex) TradableBalances

func (p *Poloniex) TradableBalances() (tb TradableBalances, err error)

func (*Poloniex) TradeHistory

func (p *Poloniex) TradeHistory(pair string, start, end time.Time) (tradeHistory TradeHistory, err error)

func (*Poloniex) TransferBalance

func (p *Poloniex) TransferBalance(currency string, amount float64, from string, to string) (tb TransferBalance, err error)

func (*Poloniex) Unsubscribe

func (p *Poloniex) Unsubscribe(chid string) error

func (*Poloniex) WSIdle

func (p *Poloniex) WSIdle(dur time.Duration, callbacks ...WSReportFunc)

func (*Poloniex) Withdraw

func (p *Poloniex) Withdraw(currency string, amount float64, address string) (w Withdraw, err error)

type PoloniexError

type PoloniexError struct {
	Error string `json:"error"`
}

type PrivateTradeHistory

type PrivateTradeHistory []PrivateTradeHistoryEntry

type PrivateTradeHistoryAll

type PrivateTradeHistoryAll map[string]PrivateTradeHistory

type PrivateTradeHistoryEntry

type PrivateTradeHistoryEntry struct {
	Date          string
	Rate          float64 `json:",string"`
	Amount        float64 `json:",string"`
	Total         float64 `json:",string"`
	OrderNumber   int64   `json:",string"`
	Type          string
	GlobalTradeID int64 `json:"globalTradeID"`
}

type ResultingTrade

type ResultingTrade struct {
	Amount  float64 `json:",string"`
	Rate    float64 `json:",string"`
	Date    string
	Total   float64 `json:",string"`
	TradeID string  `json:"tradeID"`
	Type    string
}

type Sell

type Sell struct {
	Buy
}

type Ticker

type Ticker map[string]TickerEntry

type TickerEntry

type TickerEntry struct {
	Last        float64 `json:",string"`
	Ask         float64 `json:"lowestAsk,string"`
	Bid         float64 `json:"highestBid,string"`
	Change      float64 `json:"percentChange,string"`
	BaseVolume  float64 `json:"baseVolume,string"`
	QuoteVolume float64 `json:"quoteVolume,string"`
	IsFrozen    int64   `json:"isFrozen,string"`
	ID          int64   `json:"id"`
}

type TradableBalance

type TradableBalance map[string]float64

type TradableBalanceTemp

type TradableBalanceTemp map[string]json.Number

type TradableBalances

type TradableBalances map[string]TradableBalance

type TradableBalancesTemp

type TradableBalancesTemp map[string]TradableBalanceTemp

type TradeHistory

type TradeHistory []TradeHistoryEntry

type TradeHistoryEntry

type TradeHistoryEntry struct {
	ID     int64 `json:"globalTradeID"`
	Date   string
	Type   string
	Rate   float64 `json:",string"`
	Amount float64 `json:",string"`
	Total  float64 `json:",string"`
}

type TransferBalance

type TransferBalance struct {
	Base
	Message string `json:"message"`
}

type WSOrderbook

type WSOrderbook struct {
	Pair    string
	Event   string
	TradeID int64
	Type    string
	Rate    float64
	Amount  float64
	Total   float64
	TS      time.Time
}

type WSReportFunc

type WSReportFunc = func(time.Time)

type WSTicker

type WSTicker struct {
	Pair          string
	Last          float64
	Ask           float64
	Bid           float64
	PercentChange float64
	BaseVolume    float64
	QuoteVolume   float64
	IsFrozen      bool
	DailyHigh     float64
	DailyLow      float64
	PairID        int64
}

WSTicker describes a ticker item

type Withdraw

type Withdraw struct {
	Base
}

Jump to

Keyboard shortcuts

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