btcmarkets

package
v0.0.0-...-4c12c4a Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2019 License: MIT Imports: 18 Imported by: 0

README

GoCryptoTrader package Btcmarkets

Build Status Software License GoDoc Coverage Status Go Report Card

This btcmarkets 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

BTCMarkets Exchange

Current Features
  • REST Support
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 b exchange.IBotExchange

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

// Public calls - wrapper functions

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

// Fetches current orderbook information
ob, err := b.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 := b.GetAccountInfo()
if err != nil {
  // Handle error
}
  • If enabled via individually importing package, rudimentary example below:
// Public calls

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

// Fetches current orderbook information
ob, err := b.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 := b.GetUserInfo(...)
if err != nil {
  // Handle error
}

// Submits an order and the exchange and returns its tradeID
tradeID, err := b.Trade(...)
if err != nil {
  // Handle error
}
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

This section is empty.

Variables

View Source
var WithdrawalFees = map[currency.Code]float64{
	currency.AUD:  0,
	currency.BTC:  0.001,
	currency.ETH:  0.001,
	currency.ETC:  0.001,
	currency.LTC:  0.0001,
	currency.XRP:  0.15,
	currency.BCH:  0.0001,
	currency.OMG:  0.15,
	currency.POWR: 5,
}

WithdrawalFees the large list of predefined withdrawal fees Prone to change

Functions

This section is empty.

Types

type AccountBalance

type AccountBalance struct {
	Balance      float64 `json:"balance"`
	PendingFunds float64 `json:"pendingFunds"`
	Currency     string  `json:"currency"`
}

AccountBalance holds account balance details

type BTCMarkets

type BTCMarkets struct {
	exchange.Base
	Ticker map[string]Ticker
}

BTCMarkets is the overarching type across the BTCMarkets package

func (*BTCMarkets) AuthenticateWebsocket

func (b *BTCMarkets) AuthenticateWebsocket() error

AuthenticateWebsocket sends an authentication message to the websocket

func (*BTCMarkets) CancelAllOrders

CancelAllOrders cancels all orders associated with a currency pair

func (*BTCMarkets) CancelExistingOrder

func (b *BTCMarkets) CancelExistingOrder(orderID []int64) ([]ResponseDetails, error)

CancelExistingOrder cancels an order by its ID orderID - id for order example "1337"

func (*BTCMarkets) CancelOrder

func (b *BTCMarkets) CancelOrder(order *exchange.OrderCancellation) error

CancelOrder cancels an order by its corresponding ID number

func (*BTCMarkets) GetAccountBalance

func (b *BTCMarkets) GetAccountBalance() ([]AccountBalance, error)

GetAccountBalance returns the full account balance

func (*BTCMarkets) GetAccountInfo

func (b *BTCMarkets) GetAccountInfo() (exchange.AccountInfo, error)

GetAccountInfo retrieves balances for all enabled currencies for the BTCMarkets exchange

func (*BTCMarkets) GetActiveOrders

func (b *BTCMarkets) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest) ([]exchange.OrderDetail, error)

GetActiveOrders retrieves any orders that are active/open

func (*BTCMarkets) GetDepositAddress

func (b *BTCMarkets) GetDepositAddress(cryptocurrency currency.Code, accountID string) (string, error)

GetDepositAddress returns a deposit address for a specified currency

func (*BTCMarkets) GetExchangeHistory

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

GetExchangeHistory returns historic trade data since exchange opening.

func (*BTCMarkets) GetFee

func (b *BTCMarkets) GetFee(feeBuilder *exchange.FeeBuilder) (float64, error)

GetFee returns an estimate of fee based on type of transaction

func (*BTCMarkets) GetFeeByType

func (b *BTCMarkets) GetFeeByType(feeBuilder *exchange.FeeBuilder) (float64, error)

GetFeeByType returns an estimate of fee based on type of transaction

func (*BTCMarkets) GetFundingHistory

func (b *BTCMarkets) GetFundingHistory() ([]exchange.FundHistory, error)

GetFundingHistory returns funding history, deposits and withdrawals

func (*BTCMarkets) GetMarkets

func (b *BTCMarkets) GetMarkets() ([]Market, error)

GetMarkets returns the BTCMarkets instruments

func (*BTCMarkets) GetOpenOrders

func (b *BTCMarkets) GetOpenOrders() ([]Order, error)

GetOpenOrders returns all open orders

func (*BTCMarkets) GetOrderDetail

func (b *BTCMarkets) GetOrderDetail(orderID []int64) ([]Order, error)

GetOrderDetail returns order information an a specific order orderID - example "1337"

func (*BTCMarkets) GetOrderHistory

func (b *BTCMarkets) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest) ([]exchange.OrderDetail, error)

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

func (*BTCMarkets) GetOrderInfo

func (b *BTCMarkets) GetOrderInfo(orderID string) (exchange.OrderDetail, error)

GetOrderInfo returns information on a current open order

func (*BTCMarkets) GetOrderbook

func (b *BTCMarkets) GetOrderbook(firstPair, secondPair string) (Orderbook, error)

GetOrderbook returns current orderbook symbol - example "btc" or "ltc"

func (*BTCMarkets) GetOrderbookEx

func (b *BTCMarkets) GetOrderbookEx(p currency.Pair, assetType string) (orderbook.Base, error)

GetOrderbookEx returns orderbook base on the currency pair

func (*BTCMarkets) GetOrders

func (b *BTCMarkets) GetOrders(currency, instrument string, limit, since int64, historic bool) ([]Order, error)

GetOrders returns current order information on the exchange currency - example "AUD" instrument - example "BTC" limit - example "10" since - since a time example "33434568724" historic - if false just normal Orders open

func (*BTCMarkets) GetSubscriptions

func (b *BTCMarkets) GetSubscriptions() ([]wshandler.WebsocketChannelSubscription, error)

GetSubscriptions returns a copied list of subscriptions

func (*BTCMarkets) GetTicker

func (b *BTCMarkets) GetTicker(firstPair, secondPair string) (Ticker, error)

GetTicker returns a ticker symbol - example "btc" or "ltc"

func (*BTCMarkets) GetTickerPrice

func (b *BTCMarkets) GetTickerPrice(p currency.Pair, assetType string) (ticker.Price, error)

GetTickerPrice returns the ticker for a currency pair

func (*BTCMarkets) GetTrades

func (b *BTCMarkets) GetTrades(firstPair, secondPair string, values url.Values) ([]Trade, error)

GetTrades returns executed trades on the exchange symbol - example "btc" or "ltc" values - optional paramater "since" example values.Set(since, "59868345231")

func (*BTCMarkets) GetTradingFee

func (b *BTCMarkets) GetTradingFee(base, quote currency.Code) (TradingFee, error)

GetTradingFee returns the account's trading fee for a currency pair

func (*BTCMarkets) GetWebsocket

func (b *BTCMarkets) GetWebsocket() (*wshandler.Websocket, error)

GetWebsocket returns a pointer to the exchange websocket

func (*BTCMarkets) ModifyOrder

func (b *BTCMarkets) ModifyOrder(action *exchange.ModifyOrder) (string, error)

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

func (*BTCMarkets) NewOrder

func (b *BTCMarkets) NewOrder(currency, instrument string, price, amount float64, orderSide, orderType, clientReq string) (int64, error)

NewOrder requests a new order and returns an ID currency - example "AUD" instrument - example "BTC" price - example 13000000000 (i.e x 100000000) amount - example 100000000 (i.e x 100000000) orderside - example "Bid" or "Ask" orderType - example "limit" clientReq - example "abc-cdf-1000"

func (*BTCMarkets) Run

func (b *BTCMarkets) Run()

Run implements the BTC Markets wrapper

func (*BTCMarkets) SendAuthenticatedRequest

func (b *BTCMarkets) SendAuthenticatedRequest(reqType, path string, data, result interface{}) (err error)

SendAuthenticatedRequest sends an authenticated HTTP request

func (*BTCMarkets) SendHTTPRequest

func (b *BTCMarkets) SendHTTPRequest(path string, result interface{}) error

SendHTTPRequest sends an unauthenticated HTTP request

func (*BTCMarkets) SetDefaults

func (b *BTCMarkets) SetDefaults()

SetDefaults sets basic defaults

func (*BTCMarkets) Setup

func (b *BTCMarkets) Setup(exch *config.ExchangeConfig)

Setup takes in an exchange configuration and sets all parameters

func (*BTCMarkets) Start

func (b *BTCMarkets) Start(wg *sync.WaitGroup)

Start starts the BTC Markets go routine

func (*BTCMarkets) SubmitOrder

func (b *BTCMarkets) SubmitOrder(p currency.Pair, side exchange.OrderSide, orderType exchange.OrderType, amount, price float64, clientID string) (exchange.SubmitOrderResponse, error)

SubmitOrder submits a new order

func (*BTCMarkets) SubscribeToWebsocketChannels

func (b *BTCMarkets) SubscribeToWebsocketChannels(channels []wshandler.WebsocketChannelSubscription) error

SubscribeToWebsocketChannels appends to ChannelsToSubscribe which lets websocket.manageSubscriptions handle subscribing

func (*BTCMarkets) UnsubscribeToWebsocketChannels

func (b *BTCMarkets) UnsubscribeToWebsocketChannels(channels []wshandler.WebsocketChannelSubscription) error

UnsubscribeToWebsocketChannels removes from ChannelsToSubscribe which lets websocket.manageSubscriptions handle unsubscribing

func (*BTCMarkets) UpdateOrderbook

func (b *BTCMarkets) UpdateOrderbook(p currency.Pair, assetType string) (orderbook.Base, error)

UpdateOrderbook updates and returns the orderbook for a currency pair

func (*BTCMarkets) UpdateTicker

func (b *BTCMarkets) UpdateTicker(p currency.Pair, assetType string) (ticker.Price, error)

UpdateTicker updates and returns the ticker for a currency pair

func (*BTCMarkets) WithdrawAUD

func (b *BTCMarkets) WithdrawAUD(accountName, accountNumber, bankName, bsbNumber string, amount float64) (string, error)

WithdrawAUD withdraws AUD into a designated bank address Does not return a TxID!

func (*BTCMarkets) WithdrawCrypto

func (b *BTCMarkets) WithdrawCrypto(amount float64, currency, address string) (string, error)

WithdrawCrypto withdraws cryptocurrency into a designated address

func (*BTCMarkets) WithdrawCryptocurrencyFunds

func (b *BTCMarkets) WithdrawCryptocurrencyFunds(withdrawRequest *exchange.WithdrawRequest) (string, error)

WithdrawCryptocurrencyFunds returns a withdrawal ID when a withdrawal is submitted

func (*BTCMarkets) WithdrawFiatFunds

func (b *BTCMarkets) WithdrawFiatFunds(withdrawRequest *exchange.WithdrawRequest) (string, error)

WithdrawFiatFunds returns a withdrawal ID when a withdrawal is submitted

func (*BTCMarkets) WithdrawFiatFundsToInternationalBank

func (b *BTCMarkets) WithdrawFiatFundsToInternationalBank(withdrawRequest *exchange.WithdrawRequest) (string, error)

WithdrawFiatFundsToInternationalBank returns a withdrawal ID when a withdrawal is submitted

type Market

type Market struct {
	Instrument string `json:"instrument"`
	Currency   string `json:"currency"`
}

Market holds a tradable market instrument

type Order

type Order struct {
	ID              int64           `json:"id"`
	Currency        string          `json:"currency"`
	Instrument      string          `json:"instrument"`
	OrderSide       string          `json:"orderSide"`
	OrderType       string          `json:"ordertype"`
	CreationTime    float64         `json:"creationTime"`
	Status          string          `json:"status"`
	ErrorMessage    string          `json:"errorMessage"`
	Price           float64         `json:"price"`
	Volume          float64         `json:"volume"`
	OpenVolume      float64         `json:"openVolume"`
	ClientRequestID string          `json:"clientRequestId"`
	Trades          []TradeResponse `json:"trades"`
}

Order holds order information

type OrderToGo

type OrderToGo struct {
	Currency        string `json:"currency"`
	Instrument      string `json:"instrument"`
	Price           int64  `json:"price"`
	Volume          int64  `json:"volume"`
	OrderSide       string `json:"orderSide"`
	OrderType       string `json:"ordertype"`
	ClientRequestID string `json:"clientRequestId"`
}

OrderToGo holds order information to be sent to the exchange

type Orderbook

type Orderbook struct {
	Currency   string      `json:"currency"`
	Instrument string      `json:"instrument"`
	Timestamp  int64       `json:"timestamp"`
	Asks       [][]float64 `json:"asks"`
	Bids       [][]float64 `json:"bids"`
}

Orderbook holds current orderbook information returned from the exchange

type Response

type Response struct {
	Success         bool              `json:"success"`
	ErrorCode       int               `json:"errorCode"`
	ErrorMessage    string            `json:"errorMessage"`
	ID              int               `json:"id"`
	Responses       []ResponseDetails `json:"responses"`
	ClientRequestID string            `json:"clientRequestId"`
	Orders          []Order           `json:"orders"`
	Status          string            `json:"status"`
}

Response is the genralized response type

type ResponseDetails

type ResponseDetails struct {
	Success      bool   `json:"success"`
	ErrorCode    int    `json:"errorCode"`
	ErrorMessage string `json:"errorMessage"`
	ID           int64  `json:"id"`
}

ResponseDetails holds order status details

type Ticker

type Ticker struct {
	BestBID    float64 `json:"bestBid"`
	BestAsk    float64 `json:"bestAsk"`
	LastPrice  float64 `json:"lastPrice"`
	Currency   string  `json:"currency"`
	Instrument string  `json:"instrument"`
	Timestamp  int64   `json:"timestamp"`
	Volume     float64 `json:"volume24h"`
}

Ticker holds ticker information

type Trade

type Trade struct {
	TradeID int64   `json:"tid"`
	Amount  float64 `json:"amount"`
	Price   float64 `json:"price"`
	Date    int64   `json:"date"`
}

Trade holds trade information

type TradeResponse

type TradeResponse struct {
	ID           int64   `json:"id"`
	CreationTime float64 `json:"creationTime"`
	Description  string  `json:"description"`
	Price        float64 `json:"price"`
	Volume       float64 `json:"volume"`
	Fee          float64 `json:"fee"`
}

TradeResponse holds trade information

type TradingFee

type TradingFee struct {
	Success        bool    `json:"success"`
	ErrorCode      int     `json:"errorCode"`
	ErrorMessage   string  `json:"errorMessage"`
	TradingFeeRate float64 `json:"tradingfeerate"`
	Volume30Day    float64 `json:"volume30day"`
}

TradingFee 30 day trade volume

type WithdrawRequestAUD

type WithdrawRequestAUD struct {
	Amount        int64  `json:"amount"`
	Currency      string `json:"currency"`
	AccountName   string `json:"accountName"`
	AccountNumber string `json:"accountNumber"`
	BankName      string `json:"bankName"`
	BSBNumber     string `json:"bsbNumber"`
}

WithdrawRequestAUD is a generalized withdraw request type

type WithdrawRequestCrypto

type WithdrawRequestCrypto struct {
	Amount   int64  `json:"amount"`
	Currency string `json:"currency"`
	Address  string `json:"address"`
}

WithdrawRequestCrypto is a generalized withdraw request type

Jump to

Keyboard shortcuts

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