tulip

package module
v0.0.0-...-f5dbcdc Latest Latest
Warning

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

Go to latest
Published: May 9, 2019 License: MIT Imports: 13 Imported by: 0

README

🌷 Tulip 🌷

An open source API client for Buda written in Go.

You can check the current Buda API documentation at http://api.buda.com

NOTE: You need a developer account in order to make full use of this client. You can make unauthenticated calls (http://api.buda.com/#llamadas-p-blicas)

Available Methods ✅
  • Public 🔓
    • Get markets info GetMarkets()
    • Get ticker info GetTicker()
    • Get all available orders for a market GetOrderBook()
    • Get info about recent trades GetTrades()
  • Private (Requires APIkey) 🔑
    • Get your current balance GetBalances()
    • Get your orders GetOrders()
    • Crate a new order (bid or ask) PostOrder()
    • Cancel a current order CancelOrder()
    • Get info about a specific order GetOrder()
    • Get historic info about deposits GetDepositHistory()
    • Get historic info about withdrawals GetWithdrawHistory()
TODO 👨🏻‍💻
  • Do Deposits and Withdrawals
  • Do string interpolation for queries instead of appending strings together
  • ?? Make a suggestion

Get it working 🦄

In your terminal:

$ go get github.com/igomez10/tulip

In your .go file:

package main

import (
	"fmt"
	"os"

	"github.com/igomez10/tulip"
)

func main() {

	APIKey := os.Getenv("BUDAKEY")       // you can modify this variable and hardocde your own apikey
	APISecret := os.Getenv("BUDASECRET") // you can modify this variable and hardcode your own apisecret

	buda := tulip.CreateClient(APIKey, APISecret)
	results, err := buda.GetTicker("btc-clp")
	if err != nil {
		fmt.Println(err)
	} else {
		fmt.Println(results.Market.ID)                 // "BTC-CLP"
		fmt.Println(results.Market.Name)               // "btc-clp"
		fmt.Println(results.Market.BaseCurrency)       // "BTC"
		fmt.Println(results.Market.QuoteCurrency)      // "CLP"
		fmt.Println(results.Market.MinimumOrderAmount) // ["0.0001 BTC"]
	}

Documentation 📄

Public Calls

Get Ticker

GetTicker Returns info about a specific market

buda.GetTicker(<marketID>)
marketID can be "btc-clp", "btc-cop" etc
{
   "market":{
      "id":"BTC-CLP",
      "name":"btc-clp",
      "base_currency":"BTC",
      "quote_currency":"CLP",
      "minimum_order_amount":[
         "0.0001",
         "BTC"
      ]
   }
}
Get Markets

GetMarkets Returns info about all markets

buda.GetMarkets()
{
   "markets":[
      {
         "id":"BTC-CLP",
         "name":"btc-clp",
         "base_currency":"BTC",
         "quote_currency":"CLP",
         "minimum_order_amount":[
            "0.0001",
            "BTC"
         ]
      },
      {
         "id":"BCH-PEN",
         "name":"bch-pen",
         "base_currency":"BCH",
         "quote_currency":"PEN",
         "minimum_order_amount":[
            "0.0001",
            "BCH"
         ]
      }
   ]
}
Get Order Book

GetOrderBook is used to get current state of the market. It shows the best offers (bid, ask) and the price from the last transaction, daily volume and the price in the last 24 hours

buda.GetOrderBook("btc-clp")
{
 "order_book":{
    "asks":[
       [
          "7299998.0",
          "0.0374176"
         ],
       [
          "7299999.0",
          "0.07844341"
        ]
      ],
    "bids":[
       [
          "7217231.0",
          "0.02699449"
       ],
       [
          "7183000.0",
          "0.28"
       ],
       [
          "7181619.0",
          "0.0688"
       ]
    ]
 }
}

Get Trades

GetTrades returns a list of recent trades in a specific market

buda.GetTrades("btc-clp")
{  
  "trades":{  
       "market_id":"BTC-CLP",
       "timestamp":null,
       "last_timestamp":"1517177157715",
       "entries":[
       [  
          "1517188555937",
          "0.00300551",
          "7217231.0",
          "sell",
          316863
        ],
        [  
          "1517186567638",
          "0.00206959",
          "7300000.0",
          "buy",
          316844
        ]
      ]
    }
}

Private Calls

NEEDS AN APIKEY/APISECRET
Get Balances/Balances
  • GetBalances gets the wallet balances in all cryptocurrencies and fiat currencies
  • GetBalance(currency) gets the wallet balance in a specific cryptocurrency or fiat currency
buda.GetBalances()
{
   "balances":[
      {
         "id":"BTC",
         "amount":[
            "0.0000001",
            "BTC"
         ],
         "available_amount":[
            "0.0000001",
            "BTC"
         ],
         "frozen_amount":[
            "0.0",
            "BTC"
         ],
         "pending_withdraw_amount":[
            "0.0",
            "BTC"
         ],
         "account_id":1234567
      },
      {
         "id":"COP",
         "amount":[
            "1000.33",
            "COP"
         ],
         "available_amount":[
            "1000.33",
            "COP"
         ],
         "frozen_amount":[
            "0.0",
            "COP"
         ],
         "pending_withdraw_amount":[
            "0.0",
            "COP"
         ],
         "account_id":1234567
      }
   ]
}
Get info about all YOUR Orders
Warning: GetOrderBook(A) != GetOrders(A,B,C,D,E)
  • GetOrders gets your orders made in a specific market with a specific status or/and minimum amount
buda.GetOrders(marketID, ordersPerPage, page, state, minimumExchanged)
Example:
buda.GetOrders("btc-cop", 300, 1, "pending", float64(0))
{  
   "orders":[  
      {  
         "id":123456,
         "market_id":"BTC-COP",
         "account_id":1234567,
         "type":"Bid",
         "state":"pending",
         "created_at":"2018-01-29T02:28:44.658Z",
         "fee_currency":"BTC",
         "price_type":"limit",
         "limit":[  
            "0.0",
            "COP"
         ],
         "amount":[  
            "0.0001",
            "BTC"
         ],
         "original_amount":[  
            "0.0001",
            "BTC"
         ],
         "traded_amount":[  
            "0.0",
            "BTC"
         ],
         "total_exchanged":[  
            "0.0",
            "COP"
         ],
         "paid_fee":[  
            "0.0",
            "BTC"
         ]
      }
   ],
   "meta":{  
      "total_pages":1,
      "total_count":1,
      "current_page":1
   }
}
Create a new order
Warning: Be sure to understand this method: http://api.buda.com/#nueva-orden
PostOrder creates a new order (bid or ask) in a specific market

IMPORTANT: You can either crete a Limit of Market order specifying it on the priceType parameter as "limit" or "market". Therefore, the parameter limit is only read in the first case but it is necessary to make the call. In order to post a Market order, submit the limit as float(0) or float().

buda.PostOrder(marketID string, orderType string, priceType string, limit float64, amount float64)
At the moment, only "limit" is available for priceType
Example:
buda.PostOrder("btc-cop", "bid", "limit", float64(0.00001), float64(0.0001)))
{
   "order":{
      "id":1234567,
      "market_id":"BTC-COP",
      "account_id":1234567,
      "type":"Bid",
      "state":"received",
      "created_at":"2018-01-29T02:28:44.658Z",
      "fee_currency":"BTC",
      "price_type":"limit",
      "limit":[
         "0.0",
         "COP"
      ],
      "amount":[
         "0.0001",
         "BTC"
      ],
      "original_amount":[
         "0.0001",
         "BTC"
      ],
      "traded_amount":[
         "0.0",
         "BTC"
      ],
      "total_exchanged":[
         "0.0",
         "COP"
      ],
      "paid_fee":[
         "0.0",
         "BTC"
      ]
   }
}
Cancel an order
CancelOrder cancels a specified order
buda.CancelOrder(orderID string)
CancelOrder cancels a specified order
{  
   "order":{  
      "id":1234567,
      "market_id":"BTC-COP",
      "account_id":1234567,
      "type":"Bid",
      "state":"canceled",
      "created_at":"2018-01-29T02:28:44.658Z",
      "fee_currency":"BTC",
      "price_type":"limit",
      "limit":[  
         "0.0",
         "COP"
      ],
      "amount":[  
         "0.0001",
         "BTC"
      ],
      "original_amount":[  
         "0.0001",
         "BTC"
      ],
      "traded_amount":[  
         "0.0",
         "BTC"
      ],
      "total_exchanged":[  
         "0.0",
         "COP"
      ],
      "paid_fee":[  
         "0.0",
         "BTC"
      ]
   }
}
Get info about a specific order

####GetOrder returns the current state of a specific order

buda.GetOrder(orderID string)
{  
   "order":{  
      "id":1234567,
      "market_id":"BTC-COP",
      "account_id":1234567,
      "type":"Bid",
      "state":"received",
      "created_at":"2018-01-29T02:38:37.178Z",
      "fee_currency":"BTC",
      "price_type":"limit",
      "limit":[  
         "0.0",
         "COP"
      ],
      "amount":[  
         "0.0001",
         "BTC"
      ],
      "original_amount":[  
         "0.0001",
         "BTC"
      ],
      "traded_amount":[  
         "0.0",
         "BTC"
      ],
      "total_exchanged":[  
         "0.0",
         "COP"
      ],
      "paid_fee":[  
         "0.0",
         "BTC"
      ]
   }
}
Get historic deposits in a specific fiat currency
buda.GetDepositHistory(currency string)
{  
   "deposits":[  
      {  
         "id":1234567,
         "state":"confirmed",
         "currency":"COP",
         "created_at":"2018-01-26T03:01:34.791Z",
         "deposit_data":{  
            "type":"fiat_deposit_data",
            "created_at":"2018-01-26T03:01:34.783Z",
            "updated_at":"2018-01-26T03:01:34.783Z",
            "upload_url":null
         },
         "amount":[  
            "10000.0",
            "COP"
         ],
         "fee":[  
            "431.0",
            "COP"
         ]
      },
      {  
         "id":1234567,
         "state":"confirmed",
         "currency":"COP",
         "created_at":"2018-01-22T17:06:14.473Z",
         "deposit_data":{  
            "type":"fiat_deposit_data",
            "created_at":"2018-01-22T17:06:14.465Z",
            "updated_at":"2018-01-22T17:06:14.465Z",
            "upload_url":null
         },
         "amount":[  
            "1000.0",
            "COP"
         ],
         "fee":[  
            "431.0",
            "COP"
         ]
      }
   ],
   "meta":{  
      "total_pages":1,
      "total_count":2,
      "current_page":1
   }
}
Get historic withdrawals in a specific fiat currency
buda.GetWithdrawHistory(currency string)
{  
   "withdrawals":[  
      {  
         "id":1234567,
         "state":"pending_op_execution",
         "currency":"COP",
         "created_at":"2018-01-29T02:55:04.056Z",
         "withdrawal_data":{  
            "type":"fiat/withdrawal_data",
            "id":1234567,
            "created_at":"2018-01-29T02:55:04.048Z",
            "updated_at":"2018-01-29T02:55:04.048Z",
            "transacted_at":null,
            "statement_ref":null,
            "fiat_account":{  
               "id":1234567,
               "account_number":"000000000",
               "account_type":"Account description",
               "bank_id":99,
               "created_at":"2018-01-22T16:57:32.949Z",
               "currency":"COP",
               "document_number":"000000000",
               "email":"email@email.com",
               "full_name":"Your name",
               "national_number_identifier":null,
               "phone":"+000000000000",
               "updated_at":"2018-01-22T16:57:32.949Z",
               "bank_name":"BankName",
               "pe_cci_number":null
            },
            "source_account":null
         },
         "amount":[  
            "9000.0",
            "COP"
         ],
         "fee":[  
            "0.0",
            "COP"
         ]
      }
   ],
   "meta":{  
      "total_pages":1,
      "total_count":1,
      "current_page":1
   }
}
CONTRIBUTION ⚠️

FEEL FREE TO OPEN AN ISSUE / PULL REQUEST IF YOU FIND BUGS OR IF YOU WANT TO INCLUDE NEW FEATURES. If your pull request doesn't break any old code I will happily merge it.

This client works with v2 of the Buda API.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateClient

func CreateClient(apikey string, apisecret string) *client

CreateClient returns a new client

func Describe

func Describe(i interface{}) interface{}

Types

type Balance

type Balance struct {
	ID                    string   `json:"id"`
	Amount                []string `json:"amount"`
	AvailableAmount       []string `json:"available_amount"`
	FrozenAmount          []string `json:"frozen_amount"`
	PendingWithdrawAmount []string `json:"pending_withdraw_amount"`
	AccountID             int      `json:"account_id"`
}

type BalanceResponse

type BalanceResponse struct {
	Balance Balance
}

type BalancesResponse

type BalancesResponse struct {
	Balances []Balance
}

type HistoricDespositsResponse

type HistoricDespositsResponse struct {
	Deposits []struct {
		ID          int       `json:"id"`
		State       string    `json:"state"`
		Currency    string    `json:"currency"`
		CreatedAt   time.Time `json:"created_at"`
		DepositData struct {
			Type      string      `json:"type"`
			CreatedAt time.Time   `json:"created_at"`
			UpdatedAt time.Time   `json:"updated_at"`
			UploadURL interface{} `json:"upload_url"`
		} `json:"deposit_data"`
		Amount []string `json:"amount"`
		Fee    []string `json:"fee"`
	} `json:"deposits"`
	Meta struct {
		TotalPages  int `json:"total_pages"`
		TotalCount  int `json:"total_count"`
		CurrentPage int `json:"current_page"`
	} `json:"meta"`
}

type HistoricWithdrawResponse

type HistoricWithdrawResponse struct {
	Withdrawals []struct {
		ID             int       `json:"id"`
		State          string    `json:"state"`
		Currency       string    `json:"currency"`
		CreatedAt      time.Time `json:"created_at"`
		WithdrawalData struct {
			Type         string      `json:"type"`
			ID           int         `json:"id"`
			CreatedAt    time.Time   `json:"created_at"`
			UpdatedAt    time.Time   `json:"updated_at"`
			TransactedAt interface{} `json:"transacted_at"`
			StatementRef interface{} `json:"statement_ref"`
			FiatAccount  struct {
				ID                       int         `json:"id"`
				AccountNumber            string      `json:"account_number"`
				AccountType              string      `json:"account_type"`
				BankID                   int         `json:"bank_id"`
				CreatedAt                time.Time   `json:"created_at"`
				Currency                 string      `json:"currency"`
				DocumentNumber           string      `json:"document_number"`
				Email                    string      `json:"email"`
				FullName                 string      `json:"full_name"`
				NationalNumberIdentifier interface{} `json:"national_number_identifier"`
				Phone                    string      `json:"phone"`
				UpdatedAt                time.Time   `json:"updated_at"`
				BankName                 string      `json:"bank_name"`
				PeCciNumber              interface{} `json:"pe_cci_number"`
			} `json:"fiat_account"`
			SourceAccount interface{} `json:"source_account"`
		} `json:"withdrawal_data"`
		Amount []string `json:"amount"`
		Fee    []string `json:"fee"`
	} `json:"withdrawals"`
	Meta struct {
		TotalPages  int `json:"total_pages"`
		TotalCount  int `json:"total_count"`
		CurrentPage int `json:"current_page"`
	} `json:"meta"`
}

type LimitOrder

type LimitOrder struct {
	OrderType string  `json:"type"`
	PriceType string  `json:"price_type"`
	Limit     float64 `json:"limit"`
	Amount    float64 `json:"amount"`
}

type Market

type Market struct {
	ID                 string   `json:"id"`
	Name               string   `json:"name"`
	BaseCurrency       string   `json:"base_currency"`
	QuoteCurrency      string   `json:"quote_currency"`
	MinimumOrderAmount []string `json:"minimum_order_amount"`
}

type MarketOrder

type MarketOrder struct {
	OrderType string  `json:"type"`
	PriceType string  `json:"price_type"`
	Amount    float64 `json:"amount"`
}

type MarketResponse

type MarketResponse struct {
	Market Market
}

type MarketsResponse

type MarketsResponse struct {
	Markets []Market
}

type MyOrdersResponse

type MyOrdersResponse struct {
	Orders []Order
	Meta   struct {
		TotalPages  int `json:"total_pages"`
		TotalCount  int `json:"total_count"`
		CurrentPage int `json:"current_page"`
	} `json:"meta"`
}

type Order

type Order struct {
	ID             int       `json:"id"`
	MarketID       string    `json:"market_id"`
	AccountID      int       `json:"account_id"`
	Type           string    `json:"type"`
	State          string    `json:"state"`
	CreatedAt      time.Time `json:"created_at"`
	FeeCurrency    string    `json:"fee_currency"`
	PriceType      string    `json:"price_type"`
	Limit          []string  `json:"limit"`
	Amount         []string  `json:"amount"`
	OriginalAmount []string  `json:"original_amount"`
	TradedAmount   []string  `json:"traded_amount"`
	TotalExchanged []string  `json:"total_exchanged"`
	PaidFee        []string  `json:"paid_fee"`
}

type OrderBook

type OrderBook struct {
	OrderBook struct {
		Asks [][]string `json:"asks"`
		Bids [][]string `json:"bids"`
	} `json:"order_book"`
}

type OrderResponse

type OrderResponse struct {
	Order Order
}

type TradesResponse

type TradesResponse struct {
	Trades struct {
		MarketID      string          `json:"market_id"`
		Timestamp     interface{}     `json:"timestamp"`
		LastTimestamp string          `json:"last_timestamp"`
		Entries       [][]interface{} `json:"entries"`
	} `json:"trades"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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