poloniex

package module
v0.0.0-...-231589b Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2021 License: MIT Imports: 14 Imported by: 8

README

go-poloniex

go-poloniex is an implementation of the Poloniex API (public and private) in Golang.

Based off of https://github.com/toorop/go-bittrex/

This library is more of a framework for some bots I use so it is expected that a lot of things don't work but pull requests are accepted.

Import

import "github.com/jyap808/go-poloniex"

Usage

package main

import (
	"fmt"
	"github.com/jyap808/go-poloniex"
)

const (
	API_KEY    = "YOUR_API_KEY"
	API_SECRET = "YOUR_API_SECRET"
)

func main() {
	// Poloniex client
	poloniex := poloniex.New(API_KEY, API_SECRET)

	// Get tickers
    tickers, err := poloniex.GetTickers()
	fmt.Println(err, tickers)
}

See "Examples" folder for more... examples

Stay tuned

Follow me on Twitter

Documentation

Overview

Package Poloniex is an implementation of the Poloniex API in Golang.

Index

Constants

View Source
const (
	TRADE_FILL_OR_KILL        = "fillOrKill"
	TRADE_IMMEDIATE_OR_CANCEL = "immediateOrCancel"
	TRADE_POST_ONLY           = "postOnly"
)
View Source
const (
	API_BASE = "https://poloniex.com" // Poloniex API endpoint
)

Variables

This section is empty.

Functions

func NewClient

func NewClient(apiKey, apiSecret string) (c *client)

NewClient return a new Poloniex HTTP client

func NewClientWithCustomTimeout

func NewClientWithCustomTimeout(apiKey, apiSecret string, timeout time.Duration) (c *client)

NewClientWithCustomTimeout returns a new Poloniex HTTP client with custom timeout

Types

type Balance

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

type CandleStick

type CandleStick struct {
	Date            PoloniexDate `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 Currencies

type Currencies struct {
	Pair map[string]Currency
}

type Currency

type Currency struct {
	Id                 int     `json:"id"`
	Name               string  `json:"name"`
	MaxDailyWithdrawal string  `json:"maxDailyWithdrawal"`
	TxFee              float64 `json:"txFee,string"`
	MinConf            int     `json:"minConf"`
	Disabled           int     `json:"disabled"`
	Frozen             int     `json:"frozen"`
	Delisted           int     `json:"delisted"`
	IsGeofenced        int     `json:"isGeofenced"`
}

type Deposit

type Deposit struct {
	Currency      string    `json:"currency"`
	Address       string    `json:"address"`
	Amount        float64   `json:"amount,string"`
	Confirmations uint64    `json:"confirmations"`
	TxId          string    `json:"txid"`
	Date          time.Time `json:"timestamp"`
	Status        string    `json:"status"`
}

func (*Deposit) UnmarshalJSON

func (t *Deposit) UnmarshalJSON(data []byte) error

type Lending

type Lending struct {
	Id       uint64    `json:"id"`
	Currency string    `json:"currency"`
	Rate     float64   `json:"rate,string"`
	Amount   float64   `json:"amount,string"`
	Duration float64   `json:"duration,string"`
	Interest float64   `json:"interest,string"`
	Fee      float64   `json:"fee,string"`
	Earned   float64   `json:"earned,string"`
	Open     time.Time `json:"open,string"`
	Close    time.Time `json:"close,string"`
}

func (*Lending) UnmarshalJSON

func (t *Lending) UnmarshalJSON(data []byte) error

type OpenOrder

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

type OrderBook

type OrderBook struct {
	Asks     [][]interface{} `json:"asks"`
	Bids     [][]interface{} `json:"bids"`
	IsFrozen int             `json:"isFrozen,string"`
	Error    string          `json:"error"`
}

type Poloniex

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

poloniex represent a poloniex client

func New

func New(apiKey, apiSecret string) *Poloniex

New returns an instantiated poloniex struct

func NewWithCustomTimeout

func NewWithCustomTimeout(apiKey, apiSecret string, timeout time.Duration) *Poloniex

New returns an instantiated poloniex struct with custom timeout

func (*Poloniex) Buy

func (b *Poloniex) Buy(pair string, rate float64, amount float64, tradeType string) (TradeOrder, error)

func (*Poloniex) CancelOrder

func (b *Poloniex) CancelOrder(orderNumber string) error

func (*Poloniex) ChartData

func (b *Poloniex) ChartData(currencyPair string, period int, start, end time.Time) (candles []*CandleStick, err error)

Returns candlestick chart data. Required GET parameters are "currencyPair", "period" (candlestick period in seconds; valid values are 300, 900, 1800, 7200, 14400, and 86400), "start", and "end". "Start" and "end" are given in UNIX timestamp format and used to specify the date range for the data returned.

func (*Poloniex) GetBalances

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

func (*Poloniex) GetCurrencies

func (b *Poloniex) GetCurrencies() (currencies Currencies, err error)

func (*Poloniex) GetDepositsWithdrawals

func (b *Poloniex) GetDepositsWithdrawals(start uint32, end uint32) (deposits []Deposit, withdrawals []Withdrawal, err error)

func (*Poloniex) GetOpenOrders

func (b *Poloniex) GetOpenOrders(pair string) (openOrders map[string][]OpenOrder, err error)

func (*Poloniex) GetOrderBook

func (b *Poloniex) GetOrderBook(market, cat string, depth int) (orderBook OrderBook, err error)

GetOrderBook is used to get retrieve the orderbook for a given market market: a string literal for the market (ex: BTC_NXT). 'all' not implemented. cat: bid, ask or both to identify the type of orderbook to return. depth: how deep of an order book to retrieve

func (*Poloniex) GetOrderTrades

func (b *Poloniex) GetOrderTrades(orderNumber int) (tradeOrderTransaction []TradeOrderTransaction, err error)

GetOrderTrades is used to get returns all trades involving a given order orderNumber: order number.

func (*Poloniex) GetTickers

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

GetTickers is used to get the ticker for all markets

func (*Poloniex) GetTradeHistory

func (b *Poloniex) GetTradeHistory(pair string, start uint32) (trades map[string][]Trade, err error)

func (*Poloniex) GetVolumes

func (b *Poloniex) GetVolumes() (vc VolumeCollection, err error)

GetVolumes is used to get the volume for all markets

func (*Poloniex) LendingHistory

func (b *Poloniex) LendingHistory(start, end time.Time, limit int) (lendings []Lending, err error)

Returns whole lending history chart data. Required GET parameters are "start", "end" (UNIX timestamp format and used to specify the date range for the data returned) and optionally limit (<0 for no limit, poloniex automatically limits to 500 records)

func (*Poloniex) Sell

func (b *Poloniex) Sell(pair string, rate float64, amount float64, tradeType string) (TradeOrder, error)

func (*Poloniex) SetDebug

func (c *Poloniex) SetDebug(enable bool)

set enable/disable http request/response dump

type PoloniexDate

type PoloniexDate struct {
	time.Time
}

func (*PoloniexDate) UnmarshalJSON

func (pd *PoloniexDate) UnmarshalJSON(data []byte) error

type ResultingTrade

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

type Ticker

type Ticker struct {
	Id            int     `json:"id"`
	Last          float64 `json:"last,string"`
	LowestAsk     float64 `json:"lowestAsk,string"`
	HighestBid    float64 `json:"highestBid,string"`
	PercentChange float64 `json:"percentChange,string"`
	BaseVolume    float64 `json:"baseVolume,string"`
	QuoteVolume   float64 `json:"quoteVolume,string"`
	IsFrozen      int     `json:"isFrozen,string"`
	High24Hr      float64 `json:"high24hr,string"`
	Low24Hr       float64 `json:"low24hr,string"`
}

type Tickers

type Tickers struct {
	Pair map[string]Ticker
}

type Trade

type Trade struct {
	GlobalTradeID uint64    `json:"globalTradeID"`
	TradeID       uint64    `json:"tradeID,string"`
	Date          time.Time `json:"date,string"`
	Type          string    `json:"type"`
	Category      string    `json:"category"`
	Rate          float64   `json:"rate,string"`
	Amount        float64   `json:"amount,string"`
	Total         float64   `json:"total,string"`
	Fee           float64   `json:"fee,string"`
}

func (*Trade) UnmarshalJSON

func (t *Trade) UnmarshalJSON(data []byte) error

type TradeOrder

type TradeOrder struct {
	OrderNumber     string           `json:"orderNumber"`
	ResultingTrades []ResultingTrade `json:"resultingTrades"`
	ErrorMessage    string           `json:"error"`
}

type TradeOrderTransaction

type TradeOrderTransaction struct {
	GlobalTradeID uint64    `json:"globalTradeID"`
	TradeID       uint64    `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          time.Time `json:"date,string"`
}

type Volume

type Volume map[string]float64

func (*Volume) UnmarshalJSON

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

type VolumeCollection

type VolumeCollection struct {
	TotalBNB  float64 `json:"totalBNB,string"`
	TotalBTC  float64 `json:"totalBTC,string"`
	TotalBUSD float64 `json:"totalBUSD,string"`
	TotalDAI  float64 `json:"totalDAI,string"`
	TotalETH  float64 `json:"totalETH,string"`
	TotalPAX  float64 `json:"totalPAX,string"`
	TotalTRX  float64 `json:"totalTRX,string"`
	TotalTUSD float64 `json:"totalTUSD,string"`
	TotalUSDC float64 `json:"totalUSDC,string"`
	TotalUSDJ float64 `json:"totalUSDJ,string"`
	TotalUSDT float64 `json:"totalUSDT,string"`
	TotalXMR  float64 `json:"totalXMR,string"`
	TotalXUSD float64 `json:"totalXUSD,string"`
	Volumes   map[string]Volume
}

func (*VolumeCollection) UnmarshalJSON

func (tc *VolumeCollection) UnmarshalJSON(b []byte) error

type Withdrawal

type Withdrawal struct {
	WithdrawalNumber uint64    `json:"withdrawalNumber"`
	Currency         string    `json:"currency"`
	Address          string    `json:"address"`
	Amount           float64   `json:"amount,string"`
	Date             time.Time `json:"timestamp"`
	Status           string    `json:"status"`
	TxId             string    `json:"txid"`
	IpAddress        string    `json:"ipAddress"`
}

func (*Withdrawal) UnmarshalJSON

func (t *Withdrawal) UnmarshalJSON(data []byte) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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