conn

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2020 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package client implements a client to connect with CryptoMarket using the endpoints given at https://developers.cryptomkt.com/.

Index

Constants

This section is empty.

Variables

View Source
var (
	// DELAY is the amount to wait in seconds between requests to the server,
	// too many requests and the ip is blocked.
	DELAY float64 = 2.5
)

Functions

This section is empty.

Types

type Account

type Account struct {
	Name         string
	Email        string
	Rate         Rate
	BankAccounts []BankAccount `json:"bank_accounts"`
}

type AccountResponse

type AccountResponse struct {
	Status  string
	Message string
	Data    Account
}

type Amount

type Amount struct {
	Original  string
	Remaining string
	Executed  string
}

func (*Amount) String

func (amount *Amount) String() string

type Balance

type Balance struct {
	Wallet    string
	Available string
	Balance   string
}

func (*Balance) ToMap

func (balance *Balance) ToMap() map[string]string

ToMap converts a balance object to a map

type BalancesResponse

type BalancesResponse struct {
	Status  string
	Message string
	Data    []Balance
}

type BankAccount

type BankAccount struct {
	Id          int
	Bank        string
	Description string
	Country     string
	Number      string
}

type Book

type Book struct {
	Data []BookData
	// contains filtered or unexported fields
}

func (*Book) GetLimit

func (b *Book) GetLimit() int

GetLimit returns the number of trades per page

func (*Book) GetNext

func (b *Book) GetNext() (*Book, error)

GetNext lets you go to the next page if it exists, returns (*Book, nil) if it is successfull and (nil, error) otherwise

func (*Book) GetPage

func (b *Book) GetPage() int

GetPage returns the actual page of the request.

func (*Book) GetPrevious

func (b *Book) GetPrevious() (*Book, error)

GetPrevious lets you go to the previous page if it exists, returns (*Book, nil) if it is successfull and (nil, error) otherwise

func (*Book) String

func (book *Book) String() string

type BookData

type BookData struct {
	Price     string
	Amount    string
	Timestamp string
}

func (*BookData) String

func (bookData *BookData) String() string

type BookResponse

type BookResponse struct {
	Status     string
	Message    string
	Pagination Pagination
	Data       []BookData
}

type Candle

type Candle struct {
	CandleId   int    `json:"candle_id"`
	OpenPrice  string `json:"open_price"`
	HightPrice string `json:"hight_price"`
	ClosePrice string `json:"close_price"`
	LowPrice   string `json:"low_price"`
	VolumeSum  string `json:"volume_sum"`
	CandleDate string `json:"candle_date"`
	TickCount  string `json:"tick_count"`
}

type Client

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

Client keep the needed data to connect with the asociated CryptoMarket account.

func NewClient

func NewClient(apiKey, apiSecret string) *Client

New builds a new client and returns a pointer to it.

func (*Client) CancelOrder

func (client *Client) CancelOrder(arguments ...args.Argument) (*Order, error)

CancelOrder cancel an order in CryptoMarket, given its id Returns an Order struct that supports Close() and Refresh() to cancel or update the order respectively.

List of accepted Arguments:

  • required: Id (string)
  • optional: none

https://developers.cryptomkt.com/#cancelar-una-orden

func (*Client) CreateInstant

func (client *Client) CreateInstant(arguments ...args.Argument) error

CreateInstant makes an order in the Instant Exchange of CryptoMarket Returns an error if something goes wrong

List of accepted Arguments:

  • required: Market (string), Type (string), Amount (string)
  • optional: none

https://developers.cryptomkt.com/#crear-orden-2

func (*Client) CreateOrder

func (client *Client) CreateOrder(arguments ...args.Argument) (*Order, error)

CreateOrder creates an order to buy or sell in a market of CryptoMarket Returns an Order struct that supports Close() and Refresh() to cancel or update the order respectively.

List of accepted Arguments:

  • required: Amount (string), Market (string), Price (string), Type (string)
  • optional: none

https://developers.cryptomkt.com/#crear-orden

func (*Client) GetAccount

func (client *Client) GetAccount() (*Account, error)

GetAccount gives the information of the cryptoMarket account. Returns the data in an Account struct

https://developers.cryptomkt.com/#cuenta

func (*Client) GetActiveOrders

func (client *Client) GetActiveOrders(arguments ...args.Argument) (*OrderList, error)

GetActiveOrders returns the list of active orders of the client in a given market. Retunrs an OrderList struct, where all the orders are in the Data field, in a slice of Order. OrderLists supports Next() and Previous() to get the corresponding pages. OrderLists also supports Close() and Refresh(), to close or refresh all the orders of the list.

List of accepted Arguments:

  • required: Market (string)
  • optional: Page (int), Limit (int)

https://developers.cryptomkt.com/#ordenes-activas

func (*Client) GetActiveOrdersAllPages

func (client *Client) GetActiveOrdersAllPages(arguments ...args.Argument) ([]Order, error)

GetActiveOrdersAllPages gets all the actives orders of the client in a given market. returns an array of orders.

List of accepted Arguments:

  • required: Market (string)
  • optional: none

https://developers.cryptomkt.com/es/#ordenes-activas

func (*Client) GetAllTransactions

func (client *Client) GetAllTransactions(argus ...args.Argument) ([]Transaction, error)

GetAllTransactions returns an array of transactions made in cryptomkt.

List of arguments:

required: currency (string)

func (*Client) GetBalance

func (client *Client) GetBalance() ([]Balance, error)

GetBalance returns the actual balance of the wallets of the client in CryptoMarket Returns the a slice of Balance structs

https://developers.cryptomkt.com/#obtener-balance

func (*Client) GetBook

func (client *Client) GetBook(arguments ...args.Argument) (*Book, error)

GetBook returns a pointer to a Book struct with the data given by the api and an error message. It returns (nil, error) when an error is raised and (*Book, nil) when the operation is successful. The data fields are: Price, Amount and Timestamp. To access these fields, you can call them by *Book.Data[indexYouWant].FieldYouWant

List of accepted Arguments:

  • required: Market (string), Type (string)
  • optional: Page (int), Limit (int)

https://developers.cryptomkt.com/#ordenes

func (*Client) GetExecutedOrders

func (client *Client) GetExecutedOrders(arguments ...args.Argument) (*OrderList, error)

GetExecutedOrders return a list of the executed orders of the client in a given market. Retunrs an OrderList struct, where all the orders are in the Data field, in a slice of Order. OrderLists supports Next() and Previous() to get the corresponding pages. OrderLists also supports Close() and Refresh(), to close or refresh all the orders of the list.

List of accepted Arguments:

  • required: Market (string)
  • optional: Page (int), Limit (int)

https://developers.cryptomkt.com/#ordenes-ejecutadas

func (*Client) GetExecutedOrdersAllPages

func (client *Client) GetExecutedOrdersAllPages(arguments ...args.Argument) ([]Order, error)

GetExecutedOrdersAllPages gets all executed orders of the client in a given market

List of accepted Arguments:

  • required: Market (string)
  • optional: none

https://developers.cryptomkt.com/es/#ordenes-ejecutadas

func (*Client) GetInstant

func (client *Client) GetInstant(arguments ...args.Argument) (*Instant, error)

GetInstant emulates an order in the current state of the Instant Exchange of CryptoMarket Returns an Instant struct holding the data.

List of accepted Arguments:

  • required: Market (string), Type (string), Amount (string)
  • optional: none

https://developers.cryptomkt.com/#obtener-cantidad

func (*Client) GetMarkets

func (client *Client) GetMarkets() ([]string, error)

GetMarkets returns the available markets in cryptomarket as a string slice

https://developers.cryptomkt.com/mercado

func (*Client) GetOrderStatus

func (client *Client) GetOrderStatus(arguments ...args.Argument) (*Order, error)

GetOrderStatus gives the status of an order given its id. Returns an Order struct that supports Close() and Refresh() to cancel or update the order respectively.

List of accepted Arguments:

  • required: Id (string)
  • optional: none

https://developers.cryptomkt.com/#estado-de-orden

func (*Client) GetPrices

func (client *Client) GetPrices(arguments ...args.Argument) (*Prices, error)

GetPrices return a pointer to a Prices struct with the data given by the api and an error message. It returns (nil,error) when an error is raised and (*Prices, nil) when the operation is successful. The data fields are classified in two categories, Ask and Bid. The fields are CandleId, OpenPrice, HightPrice, ClosePrice, LowPrice, VolumeSum CandleDate and TickCount. To access the data you can call this way: *Prices.Data.Ask[indexYouWant].FieldYouWant or *Prices.Data.Bid[indexYouWant].FieldYouWant

List of accepted Arguments:

  • required: Market (string), Timeframe (string)
  • optional: Page (int), Limit (int)

https://developers.cryptomkt.com/#precios

func (*Client) GetTicker

func (client *Client) GetTicker(arguments ...args.Argument) ([]Ticker, error)

GetTicker returns a list of Tickers. It returns (nil,error) when an error is raised and ([]Tiker, nil) when the operation is successful. The data fields are: High, Low, Ask, Bid, LastPrice, Volume, Market and Timestamp.

List of accepted Arguments:

  • required: none
  • optional: Market (string)

https://developers.cryptomkt.com/#ticker

func (*Client) GetTrades

func (client *Client) GetTrades(arguments ...args.Argument) (*Trades, error)

GetTrades returns a pointer to a Trades struct with the data given by the api and an error message. It returns (nil, error) when an error is raised and (*Trades, nil) when the operation is successful. The data fields are MarketTaker, Price, Amount, Tid, Timestamp and Market. You can access them by *Trades.Data[indexYouWant].FieldYouWant

List of accepted Arguments:

  • required: Market (string)
  • optional: Start (string YYYY-MM-DD), End (YYYY-MM-DD), Page (int), Limit (int)

https://developers.cryptomkt.com/#trades

func (*Client) GetTradesAllPages

func (client *Client) GetTradesAllPages(arguments ...args.Argument) ([]TradeData, error)

GetTradesAllPages returns a pointer to a Trades struct with the data given by the api and an error message. It returns (nil, error) when an error is raised and (*Trades, nil) when the operation is successful. If end argument is not provided, the maximum data amount will be trucated when it raises more than 100 elements. It is not sure it will give you exactly 100 TradeData Data.

List of accepted Arguments:

  • required: Market (string)
  • optional: Start (string YYYY-MM-DD), End (string YYYY-MM-DD)

https://developers.cryptomkt.com/es/#trades

func (*Client) GetTransactions

func (client *Client) GetTransactions(arguments ...args.Argument) (*TransactionList, error)

GetTransactions returns the movements of the wallets of the client for a given currency. Returns a TransactionList struct, where all the transactions are in the Data field in a slice of Transaction. TransactionList supports Next() and Previous to get the corresponding pages.

List of accepted Arguments:

  • required: Currency (string)
  • optional: Page (int), Limit (int)

https://developers.cryptomkt.com/#obtener-movimientos

func (*Client) GetWallets

func (client *Client) GetWallets() ([]Balance, error)

GetWallets is an alias for Balance, returns the actual balance of wallets of the client in CryptoMarket

https://developers.cryptomkt.com/#obtener-balance

func (*Client) RequestDeposit

func (client *Client) RequestDeposit(arguments ...args.Argument) error

RequestDeposit makes a deposit to a wallet of local currency Returns an error if something goes wrong

List of accepted Arguments:

  • required: Amount (string), BankAccount (string)
  • required only for México, Brasil and European Union: Voucher (file)
  • required only for México: Date (string dd/mm/yyyy), TrackingCode (string)

https://developers.cryptomkt.com/#notificar-deposito

func (*Client) RequestWithdrawal

func (client *Client) RequestWithdrawal(arguments ...args.Argument) error

RequestWithdrawal makes a withdrawal from a bank account of the client Returns an error if something goes wrong

List of accepted Arguments:

  • required: Amount (string), BankAccount (string)
  • optional: none

https://developers.cryptomkt.com/#notificar-retiro

func (*Client) String

func (client *Client) String() string

func (*Client) Transfer

func (client *Client) Transfer(arguments ...args.Argument) error

Transfer moves crypto between wallets Returns an error if something goes wrong

List of accepted Arguments:

  • required: Address (string), Amount (string) , Currency (string)
  • optional: Memo (string)

https://developers.cryptomkt.com/#transferir

type DataPrices

type DataPrices struct {
	Ask []Candle
	Bid []Candle
}

type HMACAuth

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

A HMACAuth keeps the keys of a client making them usable along all request of the client to crpytomkt

type Instant

type Instant struct {
	Obtained float64
	Required float64
}

func (*Instant) String

func (instant *Instant) String() string

func (*Instant) ToMap

func (instant *Instant) ToMap() map[string]string

type InstantResponse

type InstantResponse struct {
	Status  string
	Message string
	Data    Instant
}

type MarketListResponse

type MarketListResponse struct {
	Status  string
	Message string
	Data    []string
}

type Order

type Order struct {
	Id                string
	Status            string
	Type              string
	Price             string
	Amount            Amount
	ExecutionPrice    string `json:"execution_price"`
	AvgExecutionPrice int    `json:"avg_execution_price"`
	Market            string
	CreatedAt         string `json:"created_at"`
	UpdatedAt         string `json:"updated_at"`
	ExecutedAt        string `json:"executed_at"`
	// contains filtered or unexported fields
}

func (*Order) Close

func (o *Order) Close() (*Order, error)

Close closes the calling order, and changes the order to reflect the new state of the order, after being closed. Calls CancelOrder with the asociated client of the order. https://developers.cryptomkt.com/es/#cancelar-una-orden

func (*Order) Refresh

func (o *Order) Refresh() (*Order, error)

Refresh refreshes the calling order, and changes it to be the actual state of the order. Calls GetOrderStatus with the asociated client of the order. https://developers.cryptomkt.com/es/#estado-de-orden

func (*Order) String

func (order *Order) String() string

func (*Order) ToMap

func (order *Order) ToMap() map[string]string

ToMap converts an order object to a map

type OrderList

type OrderList struct {
	Status string

	Warnings string
	Data     []Order
	// contains filtered or unexported fields
}

func (*OrderList) Close

func (oList *OrderList) Close() error

Close closes every order in the order list.

func (*OrderList) GetNext

func (o *OrderList) GetNext() (*OrderList, error)

GetNext lets you go to the next page if it exists, returns (*Prices, nil) if it is successfull and (nil, error) otherwise

func (*OrderList) GetPrevious

func (o *OrderList) GetPrevious() (*OrderList, error)

GetPrevious get the previous page of the List of orders. If there is no previous page, rise an error.

func (*OrderList) Refresh

func (oList *OrderList) Refresh() error

Refresh refreshes every order in the order list. its an iterative implementation, so if an error is rised refreshing some order, the preciding orders end refreshed.

func (*OrderList) String

func (oList *OrderList) String() string

type OrderListResp

type OrderListResp struct {
	Status     string
	Message    string
	Pagination Pagination
	Warnings   string
	Data       []Order
}

type OrderResponse

type OrderResponse struct {
	Status  string
	Message string
	Data    Order
}

type Pagination

type Pagination struct {
	Previous interface{}
	Next     interface{}
	Limit    int
	Page     int
}

Data structs for this sdk

func (*Pagination) String

func (pagination *Pagination) String() string

type Prices

type Prices struct {
	Data DataPrices
	// contains filtered or unexported fields
}

func (*Prices) GetLimit

func (p *Prices) GetLimit() int

GetLimit returns the limit you have provided, but if you have not, it provides the default

func (*Prices) GetNext

func (p *Prices) GetNext() (*Prices, error)

GetNext lets you go to the next page if it exists, returns (*Prices, nil) if it is successfull and (nil, error) otherwise

func (*Prices) GetPage

func (p *Prices) GetPage() int

GetPage returns the page you have

func (*Prices) GetPrevious

func (p *Prices) GetPrevious() (*Prices, error)

GetPrevious lets you go to the previous page if it exists, returns (*Prices, nil) if it is successfull and (nil, error) otherwise

type PricesResponse

type PricesResponse struct {
	Status     string
	Message    string
	Pagination Pagination
	Data       DataPrices
}

type Rate

type Rate struct {
	MarketMaker string `json:"market_maker"`
	MarketTaker string `json:"market_taker"`
}

type Ticker

type Ticker struct {
	High      string
	Volume    string
	Low       string
	Ask       string
	Timestamp string
	Bid       string
	LastPrice string `json:"last_price"`
	Market    string
}

func (*Ticker) ToMap

func (ticker *Ticker) ToMap() map[string]string

ToMap converts a ticket object to a map

type TickerResponse

type TickerResponse struct {
	Status  string
	Message string
	Data    []Ticker
}

type TradeData

type TradeData struct {
	MarketTaker string `json:"market_taker"`
	Price       string
	Amount      string
	Tid         string
	Timestamp   string
	Market      string
}

func (*TradeData) ToMap

func (trade *TradeData) ToMap() map[string]string

ToMap converts a *TradeData object to a map

type Trades

type Trades struct {
	Data []TradeData
	// contains filtered or unexported fields
}

func (*Trades) GetLimit

func (t *Trades) GetLimit() int

GetLimit returns the number of trades per page.

func (*Trades) GetNext

func (t *Trades) GetNext() (*Trades, error)

GetNext lets you go to the next page if it exists, returns (*Trades, nil) if it is successfull and (nil, error) otherwise

func (*Trades) GetPage

func (t *Trades) GetPage() int

GetPage returns the actual page of the request.

func (*Trades) GetPrevious

func (t *Trades) GetPrevious() (*Trades, error)

GetPrevious lets you go to the previous page if it exists, returns (*Trades, nil) if it is successfull and (nil, error) otherwise

type TradesResponse

type TradesResponse struct {
	Status     string
	Message    string
	Pagination Pagination
	Data       []TradeData
}

type Transaction

type Transaction struct {
	Id         string
	Type       int
	Amount     string
	FeePercent string `json:"fee_percent"`
	FeeAmount  string `json:"fee_amount"`
	Balance    string
	Date       string
	Hash       string
	Address    string
	Memo       string
}

func (*Transaction) ToMap

func (transaction *Transaction) ToMap() map[string]string

type TransactionList

type TransactionList struct {
	Data []Transaction
	// contains filtered or unexported fields
}

func (*TransactionList) GetLimit

func (tList *TransactionList) GetLimit() int

GetLimit returns the limit number of elements per page

func (*TransactionList) GetNext

func (tList *TransactionList) GetNext() (*TransactionList, error)

GetNext lets you go to the next page if it exists, returns (*Prices, nil) if it is successfull and (nil, error) otherwise

func (*TransactionList) GetPage

func (tList *TransactionList) GetPage() int

GetPage returns the actual page.

func (*TransactionList) GetPrevious

func (tList *TransactionList) GetPrevious() (*TransactionList, error)

GetPrevious get the previous page of the Transaction list If there is no previous page, rise an error.

type TransactionsResponse

type TransactionsResponse struct {
	Status     string
	Message    string
	Pagination Pagination
	Data       []Transaction
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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