Skip to content
This repository has been archived by the owner on Feb 15, 2022. It is now read-only.

Bitfinex WebSockets API + Fix postonly not triggering re-buy #458

Merged
merged 27 commits into from
Aug 14, 2017
Merged
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
7dda2d5
Really re-order on "post only" error
crubb Jul 28, 2017
3458b7c
Initial commit to switch bitfinex to websockets
crubb Jul 28, 2017
9d0b78f
Select pair on first getTrade()
crubb Aug 8, 2017
43e720a
Fixed bitfinex buy and sell from commandline
crubb Aug 9, 2017
d62946a
Bitfinex: Trigger calc of wallet balances on getBalance over websocke…
crubb Aug 9, 2017
fb0fd3f
Bitfinex: Removed duplicate definition of symbol
crubb Aug 9, 2017
00d29b9
Bitfinex: Now using only one websockets connection
crubb Aug 9, 2017
b917509
Bitfinex WS: Better error handling on connect/auth/sending messages
crubb Aug 9, 2017
a39ef82
Bitfinex WS: Further improving retries and error handling
crubb Aug 10, 2017
1d142dc
Bitfinex WS: Not directly calling the websockets part of the bitfinex…
crubb Aug 10, 2017
af971ef
Fix bug with preroll when 0 volume (#464)
cmroche Aug 11, 2017
f68c6b6
Bitfinex WS: Fixed wallet recalc when asset or currency are 0
crubb Aug 11, 2017
199758e
Really re-order on "post only" error
crubb Jul 28, 2017
9c15ea8
Initial commit to switch bitfinex to websockets
crubb Jul 28, 2017
016b60b
Select pair on first getTrade()
crubb Aug 8, 2017
cfc7c78
Fixed bitfinex buy and sell from commandline
crubb Aug 9, 2017
9121fb7
Bitfinex: Trigger calc of wallet balances on getBalance over websocke…
crubb Aug 9, 2017
9a0f484
Bitfinex: Removed duplicate definition of symbol
crubb Aug 9, 2017
68f84de
Bitfinex: Now using only one websockets connection
crubb Aug 9, 2017
88efa70
Bitfinex WS: Better error handling on connect/auth/sending messages
crubb Aug 9, 2017
2268101
Bitfinex WS: Further improving retries and error handling
crubb Aug 10, 2017
a7b88c0
Bitfinex WS: Not directly calling the websockets part of the bitfinex…
crubb Aug 10, 2017
36b9575
Bitfinex WS: Fixed wallet recalc when asset or currency are 0
crubb Aug 11, 2017
4cdc4ad
Merge branch 'crubb/bitfinex.ws' of github.com:crubb/zenbot into crub…
crubb Aug 11, 2017
667fed1
Bitfinex WS: New reconnect approach, honor "INSUFFICIENT MARGIN"
crubb Aug 13, 2017
88b84d7
Bitfinex WS: Missing )
crubb Aug 13, 2017
7822028
Bitfinex WS: Remove debug logging on "close"
crubb Aug 14, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion extensions/exchanges/bitfinex/exchange.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,17 @@ module.exports = function container (get, set, clear) {
}

function authedClientWs () {
if (!public_client_ws) {
publicClientWs()

console.warn(('Warning: Not yet connected to public websockets, waiting 1s for a connection').yellow)
setTimeout(function () {
if (!authedClientWs) { authed_client_ws = authedClientWs() }
}, 1000)

return null
}

if (!authed_client_ws) {
if (!c.bitfinex || !c.bitfinex.key || c.bitfinex.key === 'YOUR-API-KEY') {
throw new Error('please configure your Bitfinex credentials in ' + path.resolve(__dirname, 'conf.js'))
Expand Down Expand Up @@ -248,7 +259,7 @@ module.exports = function container (get, set, clear) {
},

getTrades: function (opts, cb) {
pair = joinProduct(opts.product_id)
if (!pair) { pair = joinProduct(opts.product_id) }

if (!public_client_ws) { publicClientWs() }

Expand Down Expand Up @@ -295,6 +306,8 @@ module.exports = function container (get, set, clear) {
},

getBalance: function (opts, cb) {
if (!pair) { pair = joinProduct(opts.asset + '-' + opts.currency) }

if (!authed_client_ws) { authedClientWs() }
if (Object.keys(ws_balance).length === 0) { return retry('getBalance', opts, cb) }

Expand Down Expand Up @@ -330,6 +343,9 @@ module.exports = function container (get, set, clear) {
},

trade: function (action, opts, cb) {
if (!pair) { pair = joinProduct(opts.product_id) }
var symbol = 't' + pair

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate in line 352

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a duplicate. The symbol on trade needs a 't' prefix, and in case the trade function is ever called as the first function, we need to know the pair and set it globally.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please pay more attention:

trade: function (action, opts, cb) {
if (!pair) { pair = joinProduct(opts.product_id) }
var symbol = 't' + pair //line 347
client = authedClientWs();
var cid = Math.round(((new Date()).getTime()).toString() * Math.random())
var symbol = 't' + joinProduct(opts.product_id) //line 352
var amount = action === 'buy' ? opts.size : opts.size * -1

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, sorry, misunderstood your comment.

client = authedClientWs();

var cid = Math.round(((new Date()).getTime()).toString() * Math.random())
Expand Down