api

package module
v0.0.0-...-44eb7c0 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2020 License: MIT Imports: 1 Imported by: 0

README

go-bitflyer

go-bitflyer is wrapper for Crypto Trading bitFlyer Lightning API, with Golang.

Fork & Tribute

github@kkohtaka

Modifications

  • bitflyer.com
  • time.UTC()
  • Akamai, and user headers
  • types
  • times.Bitflyer
  • Cancel by id
  • Order's special
  • API Limit from headers
  • API data cached
  • Websocket for private(child/parent orders)
  • Performance tuned

Usage

package main

import (
  "log"

  "github.com/go-numb/go-bitflyer/auth"
  "github.com/go-numb/go-bitflyer/v1"
  "github.com/go-numb/go-bitflyer/v1/public/markets"
  "github.com/go-numb/go-bitflyer/v1/private/permissions"
)

func main() {
  client := v1.NewClient(&v1.ClientOpts{
    AuthConfig: &auth.AuthConfig{
      APIKey:    "<api_key>",
      APISecret: "<api_secretkey>",
    },
  })

  // return this Struct, Raw response, error 
  s, res, err := client.Permissions(&permissions.Request{})
  if err != nil {
    log.Fatalln(err)
  } else {
    log.Println(resp)
  }

  s, res, err = client.Markets(&markets.Request{})
  if err != nil {
    log.Fatalln(err)
  } else {
    log.Println(resp)
  }
}

bitflyer API realtime json-rpc

import	"github.com/go-numb/go-bitflyer/v1/jsonrpc"

func main() {
  done := make(chen struct{})

  // log can be rewritten as nil
  log := logrus.New()

  recieve := make(chan WsWriter)
  ctx, cancel := context.WithCancel(context.Background())

  go jsonrpc.Connect(ctx, recieve, []string{
		"lightning_board_snapshot",
		"lightning_board",
		"lightning_ticker",
		"lightning_executions",
	}, []string{
		string(types.FXBTCJPY),
		string(types.BTCJPY),
		string(types.ETHJPY),
  },log)
  
  go jsonrpc.ConnectForPrivate(ctx, recieve, <API_KEY>, <API_SECRET>, []string{
		"child_order_events",
		"parent_order_events",
	},log)

	go func() {
		for {
			select {
			case v := <-recieve:
				switch v.Types {
				case Board:
					fmt.Printf("%s - %+v\n", v.ProductCode, v.Board)
				case Ticker:
					fmt.Printf("%s - %+v\n", v.ProductCode, v.Ticker)
				case Executions:
					fmt.Printf("%s - %+v\n", v.ProductCode, v.Executions)

				case ChildOrders:
					fmt.Printf("%+v\n", v.ChildOrderEvent)
				case ParentOrders:
					fmt.Printf("%+v\n", v.ParentOrderEvent)

				case Undefined:
					fmt.Printf("undefined: %s - %+v\n", v.ProductCode, v.Results)
				case Error:
					fmt.Printf("error: %s - %+v\n", v.ProductCode, v.Results)

				}
			}

			select {
			case <-ctx.Done():
				return
			default:
			}
		}()

  <-done
}

Author

@_numbP

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type API

type API interface {
	ToURL() (*url.URL, error)
}

type Client

type Client interface {
	APIHost() string
}

type Request

type Request interface {
	Method() string
	Query() string
	Payload() []byte
}

Jump to

Keyboard shortcuts

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