Connect to server in Ruby
New here? Learn about Bountify and follow @bountify to get notified of new bounties! x

Looking for a way to connect to the API using Ruby.

Source code in Ruby 1.9.3 that does the following:
1. Create connection
2. Send message
3. Receive and parse message

awarded to dierbro

Crowdsource coding tasks.

1 Solution

Winning solution

Make sure to use my patched version of and replace YOUR_AUTH_KEY and YOUR_USER_ID


source ''
gem 'socketio-client', github: "dierbro/"

wrapper.rb (implements the example on the ICBIT api documentation)

require 'SocketIO'
require 'json'


client = SocketIO.connect("{AuthKey}&UserId=#{UserId}") do
    after_start do
      emit('message', { op: 'subscribe', channel: 'orderbook_BUH3' })

    on_json_message do |message| 
      puts JSON.parse(message)

Install process

mkdir icbit_api
cd icbit_api
create Gemfile and paste content
create wrapper.rb, paste the content and replace YOUR_AUTH_KEY  YOUR_USER_ID
bundle install
bundle exec ruby wrapper.rb

I tested the code with bundler 1.2.4 and ruby 1.9.3

Doesn't work on my machine. What is the install process? What gems are required? I created the Gemfile, and installed bundler. bundle throws error: The source :rubygems is deprecated because HTTP requests are insecure. Please change your source to '' if possible, or 'http://ru... Fetching gem metadata from There was a LoadError while evaluating socketio-client.gemspec: cannot load such file -- rest_client from /socketio-client.gemspec:3:in `' Does it try to require a relative path
georgeu2000 almost 8 years ago
Error continued: Does it try to require a relative path? That's been removed in Ruby 1.9.
georgeu2000 almost 8 years ago
check the updated solution above
dierbro almost 8 years ago
It worked. FWIW, I needed to install rest-client. And it only works using bundle exec ruby (not ruby). Thank you!
georgeu2000 almost 8 years ago
How do you get the message out of the SocketIO.connect do loop?
georgeu2000 almost 8 years ago