• Stars
    star
    296
  • Rank 140,464 (Top 3 %)
  • Language
    Go
  • License
    MIT License
  • Created about 9 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

BITFINEX Go trading API - Bitcoin, Litecoin, and Ether exchange

Bitfinex Trading Library for GoLang - Bitcoin, Ethereum, Ripple and more

https://api.travis-ci.org/bitfinexcom/bitfinex-api-go.svg?branch=master

A Golang reference implementation of the Bitfinex API for both REST and websocket interaction.

Features

  • Official implementation
  • REST V1/V2 and Websocket
  • Connection multiplexing
  • Types for all data schemas

Installation

go get github.com/bitfinexcom/bitfinex-api-go

Optional - run the 'trade-feed' example to begin receiving realtime trade updates via the websocket

cd $GOPATH/src/github.com/bitfinexcom/bitfinex-api-go
go run examples/v2/trade-feed/main.go

Quickstart

package main

import (
    "fmt"
    "github.com/bitfinexcom/bitfinex-api-go/v2"
)

func main() {
    client := bitfinex.NewClient().Credentials("API_KEY", "API_SEC")
	
    // create order
    response, err := c.Orders.SubmitOrder(&order.NewRequest{
        Symbol: "tBTCUSD",
        CID:    time.Now().Unix() / 1000,
        Amount: 0.02,
        Type: 	"EXCHANGE LIMIT",
        Price:  5000,
    })
    if err != nil {
        panic(err)
    }
}

Docs

Examples

Authentication

func main() {
    client := bitfinex.NewClient().Credentials("API_KEY", "API_SEC")
}

Subscribe to Trades

// using github.com/bitfinexcom/bitfinex-api-go/v2/websocket as client
_, err := client.SubscribeTrades(context.Background(), "tBTCUSD")
if err != nil {
    log.Printf("Could not subscribe to trades: %s", err.Error())
}

Get candles via REST

// using github.com/bitfinexcom/bitfinex-api-go/v2/rest as client
os, err := client.Orders.AllHistory()
if err != nil {
    log.Fatalf("getting orders: %s", err)
}

See the examples directory for more, like:

FAQ

Is there any rate limiting?

For a Websocket connection there is no limit to the number of requests sent down the connection (unlimited order operations) however an account can only create 15 new connections every 5 mins and each connection is only able to subscribe to 30 inbound data channels. Fortunately this library handles all of the load balancing/multiplexing for channels and will automatically create/destroy new connections when needed, however the user may still encounter the max connections rate limiting error.

For rest the base limit per-user is 1,000 orders per 5 minute interval, and is shared between all account API connections. It increases proportionally to your trade volume based on the following formula:

1000 + (TOTAL_PAIRS_PLATFORM * 60 * 5) / (250000000 / USER_VOL_LAST_30d)

Where TOTAL_PAIRS_PLATFORM is the number of pairs on the Bitfinex platform (currently ~101) and USER_VOL_LAST_30d is in USD.

Will I always receive an on packet?

No; if your order fills immediately, the first packet referencing the order will be an oc signaling the order has closed. If the order fills partially immediately after creation, an on packet will arrive with a status of PARTIALLY FILLED...

For example, if you submit a LIMIT buy for 0.2 BTC and it is added to the order book, an on packet will arrive via ws2. After a partial fill of 0.1 BTC, an ou packet will arrive, followed by a final oc after the remaining 0.1 BTC fills.

On the other hand, if the order fills immediately for 0.2 BTC, you will only receive an oc packet.

My websocket won't connect!

Did you call client.Connect()? :)

nonce too small

I make multiple parallel request and I receive an error that the nonce is too small. What does it mean?

Nonces are used to guard against replay attacks. When multiple HTTP requests arrive at the API with the wrong nonce, e.g. because of an async timing issue, the API will reject the request.

If you need to go parallel, you have to use multiple API keys right now.

How do te and tu messages differ?

A te packet is sent first to the client immediately after a trade has been matched & executed, followed by a tu message once it has completed processing. During times of high load, the tu message may be noticably delayed, and as such only the te message should be used for a realtime feed.

What are the sequence numbers for?

If you enable sequencing on v2 of the WS API, each incoming packet will have a public sequence number at the end, along with an auth sequence number in the case of channel 0 packets. The public seq numbers increment on each packet, and the auth seq numbers increment on each authenticated action (new orders, etc). These values allow you to verify that no packets have been missed/dropped, since they always increase monotonically.

What is the difference between R* and P* order books?

Order books with precision R0 are considered 'raw' and contain entries for each order submitted to the book, whereas P* books contain entries for each price level (which aggregate orders).

Contributing

  1. Fork it (https://github.com/bitfinexcom/bitfinex-api-go/fork)
  2. Create your feature branch (`git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

More Repositories

1

bitfinex-api-node

BITFINEX NodeJS trading API - Bitcoin, Litecoin, and Ether exchange
JavaScript
459
star
2

bfx-hf-ui

JavaScript
212
star
3

grenache

DHT based high-performance microservices framework, by Bitfinex
206
star
4

bitfinex-api-py

Python
200
star
5

bfx-hf-algo

JavaScript
90
star
6

bitfinex-api-rb

BITFINEX Ruby trading API - Bitcoin, Litecoin, and Ether exchange
Ruby
80
star
7

bitfinex-terminal

JavaScript
69
star
8

bfx-hf-indicators

JavaScript
58
star
9

grenache-grape

Grenache Grape implementation
JavaScript
53
star
10

sunbeam

JavaScript
47
star
11

bfxfixgw

Bitfinex FIX Gateway
Go
45
star
12

dazaar

JavaScript
45
star
13

bfx-hf-algo-server

JavaScript
44
star
14

smidgen

JavaScript
43
star
15

bfx-hf-strategy-py

Python
40
star
16

bfx-hf-indicators-py

Python
31
star
17

bfx-hf-strategy

JavaScript
25
star
18

bfx-report-electron

JavaScript
23
star
19

hypertele

A swiss-knife proxy powered by Hyperswarm DHT
JavaScript
20
star
20

grenache-nodejs-ws

Grenache Node.JS WebSocket implementation
JavaScript
19
star
21

dazaar-vision

JavaScript
18
star
22

eosfinex-custody-contract

C++
18
star
23

antani

Proof of Liabilities and Vote Delegation
JavaScript
16
star
24

bfx-hf-backtest

JavaScript
15
star
25

bfx-pay-woocommerce

PHP
14
star
26

pub

14
star
27

bfx-hf-chart

JavaScript
14
star
28

bfx-hf-data-server

JavaScript
13
star
29

bfx-stuff-ui

Bitfinex UI Goodies
JavaScript
13
star
30

grenache-nodejs-http

Grenache Node.JS WebSocket implementation
JavaScript
13
star
31

bfx-api-node-models

JavaScript
12
star
32

bfx-api-node-rest

JavaScript
12
star
33

bfx-reports-framework

JavaScript
10
star
34

bfx-report-ui

JavaScript
10
star
35

grenache-cli

The Grenache Command Line Interface.
M4
8
star
36

svc-js-cli

JavaScript
8
star
37

bfx-api-excel-demo

Visual Basic 6.0
7
star
38

bfx-report

JavaScript
7
star
39

bfx-hf-server

JavaScript
7
star
40

grenache-nodejs-utp

JavaScript
7
star
41

caron

Atomic Job enqueuer from Redis lists to popular Job Queues (Sidekiq, Resque, Bull, ...)
JavaScript
7
star
42

ufx-ui

JavaScript
7
star
43

hypercore-benchmark

JavaScript
6
star
44

grenache-rust

Rust
6
star
45

grenache-ruby-http

Ruby
6
star
46

mobile-pub

6
star
47

dazaar-payment

JavaScript
6
star
48

bip

6
star
49

hypercore-bisect

JavaScript
6
star
50

bfx-api-node-core

JavaScript
5
star
51

bfx-api-mock-srv

JavaScript
5
star
52

bfx-util-net-js

JavaScript
5
star
53

bfx-hf-models

JavaScript
5
star
54

ulisse

MySQL table snapshots and real time updates to Redis ordered queue
JavaScript
5
star
55

bfx-hf-util

JavaScript
5
star
56

bfx-ost-streamer

The Bitfinex osTicket Streamer Plugin.
PHP
5
star
57

dazaar-payment-lightning

JavaScript
5
star
58

lokue

LokiJS Job Queue
JavaScript
4
star
59

grenache-nodejs-zmq

Grenache Node.JS ZeroMQ implementation, by Bitfinex
JavaScript
4
star
60

bfx-svc-js

Shell
4
star
61

wasteland

JavaScript
4
star
62

bfx-api-node-util

JavaScript
3
star
63

bfx-hf-models-adapter-template

JavaScript
3
star
64

bfx-report-express

JavaScript
3
star
65

pesto-rb

Redis based distributed lock for ruby
Ruby
3
star
66

mutail

Simple and fast file(s) tail. Works with wildcards.
JavaScript
3
star
67

bfx-cli

3
star
68

dazaar-cli

JavaScript
3
star
69

bfx-api-node-plugin-example

JavaScript
3
star
70

cheesebox

JavaScript
3
star
71

grenache-ruby-ws

Ruby
3
star
72

bfx-hf-strategy-exec

JavaScript
3
star
73

grenache-nodejs-base

JavaScript
3
star
74

moonbeam

JavaScript
3
star
75

dazaar-guild

JavaScript
3
star
76

bitfinex-api-php

PHP
3
star
77

bfx-ext-eos-multisig

JavaScript
3
star
78

bfx-hf-ext-plugin-dummy

JavaScript
3
star
79

grenache-nodejs-link

JavaScript
3
star
80

bfx-facs-auth-google

JavaScript
2
star
81

bfx-api-node-plugin-managed-ob

JavaScript
2
star
82

moonbeam-history

JavaScript
2
star
83

bfx-lib-server-js

JavaScript
2
star
84

eos-block-stream

JavaScript
2
star
85

grenache-nodejs-ws-tls

JavaScript
2
star
86

affiliates-nicknames

JavaScript
2
star
87

bitfinex-terminal-order-book

JavaScript
2
star
88

bfx-api-node-plugin-managed-candles

JavaScript
2
star
89

dazaar-www

CSS
2
star
90

hypercore-tutorial

2
star
91

lib-js-util-schema

2
star
92

bfx-api-node-plugin-ob-checksum

JavaScript
2
star
93

bfx-hf-strategy-dazaar

JavaScript
2
star
94

bfx-hf-ui-config

JavaScript
2
star
95

bfx-api-node-plugin-wd

JavaScript
2
star
96

bfx-util-js

Shell
2
star
97

bfx-api-node-plugin-seq-audit

JavaScript
2
star
98

dazaar-scatter-pay

JavaScript
2
star
99

bfx-api-node-mock-data

2
star
100

lib-js-util-math

JavaScript
2
star