bitbank

package module
v0.0.0-...-3bddcd1 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2021 License: MIT Imports: 6 Imported by: 0

README

go-bitbank

bitbank API forked from https://github.com/go-numb/go-bitbank

Description

go-bitbank is a go client library for Bitbank.cc API.

Installation

$ go get -u github.com/kikku340/go-bitbank

PublicAPI

package main

import (
 "fmt"
 "github.com/kikku340/go-bitbank"
)


func main() {
	c := bitbank.New("", "")

	c.Ticker.Set("btc_jpy")
	res, err := c.Ticker.Get()
	if err != nil {
		t.Error(err)
	}

	fmt.Printf("%v\n", res)

	doSomething()
}

PrivateAPI

package main

import (
 "fmt"
 "github.com/go-numb/go-bitbank"
)

func main() {

    // loads API keys
	var s Sign
	toml.DecodeFile("../.keys/bitbank.toml", &s)
	c := New(s.Token, s.Secret)

	res, err := c.Auth.Orders.Post(&orders.Body{
		Pair:   "bcc_btc",
		Amount: 0.0001, // to string
		Price:  0.04082002,
		Side:   "sell",
		Type:   "limit",
	})
	if err != nil {
		t.Error(err)
	}

	fmt.Printf("%v\n", res)

	doSomething()
}

websocket/realtime

func main() {
Reconnect:
	wsError := make(chan error)
	
	c, err := realtime.Connect(false)
	if err != nil {
		t.Error(err)
	}

	channels := []string{
		realtime.Depth, 
		realtime.Ticker,
		realtime.Transactions,
	}
	pairs := []string{
		realtime.BTCJPY,
		realtime.XRPJPY,
		realtime.ETHBTC,
	}

	// 購読チャンネルをbitbankに通知し購読開始
	go c.Realtime(channels, pairs)

	for {
		select {
		case v := <-ws.Subscriber:
			switch v.Types {
			case realtime.TypeDepthAll:
				// e.B.Set(true, v.Depth)
				// fmt.Println("depth all\n")
			case realtime.TypeDepthDiff:
				go e.B.Set(false, v.Depth)
				// e.BestPrice()
				// fmt.Printf("diff: %+v\n", v)
				// fmt.Println("depth diff")

			case realtime.TypeTransactions:
				// go e.Set(v.Transactions)
				// fmt.Printf("%.f, delay: %v\n", e.LTP, e.Delay)
				go fmt.Printf("transaction: LTP %f\n", v.Transactions[0].Price)
			case realtime.TypeTicker:
			case realtime.TypeError:
				wsError <- v.Error
			}
		}
	}

	err = <-wsError
	log.Error(err)
	ws.Close()
	time.Sleep(3 * time.Second)
	goto Reconnect
}

Author

@_numbP

License

MIT

Documentation

Index

Constants

View Source
const (
	PUBLIC_URL  = "https://public.bitbank.cc/"
	PRIVATE_URL = "https://private.bitbank.cc/"
	// API 公式ドキュメントに記載ないため,エラーで判別
	// 1mでリミットを設けておく(参考: BitflyerAPI limit)
	API_PRIVATE_LIMIT = 200
	API_PUBLIC_LIMIT  = 500
)

Variables

This section is empty.

Functions

This section is empty.

Types

type APILimit

type APILimit struct {
	sync.Mutex

	Public  int
	Private int
}

func (*APILimit) Reset

func (p *APILimit) Reset()

func (*APILimit) Sub

func (p *APILimit) Sub(isPrivate bool)

type Client

type Client struct {
	PublicURL  string
	PrivateURL string

	Transactions *transaction.Request
	Depth        *depth.Request
	Tickers      *ticker.Request
	OHLCV        *ohlcv.Request

	Auth *private.Auth

	Limit *APILimit
}

func New

func New(token, secret string) *Client

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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