Code Monkey home page Code Monkey logo

bitfinex-api-go's Introduction

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

bitfinex-api-go's People

Contributors

abrander avatar addodelgrossi avatar alehano avatar alekna avatar andreygrehov avatar asgeir-s avatar avdva avatar brobits avatar daniel1984 avatar davide-scola avatar erubboli avatar firstrow avatar fshiori avatar hectorj avatar igrmk avatar jacobplaster avatar jvatianou-connamara avatar knarz avatar ksiamis-connamara avatar mbags avatar michaelwilner avatar prdn avatar preexo avatar remco-remco avatar robertkowalski avatar suonlight avatar uakfdotb avatar vorandrew avatar vstoican avatar wyaeld avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bitfinex-api-go's Issues

the first example gives error when rendering

./main.go:26:67: undefined: bitfinex.ORDER_TYPE_EXCHANGE_LIMIT

it's because it should be OrderTypeExchangeLimit without underscores
./main.go:26:67: undefined: bitfinex.OrderTypeExchangeLimit

best to adapt it everywhere in the examples

v2: done chan closed twice

websocket_service.go can end up closing b.done twice. This can happen if a write tries to send a message but a TCP reset comes in and shuts down the socket. Both the receiver() goroutine and the writer can call b.close(). When they both check to see if the chan is closed at the same time, it's not, so they both end up closing it at the same time, and one of them gets a panic because you can't close an already closed chan.

Websocket connection times out with i/o timeout despite pinging

Websocket connections time out after no data is sent/received from bitfinex for a given time frame. Pinging on my side with {"event":"ping"} does not reset the timeout.

read tcp 10.244.6.19:56636->104.16.175.181:443: i/o timeout","time":1536931995,"message":"worker: connection failed: read tcp 10.244.6.19:56636->104.16.175.181:443: i/o timeout recreating: edo-eth

Reconnecting is not the issue but hitting the RATE LIMIT is. That's how i reach the rate limit more frequently. How can i avoid this behavior. Should i ping differently?

nonce, claim

  1. Nonce is not properly generated. Nonce must be always higher and higher number. There is my own implementation: https://github.com/malaschitz/bitfinex-api-go/blob/master/utils/nonce.go

  2. Second problem is with claim. Function claim in positions.go send position_id as string. It is wrong and bitfinex return error: position_id must be integer.

  3. But worst problem, when I change properly claim function, api do not return any response. There is probably some bug directly in API of bitfinex. I am not able claim my position and there is not other possibility.

Can not use "go get"

I just ran "go get github.com/bitfinexcom/bitfinex-api-go" as it said in readme, but it doesn't work. How can I solve this problem?

image

v2 Candles API returns incomplete data

If the candle at time index X and X+1 have the same data (ie: no chart movement), API does not include candle X+1. This shows time "blanks" when examining the data. Cannot find documentation of this non-standard behavior. I say non-standard because none of the other major exchanges operate this way. At other exchanges, all time slices are always returned regardless if the data is the same or not. The API example code does not dive into this either. How are you supposed to handle this "missing data" issue?

header was not sent

Hi

I did set my API keys correctly. Now I am running:

~/.software/bitfinex-api-go> go run examples/account/main.go

and I get

GET https://api.bitfinex.com/v1/account_infos: 400 X-BFX-APIKEY header was not sent.

v2: panic: interface conversion: interface {} is nil, not []interface {}

Looks like some message couldn't be decoded.

Not sure how to tackle this, anyone an idea?
Should we be catching this before it get's through the switch into notificationFromRaw?

panic: interface conversion: interface {} is nil, not []interface {}

goroutine 11 [running]:
github.com/bitfinexcom/bitfinex-api-go/v2.notificationFromRaw(0x1081e880, 0x8, 0x8, 0x0, 0x0, 0x1097e261, 0xf, 0x0, 0x0, 0x0, ...)
        /home/pi/go/src/github.com/bitfinexcom/bitfinex-api-go/v2/private_types.go:916 +0x590
github.com/bitfinexcom/bitfinex-api-go/v2.(*bfxWebsocket).convertRaw(0x10856c40, 0x1097e260, 0x1, 0x1081e880, 0x8, 0x8, 0x1083bee8, 0x341040)
        /home/pi/go/src/github.com/bitfinexcom/bitfinex-api-go/v2/websocket_private.go:140 +0x1dc
github.com/bitfinexcom/bitfinex-api-go/v2.(*bfxWebsocket).handlePrivateDataMessage(0x10856c40, 0x1095c5a0, 0x3, 0x4, 0x10ccc548, 0x1, 0x0, 0x0)
        /home/pi/go/src/github.com/bitfinexcom/bitfinex-api-go/v2/websocket_private.go:27 +0xe0
github.com/bitfinexcom/bitfinex-api-go/v2.(*bfxWebsocket).handleMessage(0x10856c40, 0x108b1800, 0x73, 0x600, 0x600, 0x0)
        /home/pi/go/src/github.com/bitfinexcom/bitfinex-api-go/v2/websocket_service.go:251 +0x214
github.com/bitfinexcom/bitfinex-api-go/v2.(*bfxWebsocket).receiver(0x10856c40)
        /home/pi/go/src/github.com/bitfinexcom/bitfinex-api-go/v2/websocket_service.go:157 +0xc8
created by github.com/bitfinexcom/bitfinex-api-go/v2.(*bfxWebsocket).connect
        /home/pi/go/src/github.com/bitfinexcom/bitfinex-api-go/v2/websocket_service.go:121 +0x194

go test -v ./tests/integration

I am following your instructions and I get the following:

~/.software/bitfinex-api-go> go test -v ./tests/integration
# _/home/zeno/.software/bitfinex-api-go/tests/integration
tests/integration/order_book_test.go:8: not enough arguments in call to client.OrderBook.Get
        have (string)
        want (string, int, int, bool)
FAIL    _/home/zeno/.software/bitfinex-api-go/tests/integration [build failed]

what am I doing wrong? The keys are there.

Ho do I install?

Hi

How do I install this software?

I am doing

~/.software/bitfinex-api-go> go generate

then

~/.software/bitfinex-api-go> go install

and then I get

websocket.go:13:5: cannot find package "github.com/gorilla/websocket" in any of:
        /usr/lib/go/src/github.com/gorilla/websocket (from $GOROOT)
        ($GOPATH not set)

v1 Wallet apis wrong http methods

Hi guys,

WithdrawCrypto, WithdrawWire and Transfer methods seem to be using GET
http method although the respective endpoints are POST

I am willing to make a pr if you give me a go ahead.

400 Nonce is too small, after some calls

I'm finding the error:

400 Nonce is too small
https://api.bitfinex.com/v1/balances

There is a strange behavior, the first calls work, after a certain period the error starts to occur and it does not work anymore.

Any idea ?

v2: Wrong endpoints

Attempting to use example v2:

2018/02/09 15:25:40 getting orders: POST https://api.bitfinex.com/v2/orders/tIOTBTC/hist: 404 Error decoding response error message. Please see response body for more information. (0)

Documentation says path should be this /auth/r/orders/tBTCUSD/hist
Probably others that have this wrong too.

v2: Websocket connection errors

I am using the Websocket package to subscribe to Ticker updates and I am getting connection errors.
It was working before, but I recently reinstalled my dependencies (not an update).

Some other things broke too.
Such as the new client method 15f42ed#diff-93015be9a1b3ee72156236756317284dL220

Is there a possibility to have tags or versioning on the repo as well?
This way we can keep using the package without the fear of it breaking in the future.

Websocket Log

2018/02/16 11:08:17 sub len: 0
2018/02/16 11:08:17 connecting ws to wss://api.bitfinex.com/ws/2
2018/02/16 11:08:19 MSG RECV: &websocket.InfoEvent{Version:2}
2018/02/16 11:08:19 MSG RECV: &websocket.SubscribeEvent{SubID:"1518808097001", Channel:"ticker", ChanID:1, Symbol:"tBTCUSD", Precision:"", Frequency:"", Key:"", Len:"", Pair:"BTCUSD"}
2018/02/16 11:08:19 MSG RECV: &bitfinex.Ticker{Symbol:"tBTCUSD", Bid:9947, BidPeriod:0, BidSize:63.74092799, Ask:9947.1, AskPeriod:0, AskSize:47.82445395, DailyChange:-77, DailyChangePerc:-0.0077, LastPrice:9947, Volume:50804.0219273, High:10271, Low:9670}
2018/02/16 11:08:24 reconnect attempt 1/5
2018/02/16 11:08:24 sub len: 1
2018/02/16 11:08:24 connecting ws to wss://api.bitfinex.com/ws/2
2018/02/16 11:08:25 resubscribing to ticker tBTCUSD with nonce 1518808097002
2018/02/16 11:08:25 MSG RECV: &websocket.InfoEvent{Version:2}
2018/02/16 11:08:25 [WARN]: could not find subscription for channel ID 1
2018/02/16 11:08:25 MSG RECV: &websocket.SubscribeEvent{SubID:"1518808097002", Channel:"ticker", ChanID:1, Symbol:"tBTCUSD", Precision:"", Frequency:"", Key:"", Len:"", Pair:"BTCUSD"}
2018/02/16 11:08:27 MSG RECV: &bitfinex.Ticker{Symbol:"tBTCUSD", Bid:9946, BidPeriod:0, BidSize:64.07389119, Ask:9946.1, AskPeriod:0, AskSize:63.59846063, DailyChange:-77, DailyChangePerc:-0.0077, LastPrice:9947, Volume:50809.02576089, High:10271, Low:9670}
2018/02/16 11:08:30 reconnect attempt 1/5
2018/02/16 11:08:30 sub len: 1
2018/02/16 11:08:30 connecting ws to wss://api.bitfinex.com/ws/2
2018/02/16 11:08:30 resubscribing to ticker tBTCUSD with nonce 1518808097003
2018/02/16 11:08:30 MSG RECV: &websocket.InfoEvent{Version:2}
2018/02/16 11:08:31 [WARN]: could not find subscription for channel ID 3
2018/02/16 11:08:31 MSG RECV: &websocket.SubscribeEvent{SubID:"1518808097003", Channel:"ticker", ChanID:3, Symbol:"tBTCUSD", Precision:"", Frequency:"", Key:"", Len:"", Pair:"BTCUSD"}
2018/02/16 11:08:35 reconnect attempt 1/5
2018/02/16 11:08:35 sub len: 1
2018/02/16 11:08:35 connecting ws to wss://api.bitfinex.com/ws/2
2018/02/16 11:08:36 resubscribing to ticker tBTCUSD with nonce 1518808097004
2018/02/16 11:08:36 MSG RECV: &websocket.InfoEvent{Version:2}
2018/02/16 11:08:37 [WARN]: could not find subscription for channel ID 2
2018/02/16 11:08:37 MSG RECV: &websocket.SubscribeEvent{SubID:"1518808097004", Channel:"ticker", ChanID:2, Symbol:"tBTCUSD", Precision:"", Frequency:"", Key:"", Len:"", Pair:"BTCUSD"}
2018/02/16 11:08:37 MSG RECV: &bitfinex.Ticker{Symbol:"tBTCUSD", Bid:9949.1, BidPeriod:0, BidSize:66.94639044, Ask:9950, AskPeriod:0, AskSize:35.63762188, DailyChange:-74, DailyChangePerc:-0.0074, LastPrice:9950, Volume:50808.91830258, High:10271, Low:9670}
2018/02/16 11:08:41 reconnect attempt 1/5
2018/02/16 11:08:41 sub len: 1
2018/02/16 11:08:41 connecting ws to wss://api.bitfinex.com/ws/2
2018/02/16 11:08:42 resubscribing to ticker tBTCUSD with nonce 1518808097005
2018/02/16 11:08:42 MSG RECV: &websocket.InfoEvent{Version:2}
2018/02/16 11:08:42 [WARN]: could not find subscription for channel ID 2
2018/02/16 11:08:42 MSG RECV: &websocket.SubscribeEvent{SubID:"1518808097005", Channel:"ticker", ChanID:2, Symbol:"tBTCUSD", Precision:"", Frequency:"", Key:"", Len:"", Pair:"BTCUSD"}
2018/02/16 11:08:47 reconnect attempt 1/5
2018/02/16 11:08:47 sub len: 1
2018/02/16 11:08:47 connecting ws to wss://api.bitfinex.com/ws/2
2018/02/16 11:08:47 resubscribing to ticker tBTCUSD with nonce 1518808097006
2018/02/16 11:08:47 MSG RECV: &websocket.InfoEvent{Version:2}
2018/02/16 11:08:48 [WARN]: could not find subscription for channel ID 5
2018/02/16 11:08:48 MSG RECV: &websocket.SubscribeEvent{SubID:"1518808097006", Channel:"ticker", ChanID:5, Symbol:"tBTCUSD", Precision:"", Frequency:"", Key:"", Len:"", Pair:"BTCUSD"}
2018/02/16 11:08:48 MSG RECV: &bitfinex.Ticker{Symbol:"tBTCUSD", Bid:9963.9, BidPeriod:0, BidSize:75.5583129, Ask:9966.5, AskPeriod:0, AskSize:52.52509153, DailyChange:-59.5, DailyChangePerc:-0.0059, LastPrice:9964.5, Volume:50815.72499832, High:10271, Low:9670}
2018/02/16 11:08:52 reconnect attempt 1/5
2018/02/16 11:08:52 sub len: 1
2018/02/16 11:08:52 connecting ws to wss://api.bitfinex.com/ws/2
2018/02/16 11:08:53 resubscribing to ticker tBTCUSD with nonce 1518808097007
2018/02/16 11:08:53 MSG RECV: &websocket.InfoEvent{Version:2}
2018/02/16 11:08:53 [WARN]: could not find subscription for channel ID 12
2018/02/16 11:08:53 MSG RECV: &websocket.SubscribeEvent{SubID:"1518808097007", Channel:"ticker", ChanID:12, Symbol:"tBTCUSD", Precision:"", Frequency:"", Key:"", Len:"", Pair:"BTCUSD"}
2018/02/16 11:08:58 reconnect attempt 1/5
2018/02/16 11:08:58 sub len: 1
2018/02/16 11:08:58 connecting ws to wss://api.bitfinex.com/ws/2
2018/02/16 11:08:59 resubscribing to ticker tBTCUSD with nonce 1518808097008
2018/02/16 11:08:59 MSG RECV: &websocket.InfoEvent{Version:2}
2018/02/16 11:08:59 [WARN]: could not find subscription for channel ID 5
2018/02/16 11:08:59 MSG RECV: &websocket.SubscribeEvent{SubID:"1518808097008", Channel:"ticker", ChanID:5, Symbol:"tBTCUSD", Precision:"", Frequency:"", Key:"", Len:"", Pair:"BTCUSD"}
2018/02/16 11:09:04 reconnect attempt 1/5
2018/02/16 11:09:04 sub len: 1
2018/02/16 11:09:04 connecting ws to wss://api.bitfinex.com/ws/2
2018/02/16 11:09:04 resubscribing to ticker tBTCUSD with nonce 1518808097009
2018/02/16 11:09:04 MSG RECV: &websocket.InfoEvent{Version:2}
2018/02/16 11:09:04 [WARN]: could not find subscription for channel ID 5
2018/02/16 11:09:04 MSG RECV: &websocket.SubscribeEvent{SubID:"1518808097009", Channel:"ticker", ChanID:5, Symbol:"tBTCUSD", Precision:"", Frequency:"", Key:"", Len:"", Pair:"BTCUSD"}
2018/02/16 11:09:08 MSG RECV: &bitfinex.Ticker{Symbol:"tBTCUSD", Bid:9958.1, BidPeriod:0, BidSize:55.43289962, Ask:9958.9, AskPeriod:0, AskSize:14.35730542, DailyChange:-65.7, DailyChangePerc:-0.0066, LastPrice:9958.3, Volume:50827.83805265, High:10271, Low:9670}
2018/02/16 11:09:09 reconnect attempt 1/5
2018/02/16 11:09:09 sub len: 1
2018/02/16 11:09:09 connecting ws to wss://api.bitfinex.com/ws/2
2018/02/16 11:09:09 resubscribing to ticker tBTCUSD with nonce 1518808097010
2018/02/16 11:09:09 MSG RECV: &websocket.InfoEvent{Version:2}
2018/02/16 11:09:10 [WARN]: could not find subscription for channel ID 9
2018/02/16 11:09:10 MSG RECV: &websocket.SubscribeEvent{SubID:"1518808097010", Channel:"ticker", ChanID:9, Symbol:"tBTCUSD", Precision:"", Frequency:"", Key:"", Len:"", Pair:"BTCUSD"}
2018/02/16 11:09:14 reconnect attempt 1/5
2018/02/16 11:09:14 sub len: 1
2018/02/16 11:09:14 connecting ws to wss://api.bitfinex.com/ws/2
2018/02/16 11:09:16 resubscribing to ticker tBTCUSD with nonce 1518808097011
2018/02/16 11:09:16 MSG RECV: &websocket.InfoEvent{Version:2}
2018/02/16 11:09:16 [WARN]: could not find subscription for channel ID 16
2018/02/16 11:09:16 MSG RECV: &websocket.SubscribeEvent{SubID:"1518808097011", Channel:"ticker", ChanID:16, Symbol:"tBTCUSD", Precision:"", Frequency:"", Key:"", Len:"", Pair:"BTCUSD"}
2018/02/16 11:09:18 MSG RECV: &bitfinex.Ticker{Symbol:"tBTCUSD", Bid:9954.1, BidPeriod:0, BidSize:83.21620341, Ask:9954.2, AskPeriod:0, AskSize:26.7526391, DailyChange:-69.1, DailyChangePerc:-0.0069, LastPrice:9954.9, Volume:50827.60858321, High:10271, Low:9670}
2018/02/16 11:09:21 reconnect attempt 1/5
2018/02/16 11:09:21 sub len: 1
2018/02/16 11:09:21 connecting ws to wss://api.bitfinex.com/ws/2
2018/02/16 11:09:22 resubscribing to ticker tBTCUSD with nonce 1518808097012
2018/02/16 11:09:22 MSG RECV: &websocket.InfoEvent{Version:2}
2018/02/16 11:09:23 MSG RECV: &websocket.SubscribeEvent{SubID:"1518808097012", Channel:"ticker", ChanID:3, Symbol:"tBTCUSD", Precision:"", Frequency:"", Key:"", Len:"", Pair:"BTCUSD"}
2018/02/16 11:09:23 MSG RECV: &bitfinex.Ticker{Symbol:"tBTCUSD", Bid:9954.1, BidPeriod:0, BidSize:83.21620341, Ask:9954.2, AskPeriod:0, AskSize:26.7526391, DailyChange:-69.1, DailyChangePerc:-0.0069, LastPrice:9954.9, Volume:50827.60858321, High:10271, Low:9670}
2018/02/16 11:09:27 reconnect attempt 1/5
2018/02/16 11:09:27 sub len: 1
2018/02/16 11:09:27 connecting ws to wss://api.bitfinex.com/ws/2
2018/02/16 11:09:28 resubscribing to ticker tBTCUSD with nonce 1518808097013
2018/02/16 11:09:28 MSG RECV: &websocket.InfoEvent{Version:2}
2018/02/16 11:09:29 [WARN]: could not find subscription for channel ID 15
2018/02/16 11:09:29 MSG RECV: &websocket.SubscribeEvent{SubID:"1518808097013", Channel:"ticker", ChanID:15, Symbol:"tBTCUSD", Precision:"", Frequency:"", Key:"", Len:"", Pair:"BTCUSD"}
2018/02/16 11:09:33 reconnect attempt 1/5
2018/02/16 11:09:33 sub len: 1
2018/02/16 11:09:33 connecting ws to wss://api.bitfinex.com/ws/2
2018/02/16 11:09:34 resubscribing to ticker tBTCUSD with nonce 1518808097014
2018/02/16 11:09:34 MSG RECV: &websocket.InfoEvent{Version:2}
2018/02/16 11:09:34 MSG RECV: &websocket.SubscribeEvent{SubID:"1518808097014", Channel:"ticker", ChanID:9, Symbol:"tBTCUSD", Precision:"", Frequency:"", Key:"", Len:"", Pair:"BTCUSD"}
2018/02/16 11:09:34 MSG RECV: &bitfinex.Ticker{Symbol:"tBTCUSD", Bid:9952, BidPeriod:0, BidSize:60.27652022, Ask:9952.1, AskPeriod:0, AskSize:35.26959297, DailyChange:-115.9, DailyChangePerc:-0.0115, LastPrice:9952.1, Volume:50826.37450999, High:10271, Low:9670}
2018/02/16 11:09:37 MSG RECV: &bitfinex.Ticker{Symbol:"tBTCUSD", Bid:9951, BidPeriod:0, BidSize:59.8403597, Ask:9951.1, AskPeriod:0, AskSize:30.41273471, DailyChange:-116.92401978, DailyChangePerc:-0.0116, LastPrice:9951.07598022, Volume:50826.03804297, High:10271, Low:9670}
2018/02/16 11:09:39 reconnect attempt 1/5
2018/02/16 11:09:39 sub len: 1
2018/02/16 11:09:39 connecting ws to wss://api.bitfinex.com/ws/2
2018/02/16 11:09:40 resubscribing to ticker tBTCUSD with nonce 1518808097015
2018/02/16 11:09:40 MSG RECV: &websocket.InfoEvent{Version:2}
2018/02/16 11:09:40 [WARN]: could not find subscription for channel ID 2
2018/02/16 11:09:40 MSG RECV: &websocket.SubscribeEvent{SubID:"1518808097015", Channel:"ticker", ChanID:2, Symbol:"tBTCUSD", Precision:"", Frequency:"", Key:"", Len:"", Pair:"BTCUSD"}
2018/02/16 11:09:45 reconnect attempt 1/5
2018/02/16 11:09:45 sub len: 1
2018/02/16 11:09:45 connecting ws to wss://api.bitfinex.com/ws/2
2018/02/16 11:09:46 resubscribing to ticker tBTCUSD with nonce 1518808097016
2018/02/16 11:09:46 MSG RECV: &websocket.InfoEvent{Version:2}
2018/02/16 11:09:46 [WARN]: could not find subscription for channel ID 2
2018/02/16 11:09:46 MSG RECV: &websocket.SubscribeEvent{SubID:"1518808097016", Channel:"ticker", ChanID:2, Symbol:"tBTCUSD", Precision:"", Frequency:"", Key:"", Len:"", Pair:"BTCUSD"}
2018/02/16 11:09:47 MSG RECV: &bitfinex.Ticker{Symbol:"tBTCUSD", Bid:9951, BidPeriod:0, BidSize:63.12733983, Ask:9951.1, AskPeriod:0, AskSize:28.70953471, DailyChange:-116.9, DailyChangePerc:-0.0116, LastPrice:9951.1, Volume:50818.87207771, High:10271, Low:9670}
2018/02/16 11:09:51 reconnect attempt 1/5
2018/02/16 11:09:51 sub len: 1
2018/02/16 11:09:51 connecting ws to wss://api.bitfinex.com/ws/2
2018/02/16 11:09:52 resubscribing to ticker tBTCUSD with nonce 1518808097017
2018/02/16 11:09:52 MSG RECV: &websocket.InfoEvent{Version:2}
2018/02/16 11:09:52 MSG RECV: &websocket.SubscribeEvent{SubID:"1518808097017", Channel:"ticker", ChanID:1, Symbol:"tBTCUSD", Precision:"", Frequency:"", Key:"", Len:"", Pair:"BTCUSD"}
2018/02/16 11:09:52 MSG RECV: &bitfinex.Ticker{Symbol:"tBTCUSD", Bid:9951, BidPeriod:0, BidSize:63.12733983, Ask:9951.1, AskPeriod:0, AskSize:28.70953471, DailyChange:-116.9, DailyChangePerc:-0.0116, LastPrice:9951.1, Volume:50818.87207771, High:10271, Low:9670}
2018/02/16 11:09:57 reconnect attempt 1/5
2018/02/16 11:09:57 sub len: 1
2018/02/16 11:09:57 connecting ws to wss://api.bitfinex.com/ws/2
2018/02/16 11:09:57 bad handshake: status code 429
2018/02/16 11:09:57 reconnect failed: websocket: bad handshake
2018/02/16 11:09:58 reconnect attempt 2/5
2018/02/16 11:09:58 sub len: 0
2018/02/16 11:09:58 connecting ws to wss://api.bitfinex.com/ws/2
2018/02/16 11:09:58 bad handshake: status code 429
2018/02/16 11:09:58 reconnect failed: websocket: bad handshake
2018/02/16 11:09:59 reconnect attempt 3/5
2018/02/16 11:09:59 sub len: 0
2018/02/16 11:09:59 connecting ws to wss://api.bitfinex.com/ws/2
2018/02/16 11:09:59 bad handshake: status code 429
2018/02/16 11:09:59 reconnect failed: websocket: bad handshake
2018/02/16 11:10:00 reconnect attempt 4/5
2018/02/16 11:10:00 sub len: 0
2018/02/16 11:10:00 connecting ws to wss://api.bitfinex.com/ws/2
2018/02/16 11:10:00 bad handshake: status code 429
2018/02/16 11:10:00 reconnect failed: websocket: bad handshake
2018/02/16 11:10:01 reconnect attempt 5/5
2018/02/16 11:10:01 sub len: 0
2018/02/16 11:10:01 connecting ws to wss://api.bitfinex.com/ws/2
2018/02/16 11:10:02 bad handshake: status code 429
2018/02/16 11:10:02 reconnect failed: websocket: bad handshake
2018/02/16 11:10:02 could not reconnect: websocket: bad handshake
2018/02/16 11:10:02 Bitfinex listening error: %+vwebsocket: bad handshake
exit status 1

response not matching the api documentation

According to the v1.1 docs, my response for the ticker websocket should look like:

[ 3, 8606.1, 45.3786527, 8607, 27.6446367, -426, -0.0472, 8606.1, 54199.00831008, 9095.92211691, 8450 ]

however, my responses look like this:

[2.16389896e+08 1.521767351e+09 8609.4 -0.002]

Using the examples for v1 websockets.

Callback Architecture

bitfinex-api-node has a general callback architecture to easily and dynamically attach callbacks to receipts of a specific message type. This PR implements a similar callback architecture for Go, which will enable the addition of future convenience methods like onTrade and onBookUpdate

Public trade history is missing v2

Hi, I could not find a method to get public trades for a pair in specific period in API version 2. As far as I understood TradeService.All method fetches only users trade history(link). Are you planning to add public trades method?

Websocket v2 subscriptions are silently ignored

Hey guys,

since a couple of days I'm no longer receiving subscribed events for some submitted subscription requests. Instead, when trying to subscribe the unanswered requests again after about 10 sec, I get subscribe: dup code 10301 errors. See the packet log for an activity dump (timestamps are in UTC, server id 3acdef95-0b68-4610-8ab5-8767f23c48a9, this was on api.ethfinex.com).

The problem occurs both on wss://api.bitfinex.com/ws/2 and wss://api.ethfinex.com/ws/2. In only maybe 1 out of 10 trials all subscriptions are confirmed.

We're a heavy users of your API (watching all trades on all markets) and we've already implemented subscription limiting to max 50. We're opening 5-6 websockets and sending subscription requests in a tight loop when starting up. Up until a few days ago this strategy worked just fine. Please let me know if you want us to change anything.

No Initial Orderbook Snapshot

Hi,

I don't receive any Orderbook Snapshots when connecting to the public stream via websocket. (subscribed with SubscribeBook).

But I see the debugging messages in transport.go on line 123:

log.Print(string(msg))

as

2018/01/15 01:46:29 [9111,[[3.752,1,876.71361388],[3.7502,2,185.63378099],[3.7501,1,20],[3.75,3,31503.85235593],[3.7457,1,320],[3.7456,1,730.84438071],[3.7426,1,913.47471184],[3.7425,1,1826.94942368],[3.74,1,355.27607171],[3.7389,1,167.07958922],[3.7348,8,1136.1],[3.7314,2,13400.32458425],[3.7313,1,3651.16182747],[3.7286,1,200],[3.7285,2,133.0928],[3.7267,1,1500],[3.7247,1,12],[3.7221,1,768.011836],[3.722,1,6],[3.7201,1,470.02721328],[3.72,2,5225.61796573],[3.7199,1,2000],[3.7185,1,2000],[3.7145,1,5000],[3.7139,2,57.80859409],[3.7526,1,-142.55],[3.7533,1,-19.69919349],[3.7549,1,-700],[3.755,1,-148.98331241],[3.7556,1,-142.55],[3.7558,1,-35],[3.7564,1,-74.4387],[3.76,1,-10],[3.7635,1,-50],[3.7637,1,-33.16071688],[3.7645,1,-29.69919349],[3.7648,1,-2935.8425746],[3.7649,1,-69],[3.765,1,-164.54664179],[3.7659,1,-13.279],[3.7662,1,-11.415573],[3.7666,1,-35.71154125],[3.7667,1,-12],[3.7676,1,-30],[3.7677,1,-1223.8],[3.7687,1,-1500],[3.7692,1,-60],[3.7693,1,-1907.3],[3.7697,1,-121.5569],[3.77,3,-1133.17058023]]]

The message is not handled it seems.

Any ideas?

Duplicate write onchannel from websocket

I signal here that using websocket to retrieve data (V1) something strange happens

// api is a bitfinex V1 client
api.WebSocket.AddSubscribe(bitfinex.ChanTicker, tickerKey, tickers)
handleTicker := func(results <-chan []float64, tickerKey string) {
		for {
			values, stillOpen := <-results
			if !stillOpen {
				return
			}
                        fmt.Println(values, tickerKey)
                        // ... other code
		}
	}
        go handleTicker(tickers, tickerKey)

        go api.Subscribe()

Here the output

[0.0085788 693.42706957 0.0085809 807.79752121 -0.0001808 -0.0207 0.0085692 24460.81097189 0.008895 0.0085195] LTCBTC
[0.0085809 807.79752121 -0.0001808 -0.0207 0.0085692 24460.81097189 0.008895 0.0085195] LTCBTC

[0.032302 351.59487017 0.032315 242.43108078 -0.003122 -0.0881 0.032315 35404.67950253 0.035663 0.031924] ETHBTC
[0.032315 242.43108078 -0.003122 -0.0881 0.032315 35404.67950253 0.035663 0.031924] ETHBTC

[0.020202 825.36196188 0.020237 1068.59876956 0.001134 0.0595 0.0202 22745.26364041 0.022298 0.019021] ZECBTC
[0.020237 1068.59876956 0.001134 0.0595 0.0202 22745.26364041 0.022298 0.019021] ZECBTC

[0.0016445 4739.97658367 0.0016459 3647.27738417 -3.23e-05 -0.0192 0.0016467 20592.09547885 0.0016937 0.0016419] ETCBTC
[0.0016459 3647.27738417 -3.23e-05 -0.0192 0.0016467 20592.09547885 0.0016937 0.0016419] ETCBTC

[3.636e-05 604689.79599884 3.658e-05 214247.56797288 -2.7e-06 -0.027 3.654e-05 576044.754326 4.159e-05 3.641e-05] XLMBTC
[3.658e-05 214247.56797288 -2.7e-06 -0.027 3.654e-05 576044.754326 4.159e-05 3.641e-05] XLMBTC

Let's take first couple of lines

[0.0085788 693.42706957 0.0085809 807.79752121 -0.0001808 -0.0207 0.0085692 24460.81097189 0.008895 0.0085195] LTCBTC
[0.0085809 807.79752121 -0.0001808 -0.0207 0.0085692 24460.81097189 0.008895 0.0085195] LTCBTC

The first two elements of the array (got from the channel) are missing
the call of handleDataMessage in the library fills the channel twice, and removes the first two elements the second time it pushes into the chan.

Please solve this or explain if this is a normal behaviour, thanks

v2: Don't use float64

float64 is used in a few places in the v2 code. Aside from the obvious case of fractional precision loss, floats are also imprecise for large numbers: https://play.golang.org/p/Xht8UkOf7q which could be relevant here if channel IDs ever become large, and is more likely to soon be relevant for order IDs (which are already up to 6129454770 as of the time of this issue).

For the bodies (pricing & amounts), I think unmarshalling of the value should be deferred (e.g. via json.RawMessage), and then converted to float only if the consumer is OK with the imprecision. Otherwise the raw value should be provided as a []byte.

Withdraw paylaod

To withdraw Ripple you need to include the ripple tag in the payment_id field in the withdraw request. V1 does not include a payment_id input to the Withdraw method.

issues installing the package.

when i run go get github.com/bitfinexcom/bitfinex-api-go i get an error that says there are no buildable source files in the directory. I've tried running go get github.com/bitfinexcom/bitfinex-api-go/utils which works fine, but go get github.com/bitfinexcom/bitfinex-api-go/bitfinex does not work. obviously I am missing something here. Anyone got any ideas?

Edit:

Never mind, I figured it out. its go get github.com/bitfinexcom/bitfinex-api-go/v1. You should update the documentation to reflect this.

Unsupported protocol scheme

When I try running the example in examples/account I get the following error:

Error: Get wss://api.bitfinex.com/account_infos: unsupported protocol scheme "wss"

Is this related to the recently updated API endpoints?

fix precision problems

Hi,
I got such error message, I suppose it's better to change at here.

2018/12/27 08:24:03 jenny.go:467: DayBreak.createPosition - s.egn.SubmitSingleOrder(xxxxxxxxxxxxxx, ETCUSD, 174.33776, 5.73599, "limit") failed: POST https://api.bitfinex.com/v1/order/new: 400 Invalid order price precision (5 sig figures limit)

diff --git a/v1/orders.go b/v1/orders.go
index a26f5ec..2c4f135 100644
--- a/v1/orders.go
+++ b/v1/orders.go
@@ -86,8 +86,8 @@ func (s *OrderService) Create(symbol string, amount float64, price float64, orde

payload := map[string]interface{}{
"symbol": symbol,
"amount": strconv.FormatFloat(amount, 'f', -1, 32),
"price": strconv.FormatFloat(price, 'f', -1, 32),

"side": side,
"type": orderType,
"exchange": "bitfinex",

change to ====>>>>
"amount": strconv.FormatFloat(amount, 'g', 5, 32),
"price": strconv.FormatFloat(price, 'g', 5, 32),

dependencie error with go get

you can avoid some dependencie errors by also doing:
go get github.com/bitfinexcom/bitfinex-api-go**/v1**

otherwise you will get dependencie errors during compiling

Maybe this could be avoided somehow?

Fix type errors of v2 public examples

https://github.com/bitfinexcom/bitfinex-api-go/blob/master/examples/v2/ws-book/main.go#L20
https://github.com/bitfinexcom/bitfinex-api-go/blob/master/examples/v2/ws-book/main.go#L24

The lines above causes he following errors:

./x.go:20: cannot use func literal (type func(context.Context, interface {})) as type bitfinex.handlerT in argument to c.Websocket.AttachEventHandler
./x.go:24: cannot use func literal (type func(context.Context, interface {})) as type bitfinex.handlerT in argument to c.Websocket.AttachPublicHandler

Client stops receiving data

I am running go 1.8 on Ubuntu 16.10.

I have created a client that is basically a copy of the ws-book example, but on top of printing the received data for debug from the subscribed channels, it sends the data out through a zmq socket.

The problem I am having is that the feed stops receiving data. The program does not end or segfaults, it keeps running but not more data comes in, while I can see in the bitfinex webpage that trades are happening in the pairs the channel is subscribed to.

I have taken a quick look at the code and have not found a way to set a reconnect variable (in case the websocket was not reconnecting) or any way to know if the websocket has disconnected for whatever reason (apart from the ending error coming from c.WebSocket.Subscribe() ).

Am I correct if I assume that the websocket will try to reconnect automatically if a disconnection occurs? How can I find out what is happening with the websocket to find out the reason the program stops receiving data?

Wallet-Transfer should be POST

In v1/wallet.go the Transfer-function should do a POST request instead of a GET, i.e. req, err := c.client.newAuthenticatedRequest("POST", "transfer", payload).

v2: Don't launch handlers in a goroutine

Websocket responses should not be launched in a goroutine (https://github.com/bitfinexcom/bitfinex-api-go/blob/master/v2/websocket_service.go#L269). This can cause race conditions if 2 messages for the same item come in at near the same time.

For example lets say you're subscribed to the order books channel, and someone creates an order, but then immediately deletes it. This is going to cause 2 messages back to back. If the application is trying to keep track of the order book, it might end up processing the delete before the create, which will result in an order being added to the local order book that shouldn't have been.

If the goal is to keep the websocket reader from blocking, a buffered chan should be used instead (though this might introduce different issues). However I think calling the handler synchronously is perfectly fine. If the consumer wants to implement a buffered chan, they can.

Nonce bug

I have corrected the Nonce issue with the fix from #32 and the values seem correct but the error 400 Nonce is too small doesn't stop.

I guessed that the counter linked to the API key was too high and I try some very big values and a new key but there is no changes.

v2: Don't require consumer to do type conversions

The v2 client unmarshals a lot of things into generic types. For example public websockets get unmarshalled into things like [][]float64, or timestamps get unmarshalled into int64 as milliseconds.

This requires the consumer to do a lot of work with the data. For the [][]float64 they have to know which indices correspond to which fields, then convert to the appropriate unit. For the times they have to convert to a native time.Time type, etc. This is work that the library should be doing, not the client. The consumer of the library shouldn't need to go look up the wire protocol to determine how to handle the data being returned by the library.
The library should instead pass the handlers structs which are representative of the response object. And types should be converted to useful go types instead of wire types (int64 -> time.Time).

v2: REST Codebase doesn't send API Key/Signature headers

Been reading for an hour trying to find in the codebase in the REST where bfx-nonce, bfx-apikey, and bfx-signature are set. Simple grep of "apikey" reveals no results. So there's no code sending API credentials, which means the example client provided fails to execute.

Support HTTP timeouts

Preferably, this is done by allowing the user to provide it's own HTTP client instead of using the http.DefaultClient.

I realize that you heavily rely on the httpDo method for testing, but it's not very good design to hard-code the HTTP client there.

Change API endpoints

@erubboli please make sure that all URLs match

wss://api.bitfinex.com/ws/ for websocket v1
wss://api.bitfinex.com/ws/2 for websocket v2
wss://api.bitfinex.com/v1/... for rest v1
wss://api.bitfinex.com/v2/... for rest v2

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.