poloniex

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2025 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BASE_URL       = "https://poloniex.com/"
	TRADE_API      = BASE_URL + "tradingApi"
	PUBLIC_URL     = BASE_URL + "public"
	TICKER_API     = "?command=returnTicker"
	CURRENCIES_API = "?command=returnCurrencies"
	ORDER_BOOK_API = "?command=returnOrderBook&currencyPair=%s&depth=%d"
)
View Source
const EXCHANGE_NAME = "poloniex.com"

Variables

This section is empty.

Functions

func Sym2duo

func Sym2duo(pair string) q.D

Types

type DepositsWithdrawals

type DepositsWithdrawals struct {
	Deposits []struct {
		Currency      string    `json:"currency"`
		Address       string    `json:"address"`
		Amount        float64   `json:"amount,string"`
		Confirmations int       `json:"confirmations"`
		TransactionID string    `json:"txid"`
		Timestamp     time.Time `json:"timestamp"`
		Status        string    `json:"status"`
	} `json:"deposits"`
	Withdrawals []struct {
		WithdrawalNumber int64     `json:"withdrawalNumber"`
		Currency         string    `json:"currency"`
		Address          string    `json:"address"`
		Amount           float64   `json:"amount,string"`
		Confirmations    int       `json:"confirmations"`
		TransactionID    string    `json:"txid"`
		Timestamp        time.Time `json:"timestamp"`
		Status           string    `json:"status"`
		IPAddress        string    `json:"ipAddress"`
	} `json:"withdrawals"`
}

type GenericResponse

type GenericResponse struct {
	Success int    `json:"success"`
	Error   string `json:"error"`
}

type MarginPosition

type MarginPosition struct {
	Amount            float64 `json:"amount,string"`
	Total             float64 `json:"total,string"`
	BasePrice         float64 `json:"basePrice,string"`
	LiquidiationPrice float64 `json:"liquidiationPrice"`
	ProfitLoss        float64 `json:"pl,string"`
	LendingFees       float64 `json:"lendingFees,string"`
	Type              string  `json:"type"`
}

type Poloniex

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

func New

func New(client *http.Client, accessKey, secretKey string) *Poloniex

func (*Poloniex) AllTicker

func (poloniex *Poloniex) AllTicker(SymPair map[string]q.D) (mdt *sync.Map, err error)

func (*Poloniex) Balances

func (poloniex *Poloniex) Balances() (availables, frozens *sync.Map, err error)

func (*Poloniex) CancelOrder

func (poloniex *Poloniex) CancelOrder(orderId string, currency CurrencyPair) (bool, error)

func (*Poloniex) CloseMarginPosition

func (poloniex *Poloniex) CloseMarginPosition(currency CurrencyPair) (bool, error)

func (*Poloniex) Fee

func (poloniex *Poloniex) Fee() float64

func (*Poloniex) GetAccount

func (poloniex *Poloniex) GetAccount() (*Account, error)

func (*Poloniex) GetAllCurrencies

func (poloniex *Poloniex) GetAllCurrencies() (map[string]*PoloniexCurrency, error)

func (*Poloniex) GetAttr

func (poloniex *Poloniex) GetAttr() (a q.Attr)

func (*Poloniex) GetDepositsWithdrawals

func (poloniex *Poloniex) GetDepositsWithdrawals(start, end string) (*DepositsWithdrawals, error)

func (*Poloniex) GetDepth

func (poloniex *Poloniex) GetDepth(size int, currency CurrencyPair) (*Depth, error)

func (*Poloniex) GetKlineRecords

func (poloniex *Poloniex) GetKlineRecords(currency CurrencyPair, period KlinePeriod, size int, optional ...OptionalParameter) ([]Kline, error)

func (*Poloniex) GetMarginPosition

func (poloniex *Poloniex) GetMarginPosition(currency CurrencyPair) (*MarginPosition, error)

func (*Poloniex) GetOneOrder

func (poloniex *Poloniex) GetOneOrder(orderId string, currency CurrencyPair) (*Order, error)

func (*Poloniex) GetOrderHistorys

func (poloniex *Poloniex) GetOrderHistorys(currency CurrencyPair, opt ...OptionalParameter) ([]Order, error)

func (*Poloniex) GetTicker

func (poloniex *Poloniex) GetTicker(currency CurrencyPair) (*Ticker, error)

func (*Poloniex) GetTrades

func (poloniex *Poloniex) GetTrades(currencyPair CurrencyPair, since int64) ([]Trade, error)

func (*Poloniex) GetUnfinishedOrders

func (poloniex *Poloniex) GetUnfinishedOrders(currency CurrencyPair) ([]Order, error)

func (*Poloniex) LimitBuy

func (poloniex *Poloniex) LimitBuy(amount, price string, currency CurrencyPair, opt ...LimitOrderOptionalParameter) (*Order, error)

func (*Poloniex) LimitSell

func (poloniex *Poloniex) LimitSell(amount, price string, currency CurrencyPair, opt ...LimitOrderOptionalParameter) (*Order, error)

func (*Poloniex) MarginLimitBuy

func (poloniex *Poloniex) MarginLimitBuy(amount, price string, currency CurrencyPair) (*Order, error)

func (*Poloniex) MarginLimitSell

func (poloniex *Poloniex) MarginLimitSell(amount, price string, currency CurrencyPair) (*Order, error)

func (*Poloniex) MarketBuy

func (poloniex *Poloniex) MarketBuy(amount, price string, currency CurrencyPair) (*Order, error)

func (*Poloniex) MarketSell

func (poloniex *Poloniex) MarketSell(amount, price string, currency CurrencyPair) (*Order, error)

func (*Poloniex) OneTicker

func (poloniex *Poloniex) OneTicker(d q.D) (ticker q.Bbo, err error)

func (*Poloniex) PairArray

func (poloniex *Poloniex) PairArray() (map[string]q.D, map[q.D]q.P, error)

func (*Poloniex) PlaceOrders

func (poloniex *Poloniex) PlaceOrders(places [3]q.Order) (orders [3]q.Order, err error)

func (*Poloniex) Post

func (poloniex *Poloniex) Post(params url.Values) (resp []byte, err error)

func (polo *Poloniex) OrderBook() (mdt *sync.Map, err error) {

	url := PUBLIC_URL + TICKER_API
	ret, err := HttpGet(polo.client, url)
	if err != nil {
		return nil, err
	}
	for pairrev, v := range ret {
		pair := Sym2duo(pairrev)
		tickermap, ok := v.(map[string]any)
		if !ok {
			return nil, errors.New("not found")
		}
		isFrozen, _ := strconv.ParseFloat(tickermap["isFrozen"].(string), 64)
		if isFrozen == 0 {
			var ticker BBO
			ticker.Pair = pairrev
			ticker.Bid, _ = strconv.ParseFloat(tickermap["highestBid"].(string), 64)
			ticker.Ask, _ = strconv.ParseFloat(tickermap["lowestAsk"].(string), 64)
			ticker.BidSize = 1e-12
			ticker.AskSize = 1e-12
			ticker.High, _ = strconv.ParseFloat(tickermap["high24hr"].(string), 64)
			ticker.Low, _ = strconv.ParseFloat(tickermap["low24hr"].(string), 64)
			ticker.Last, _ = strconv.ParseFloat(tickermap["last"].(string), 64)
			ticker.Vol, _ = strconv.ParseFloat(tickermap["quoteVolume"].(string), 64)
			if ticker.Valid() {
				mdt.Store(pair,ticker)
			}
		} else {
			logs.I(pair, "isFrozen")
		}
	}
	return
}

func (*Poloniex) String

func (poloniex *Poloniex) String() string

func (*Poloniex) Test

func (poloniex *Poloniex) Test() bool

func (*Poloniex) TradeFee

func (poloniex *Poloniex) TradeFee() (map[string]q.TradeFee, error)

func (*Poloniex) Withdraw

func (poloniex *Poloniex) Withdraw(amount string, currency Currency, fees, receiveAddr, safePwd string) (string, error)

func (*Poloniex) WithdrawFee

func (poloniex *Poloniex) WithdrawFee() (sf []q.NetworkWithdraw, err error)

Jump to

Keyboard shortcuts

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