anx

package
v0.0.0-...-eb07c7e Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2019 License: MIT Imports: 16 Imported by: 0

README

GoCryptoTrader package Anx

Build Status Software License GoDoc Coverage Status Go Report Card

This anx package is part of the GoCryptoTrader codebase.

This is still in active development

You can track ideas, planned features and what's in progresss on this Trello board: https://trello.com/b/ZAhMhpOy/gocryptotrader.

Join our slack to discuss all things related to GoCryptoTrader! GoCryptoTrader Slack

ANX Exchange

Current Features
  • REST functions
Features not yet included
  • Long polling streaming
How to enable
  // Exchanges will be abstracted out in further updates and examples will be
  // supplied then
How to do REST public/private calls
  • If enabled via "configuration".json file the exchange will be added to the IBotExchange array in the go var bot Bot and you will only be able to use the wrapper interface functions for accessing exchange data. View routines.go for an example of integration usage with GoCryptoTrader. Rudimentary example below:

main.go

var a exchange.IBotExchange

for i := range bot.exchanges {
  if bot.exchanges[i].GetName() == "ANX" {
    a = bot.exchanges[i]
  }
}

// Public calls - wrapper functions

// Fetches current ticker information
tick, err := a.GetTickerPrice()
if err != nil {
  // Handle error
}

// Fetches current orderbook information
ob, err := a.GetOrderbookEx()
if err != nil {
  // Handle error
}

// Private calls - wrapper functions - make sure your APIKEY and APISECRET are
// set and AuthenticatedAPISupport is set to true

// Fetches current account information
accountInfo, err := a.GetAccountInfo()
if err != nil {
  // Handle error
}
  • If enabled via individually importing package, rudimentary example below:
// Public calls

// Fetches current ticker information
ticker, err := a.GetTicker()
if err != nil {
  // Handle error
}

// Fetches current orderbook information
ob, err := a.GetOrderBook()
if err != nil {
  // Handle error
}

// Private calls - make sure your APIKEY and APISECRET are set and
// AuthenticatedAPISupport is set to true

// GetUserInfo returns account info
accountInfo, err := a.GetUserInfo(...)
if err != nil {
  // Handle error
}

// Submits an order and the exchange and returns its tradeID
tradeID, err := a.Trade(...)
if err != nil {
  // Handle error
}
How to do LongPolling public/private calls
  // Exchanges will be abstracted out in further updates and examples will be
  // supplied then
Please click GoDocs chevron above to view current GoDoc information for this package

Contribution

Please feel free to submit any pull requests or suggest any desired features to be added.

When submitting a PR, please abide by our coding guidelines:

  • Code must adhere to the official Go formatting guidelines (i.e. uses gofmt).
  • Code must be documented adhering to the official Go commentary guidelines.
  • Code must adhere to our coding style.
  • Pull requests need to be based on and opened against the master branch.

Donations

If this framework helped you in any way, or you would like to support the developers working on it, please donate Bitcoin to:

1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB

Documentation

Index

Constants

View Source
const (
	CancelOrderNotFound    string = "ORDER_NOT_FOUND"
	CancelRequestSubmitted string = "CANCEL_REQUEST_SUBMITTED"
	CancelOrderWrongState  string = "ORDER_CANCEL_WRONG_STATE"
)

List of strings

Variables

View Source
var WithdrawalFees = map[currency.Code]float64{
	currency.BTC:  0.002,
	currency.DOGE: 0.1,
	currency.ETH:  0.005,
	currency.GNT:  0.001,
	currency.LTC:  0.02,
	currency.OAX:  0.001,
	currency.XRP:  1,
	currency.HKD:  0.01,
}

WithdrawalFees the large list of predefined withdrawal fees Prone to change

Functions

This section is empty.

Types

type ANX

type ANX struct {
	exchange.Base
}

ANX is the overarching type across the alphapoint package

func (*ANX) AuthenticateWebsocket

func (a *ANX) AuthenticateWebsocket() error

AuthenticateWebsocket sends an authentication message to the websocket

func (*ANX) CancelAllOrders

CancelAllOrders cancels all orders associated with a currency pair

func (*ANX) CancelOrder

func (a *ANX) CancelOrder(order *exchange.OrderCancellation) error

CancelOrder cancels an order by its corresponding ID number

func (*ANX) CancelOrderByIDs

func (a *ANX) CancelOrderByIDs(orderIds []string) (OrderCancelResponse, error)

CancelOrderByIDs cancels orders, requires already knowing order IDs There is no existing API call to retrieve orderIds

func (*ANX) CheckAPIWithdrawPermission

func (a *ANX) CheckAPIWithdrawPermission() (bool, error)

CheckAPIWithdrawPermission checks if the API key is allowed to withdraw

func (*ANX) CreateNewSubAccount

func (a *ANX) CreateNewSubAccount(currency, name string) (string, error)

CreateNewSubAccount generates a new sub account

func (*ANX) GetAPIKey

func (a *ANX) GetAPIKey(username, password, otp, deviceID string) (apiKey, apiSecret string, err error)

GetAPIKey returns a new generated API key set.

func (*ANX) GetAccountInfo

func (a *ANX) GetAccountInfo() (exchange.AccountInfo, error)

GetAccountInfo retrieves balances for all enabled currencies on the exchange

func (*ANX) GetAccountInformation

func (a *ANX) GetAccountInformation() (AccountInformation, error)

GetAccountInformation retrieves details including API permissions

func (*ANX) GetActiveOrders

func (a *ANX) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest) ([]exchange.OrderDetail, error)

GetActiveOrders retrieves any orders that are active/open

func (*ANX) GetCurrencies

func (a *ANX) GetCurrencies() (CurrenciesStore, error)

GetCurrencies returns a list of supported currencies (both fiat and cryptocurrencies)

func (*ANX) GetDataToken

func (a *ANX) GetDataToken() (string, error)

GetDataToken returns token data

func (*ANX) GetDepositAddress

func (a *ANX) GetDepositAddress(cryptocurrency currency.Code, _ string) (string, error)

GetDepositAddress returns a deposit address for a specified currency

func (*ANX) GetDepositAddressByCurrency

func (a *ANX) GetDepositAddressByCurrency(currency, name string, newAddr bool) (string, error)

GetDepositAddressByCurrency returns a deposit address for a specific currency

func (*ANX) GetDepth

func (a *ANX) GetDepth(currency string) (Depth, error)

GetDepth returns current orderbook depth.

func (*ANX) GetExchangeHistory

func (a *ANX) GetExchangeHistory(p currency.Pair, assetType string) ([]exchange.TradeHistory, error)

GetExchangeHistory returns historic trade data since exchange opening.

func (*ANX) GetFee

func (a *ANX) GetFee(feeBuilder *exchange.FeeBuilder) (float64, error)

GetFee returns an estimate of fee based on type of transaction

func (*ANX) GetFeeByType

func (a *ANX) GetFeeByType(feeBuilder *exchange.FeeBuilder) (float64, error)

GetFeeByType returns an estimate of fee based on type of transaction

func (*ANX) GetFundingHistory

func (a *ANX) GetFundingHistory() ([]exchange.FundHistory, error)

GetFundingHistory returns funding history, deposits and withdrawals

func (*ANX) GetOrderHistory

func (a *ANX) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest) ([]exchange.OrderDetail, error)

GetOrderHistory retrieves account order information Can Limit response to specific order status

func (*ANX) GetOrderInfo

func (a *ANX) GetOrderInfo(orderID string) (exchange.OrderDetail, error)

GetOrderInfo returns information on a current open order

func (*ANX) GetOrderList

func (a *ANX) GetOrderList(isActiveOrdersOnly bool) ([]OrderResponse, error)

GetOrderList retrieves orders from the exchange

func (*ANX) GetOrderbookEx

func (a *ANX) GetOrderbookEx(p currency.Pair, assetType string) (orderbook.Base, error)

GetOrderbookEx returns the orderbook for a currency pair

func (*ANX) GetSubscriptions

func (a *ANX) GetSubscriptions() ([]exchange.WebsocketChannelSubscription, error)

GetSubscriptions returns a copied list of subscriptions

func (*ANX) GetTicker

func (a *ANX) GetTicker(currency string) (Ticker, error)

GetTicker returns the current ticker

func (*ANX) GetTickerPrice

func (a *ANX) GetTickerPrice(p currency.Pair, assetType string) (ticker.Price, error)

GetTickerPrice returns the ticker for a currency pair

func (*ANX) GetTradablePairs

func (a *ANX) GetTradablePairs() ([]string, error)

GetTradablePairs returns a list of available

func (*ANX) GetWebsocket

func (a *ANX) GetWebsocket() (*exchange.Websocket, error)

GetWebsocket returns a pointer to the exchange websocket

func (*ANX) ModifyOrder

func (a *ANX) ModifyOrder(action *exchange.ModifyOrder) (string, error)

ModifyOrder will allow of changing orderbook placement and limit to market conversion

func (*ANX) NewOrder

func (a *ANX) NewOrder(orderType string, buy bool, tradedCurrency string, tradedCurrencyAmount float64, settlementCurrency string, settlementCurrencyAmount, limitPriceSettlement float64,
	replace bool, replaceUUID string, replaceIfActive bool) (string, error)

NewOrder sends a new order request to the exchange.

func (*ANX) OrderInfo

func (a *ANX) OrderInfo(orderID string) (OrderResponse, error)

OrderInfo returns information about a specific order

func (*ANX) Run

func (a *ANX) Run()

Run implements the ANX wrapper

func (*ANX) Send

func (a *ANX) Send(currency, address, otp, amount string) (string, error)

Send withdraws a currency to an address

func (*ANX) SendAuthenticatedHTTPRequest

func (a *ANX) SendAuthenticatedHTTPRequest(path string, params map[string]interface{}, result interface{}) error

SendAuthenticatedHTTPRequest sends a authenticated HTTP request

func (*ANX) SendHTTPRequest

func (a *ANX) SendHTTPRequest(path string, result interface{}) error

SendHTTPRequest sends an unauthenticated HTTP request

func (*ANX) SetDefaults

func (a *ANX) SetDefaults()

SetDefaults sets current default settings

func (*ANX) Setup

func (a *ANX) Setup(exch *config.ExchangeConfig)

Setup is run on startup to setup exchange with config values

func (*ANX) Start

func (a *ANX) Start(wg *sync.WaitGroup)

Start starts the ANX go routine

func (*ANX) SubmitOrder

func (a *ANX) SubmitOrder(p currency.Pair, side exchange.OrderSide, orderType exchange.OrderType, amount, price float64, _ string) (exchange.SubmitOrderResponse, error)

SubmitOrder submits a new order

func (*ANX) SubscribeToWebsocketChannels

func (a *ANX) SubscribeToWebsocketChannels(channels []exchange.WebsocketChannelSubscription) error

SubscribeToWebsocketChannels appends to ChannelsToSubscribe which lets websocket.manageSubscriptions handle subscribing

func (*ANX) UnsubscribeToWebsocketChannels

func (a *ANX) UnsubscribeToWebsocketChannels(channels []exchange.WebsocketChannelSubscription) error

UnsubscribeToWebsocketChannels removes from ChannelsToSubscribe which lets websocket.manageSubscriptions handle unsubscribing

func (*ANX) UpdateOrderbook

func (a *ANX) UpdateOrderbook(p currency.Pair, assetType string) (orderbook.Base, error)

UpdateOrderbook updates and returns the orderbook for a currency pair

func (*ANX) UpdateTicker

func (a *ANX) UpdateTicker(p currency.Pair, assetType string) (ticker.Price, error)

UpdateTicker updates and returns the ticker for a currency pair

func (*ANX) WithdrawCryptocurrencyFunds

func (a *ANX) WithdrawCryptocurrencyFunds(withdrawRequest *exchange.WithdrawRequest) (string, error)

WithdrawCryptocurrencyFunds returns a withdrawal ID when a withdrawal is submitted

func (*ANX) WithdrawFiatFunds

func (a *ANX) WithdrawFiatFunds(withdrawRequest *exchange.WithdrawRequest) (string, error)

WithdrawFiatFunds returns a withdrawal ID when a withdrawal is submitted

func (*ANX) WithdrawFiatFundsToInternationalBank

func (a *ANX) WithdrawFiatFundsToInternationalBank(withdrawRequest *exchange.WithdrawRequest) (string, error)

WithdrawFiatFundsToInternationalBank returns a withdrawal ID when a withdrawal is submitted

type AccountInformation

type AccountInformation struct {
	UserUUID   string   `json:"userUuid"`
	Rights     []string `json:"Rights"`
	ResultCode string   `json:"resultCode"`
	Wallets    map[string]struct {
		Balance              Amount `json:"Balance"`
		AvailableBalance     Amount `json:"Available_Balance"`
		DailyWithdrawalLimit Amount `json:"Daily_Withdrawal_Limit"`
		MaxWithdraw          Amount `json:"Max_Withdraw"`
	} `json:"Wallets"`
}

AccountInformation Used by Get account information Retrieves details of the account and api's

type Amount

type Amount struct {
	DisplayShort string  `json:"displayShort"`
	ValueInt     int64   `json:"valueInt"`
	Currency     string  `json:"currency"`
	Display      string  `json:"display"`
	Value        float64 `json:"value"`
}

Amount basic storage of wallet details

type Currencies

type Currencies map[string]CurrencyData

Currencies stores a list of currencies

type CurrenciesStaticResponse

type CurrenciesStaticResponse struct {
	CurrenciesResponse CurrenciesStore `json:"CurrencyStatic"`
}

CurrenciesStaticResponse stores the currencyStatic response

type CurrenciesStore

type CurrenciesStore struct {
	Currencies    Currencies    `json:"currencies"`
	CurrencyPairs CurrencyPairs `json:"currencyPairs"`
	Timestamp     string        `json:"timestamp"`
	ResultCode    string        `json:"resultCode"`
}

CurrenciesStore stores the available cryptocurrencies and fiat currencies

type CurrencyData

type CurrencyData struct {
	Decimals               int     `json:"decimals"`
	MinOrderSize           float64 `json:"minOrderSize"`
	MaxOrderSize           float64 `json:"maxOrderSize"`
	DisplayDenominator     float64 `json:"displayDenominator"`
	SummaryDecimals        int     `json:"summaryDecimals"`
	DisplayUnit            string  `json:"displayUnit"`
	Symbol                 string  `json:"symbol"`
	Type                   string  `json:"type"`
	ConfirmationThresholds []struct {
		ConfosRequired int `json:"confosRequired"`
	} `json:"confirmationThresholds"`
	NetworkFee     float64 `json:"networkFee"`
	EngineSettings struct {
		DepositsEnabled     bool `json:"depositsEnabled"`
		WithdrawalsEnabled  bool `json:"withdrawalsEnabled"`
		DisplayEnabled      bool `json:"displayEnabled"`
		MobileAccessEnabled bool `json:"mobileAccessEnabled"`
	} `json:"engineSettings"`
	MinOrderValue       float64 `json:"minOrderValue"`
	MaxOrderValue       float64 `json:"maxOrderValue"`
	MaxMarketOrderValue float64 `json:"maxMarketOrderValue"`
	MaxMarketOrderSize  float64 `json:"maxMarketOrderSize"`
	DigitalCurrencyType string  `json:"digitalCurrencyType"`
	AssetName           string  `json:"assetName"`
	AssetDivisibility   int     `json:"assetDivisibility"`
	AssetIcon           string  `json:"assetIcon"`
	AssetIssueQuantity  string  `json:"assetIssueQuantity"`
}

CurrencyData holds the currency information

type CurrencyPairData

type CurrencyPairData struct {
	PriceDecimals  int `json:"priceDecimals"`
	EngineSettings struct {
		TradingEnabled bool `json:"tradingEnabled"`
		DisplayEnabled bool `json:"displayEnabled"`
		CancelOnly     bool `json:"cancelOnly"`
		VerifyRequired bool `json:"verifyRequired"`
		RestrictedBuy  bool `json:"restrictedBuy"`
		RestrictedSell bool `json:"restrictedSell"`
	} `json:"engineSettings"`
	MinOrderRate         float64 `json:"minOrderRate"`
	MaxOrderRate         float64 `json:"maxOrderRate"`
	DisplayPriceDecimals int     `json:"displayPriceDecimals"`
	TradedCcy            string  `json:"tradedCcy"`
	SettlementCcy        string  `json:"settlementCcy"`
	PreferredMarket      string  `json:"preferredMarket"`
	ChartEnabled         bool    `json:"chartEnabled"`
	SimpleTradeEnabled   bool    `json:"simpleTradeEnabled"`
}

CurrencyPairData holds the currency information

type CurrencyPairs

type CurrencyPairs map[string]CurrencyPairData

CurrencyPairs stores currency pair info

type Depth

type Depth struct {
	Result string `json:"result"`
	Data   struct {
		Now            string      `json:"now"`
		DataUpdateTime string      `json:"dataUpdateTime"`
		Asks           []DepthItem `json:"asks"`
		Bids           []DepthItem `json:"bids"`
	} `json:"data"`
}

Depth contains full depth information

type DepthItem

type DepthItem struct {
	Price     float64 `json:"price,string"`
	PriceInt  float64 `json:"price_int,string"`
	Amount    float64 `json:"amount,string"`
	AmountInt int64   `json:"amount_int,string"`
}

DepthItem contains depth information

type Order

type Order struct {
	OrderType                      string  `json:"orderType"`
	BuyTradedCurrency              bool    `json:"buyTradedCurrency"`
	TradedCurrency                 string  `json:"tradedCurrency"`
	SettlementCurrency             string  `json:"settlementCurrency"`
	TradedCurrencyAmount           float64 `json:"tradedCurrencyAmount,string"`
	SettlementCurrencyAmount       float64 `json:"settlementCurrencyAmount,string"`
	LimitPriceInSettlementCurrency float64 `json:"limitPriceInSettlementCurrency,string"`
	ReplaceExistingOrderUUID       string  `json:"replaceExistingOrderUuid"`
	ReplaceOnlyIfActive            bool    `json:"replaceOnlyIfActive"`
}

Order holds order information

type OrderCancelResponse

type OrderCancelResponse struct {
	OrderCancellationResponses []OrderCancellationResponse `json:"orderIds"`
	ResultCode                 string                      `json:"resultCode"`
	UUID                       int64                       `json:"uuid"`
	ErrorCode                  int64                       `json:"errorCode"`
}

OrderCancelResponse returned when cancelling multiple orders

type OrderCancellationResponse

type OrderCancellationResponse struct {
	UUID  string `json:"uuid"`
	Error string `json:"errorCode"`
}

OrderCancellationResponse contains the orderID and error when cancelling multiple orders

type OrderResponse

type OrderResponse struct {
	BuyTradedCurrency              bool    `json:"buyTradedCurrency"`
	ExecutedAverageRate            string  `json:"executedAverageRate"`
	LimitPriceInSettlementCurrency string  `json:"limitPriceInSettlementCurrency"`
	OrderID                        string  `json:"orderId"`
	OrderStatus                    string  `json:"orderStatus"`
	OrderType                      string  `json:"orderType"`
	ReplaceExistingOrderUUID       string  `json:"replaceExistingOrderId"`
	SettlementCurrency             string  `json:"settlementCurrency"`
	SettlementCurrencyAmount       float64 `json:"settlementCurrencyAmount,string"`
	SettlementCurrencyOutstanding  string  `json:"settlementCurrencyOutstanding"`
	Timestamp                      int64   `json:"timestamp"`
	TradedCurrency                 string  `json:"tradedCurrency"`
	TradedCurrencyAmount           float64 `json:"tradedCurrencyAmount,string"`
	TradedCurrencyOutstanding      string  `json:"tradedCurrencyOutstanding"`
}

OrderResponse holds order response data

type Ticker

type Ticker struct {
	Result string `json:"result"`
	Data   struct {
		High       TickerComponent `json:"high"`
		Low        TickerComponent `json:"low"`
		Avg        TickerComponent `json:"avg"`
		Vwap       TickerComponent `json:"vwap"`
		Vol        TickerComponent `json:"vol"`
		Last       TickerComponent `json:"last"`
		Buy        TickerComponent `json:"buy"`
		Sell       TickerComponent `json:"sell"`
		Now        string          `json:"now"`
		UpdateTime string          `json:"dataUpdateTime"`
	} `json:"data"`
}

Ticker contains ticker data

type TickerComponent

type TickerComponent struct {
	Currency     string `json:"currency"`
	Display      string `json:"display"`
	DisplayShort string `json:"display_short"`
	Value        string `json:"value"`
}

TickerComponent is a sub-type for ticker

Jump to

Keyboard shortcuts

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