bitfinexcom / bitfinex-api-rb

BITFINEX Ruby trading API - Bitcoin, Litecoin, and Ether exchange
https://www.bitfinex.com/
MIT License
81 stars 94 forks source link

FundingTicker not working #86

Closed larry82 closed 5 years ago

larry82 commented 5 years ago

Issue type

face commented 5 years ago

Hi @larry82,

Are you using the pub-api URL? The following works for me:

require 'rubygems'
require 'bitfinex'

client = Bitfinex::WSv2.new({
  url:  'wss://api-pub.bitfinex.com/ws/2',
  transform: true
})

client.on(:ticker) do |symbol, msg|
  p "recv ticker message for symbol #{symbol}"
  p msg.serialize.join('|')

end

client.on(:open) do
  client.subscribe_ticker('fUSD')
end

client.open!

If you are still having issues, please share a code snippet that reproduces the issue.

Thanks

larry82 commented 5 years ago

I, [2019-07-07T20:26:54.711699 #37837] INFO -- ws2: recv [179343,[0.0007134986301369863,0.000645,30,5003639.261537059,0.00063735,2,196897.94456750999,-0.0000024,-0.0034,0.000699,130755027.60711361,0.00071253,0.00000191,null,null,184654802.74329743]] "recv ticker message for symbol fUSD" "|||||||||||||"

This is what I got after using your code

I'm using rails and this is my gem file

`source 'https://rubygems.org' git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby '2.6.3'

gem 'john_hancock'

gem 'bitfinex-rb', :require => "bitfinex"

gem "chartkick"

gem 'rails', '~> 6.0.0.rc1'

gem 'pg'

gem 'puma', '~> 3.12'

gem 'sass-rails', '~> 5'

gem 'webpacker', '~> 4.0'

gem 'turbolinks', '~> 5'

gem 'jbuilder', '~> 2.5'

gem 'redis', '~> 4.0'

gem 'bootsnap', '>= 1.4.2', require: false

group :development, :test do

gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] gem 'pry-rails' gem 'annotate' gem 'brakeman' gem 'bundler-audit' gem 'letter_opener_web', '~> 1.3', '>= 1.3.4' end

group :development do

gem 'web-console', '>= 3.3.0' gem 'listen', '>= 3.0.5', '< 3.2'

gem 'spring' gem 'spring-watcher-listen', '~> 2.0.0' end

group :test do

gem 'capybara', '>= 2.15' gem 'selenium-webdriver'

gem 'webdrivers' end

gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

gem 'jumpstart', path: 'lib/jumpstart'

gem 'administrate', github: 'excid3/administrate', branch: 'jumpstart' #'~> 0.10.0' gem 'attr_encrypted', '~> 3.1' gem 'devise', '~> 4.6.0' gem 'devise_invitable', '~> 2.0' gem 'devise_masquerade', '~> 0.6.4' gem 'image_processing', '~> 1.2' gem 'inline_svg', '~> 1.3', '>= 1.3.1' gem 'local_time', '~> 2.1' gem 'name_of_person', '~> 1.0' gem 'pagy', '~> 3.0' gem 'pay', '~> 1.0.0.beta5' gem 'receipts', '~> 0.2.2' gem 'turbolinks_render', '~> 0.9.12'

gem 'omniauth' gem 'strong_migrations' gem 'whenever', require: false

if File.exists?("config/jumpstart/Gemfile") eval_gemfile "config/jumpstart/Gemfile" end

`

larry82 commented 5 years ago

I set the "transform" option to false and then the msg can be shown normally

client = Bitfinex::WSv2.new({
      url:  'wss://api-pub.bitfinex.com/ws/2',
      transform: false
    })

    client.on(:ticker) do |symbol, msg|
      p "recv ticker message for symbol #{symbol}"
      p msg
    end

    client.on(:open) do
      client.subscribe_ticker('fUSD')
    end

    client.open!
"recv ticker message for symbol fUSD"
[0.000713345205479452, 0.000645, 30, 6087698.5942001995, 0.00062886, 2, 429636.50682435, -0.00010726, -0.1527, 0.00059522, 132211775.44697618, 0.00071253, 1.91e-06, nil, nil, 186125929.93047523]
face commented 5 years ago

Ok so it looks like it is working for you now. If I'm mistaken I will re-open the issue. Thank you.