create account

Coingecko Task Request: Public Websocket API Connections for Binance by utopian.tasks

View this thread on: hive.blogpeakd.comecency.com
· @utopian.tasks ·
$87.88
Coingecko Task Request: Public Websocket API Connections for Binance
### Utopian for CoinGecko:
Utopian.io is running this task request on behalf of [CoinGecko.com](https://coingecko.com)

<center>
https://steemitimages.com/0x0/https://cdn.steemitimages.com/DQmb1qRjsYXwawCHsjhwehMUDrQe9xZhc5iD8gegQMHuNuf/utopian%20coingecko%20collab.png
</center>

#### GitHub Repository
https://github.com/coingecko/cryptoexchange

#### Project Background
Cryptoexchange is a rubygem that allows Ruby developers to interact with over 240+ cryptocurrency exchange market data APIs in a single library. This rubygem is used to power [CoinGecko](https://www.coingecko.com). It is open source under the terms of the MIT License.


#### Task Specification
For the existing HTTP API, this rubygem has established a pretty good abstraction which allows developers to easily contribute new exchanges.

The **websocket API feature**, however, is a new addition to this rubygem. As such, we are still figuring out the best abstraction/structure.

Below pull request is the initial proof-of-concept for Bitfinex connection. Please use it as general reference in creating the Binance websocket API: 
https://github.com/coingecko/cryptoexchange/pull/1008 


#### Deliverables
We are looking for candidate(s) to complete the following tasks:
- [ ] Implement **public websocket API** connections for [Binance](https://github.com/binance-exchange/binance-official-api-docs/blob/master/web-socket-streams.md) (Ticker, OrderBook, Trade)
- [ ] Suggest ways to improve upon the rubygem websocket connection design. (See *notes below)
- [ ] Suggest ways to spec/test external websocket API connection. (See *notes below)

#### *Notes
- The Bitfinex websocket API requires us to make only ONE connection for ONE trading pair. For example, only one websocket connection of BTC/USDT is needed in order to obtain stream data corresponding to that pairing. As such, the existing structure in place for Bitfinex leverages on Threads in order to handle multiple streams.
- There may be a case where some websocket API (such as Binance) require only ONE connection for MULTIPLE trading pairs. You may need to introduce additional abstractions to handle this situation.
- The HTTP API implementation of this rubygem uses [VCR](https://github.com/vcr/vcr) in order to mock API responses to ensure we can run an end-to-end integration test. VCR does not appear to work with websocket. We are considering manually mocking the websocket response but this can turn out to be unscalable when response changes.
- Feel free to suggest ways to streamline this abstraction.

#### Additional Notes for Binance Implementation
We have looked into the [Binance websocket API documentation](https://github.com/binance-exchange/binance-official-api-docs/blob/master/web-socket-streams.md).

Here is a code you can use to get started making websocket connection for testing purposes in ruby console.

```
EM.run do
  ws = WebSocket::EventMachine::Client.connect(uri: 'wss://stream.binance.com:9443/ws/bnbbtc@ticker')

  ws.onopen do
  end

  ws.onmessage do |message, _|
    begin
      message = JSON.parse(message)
      puts message
    rescue Exception => e
      puts e
    end
  end

  ws.onclose do
    puts "Close!"
  end
end
```

Binance websocket also allows multiple streams. This allows us to maintain less websocket connections (if possible just one)

```
EM.run do
  ws = WebSocket::EventMachine::Client.connect(uri: 'wss://stream.binance.com:9443/stream?streams=bnbbtc@miniTicker/ethbtc@miniTicker/ethbtc@miniTicker')

  ws.onopen do
  end

  ws.onmessage do |message, _|
    begin
      message = JSON.parse(message)
      puts message
    rescue Exception => e
      puts e
    end
  end

  ws.onclose do
    puts "Close!"
  end
end
```

`!miniTicker@arr` seems to be an ideal candidate for Ticker data as stated in https://github.com/binance-exchange/binance-official-api-docs/blob/master/web-socket-streams.md#all-market-mini-tickers-stream

The following channels on Binance correspond to the data we want to capture:
- !miniTicker@arr OR @ticker OR @miniTicker (Ticker)
- @depth (OrderBook)
- @trade (Trade)

#### How to get started?

1. Navigate to the repository on Github https://github.com/coingecko/cryptoexchange
2. Be sure to check out the README on its [usages](https://github.com/coingecko/cryptoexchange) to familiarize yourself with the gem and [contributing guide](https://github.com/coingecko/cryptoexchange/wiki/Implementing-a-New-Exchange-(Websocket-API)).
3. https://github.com/coingecko/cryptoexchange/wiki/Implementing-a-New-Exchange-(Websocket-API) will likely be useful to you to get started.
4. When you begin work, we suggest creating a Pull Request with a WIP headline so we can commence discussion there.


#### Deadline
2 weeks. Set to start upon candidate selection.

#### Communication
Please register your interest at https://discord.gg/pKGV9sp, CoinGecko's official Discord server in the "utopian-io" channel.

You may contact us directly for further information via email at hello@coingecko.com or in our Discord developer discussion hub.

#### Github
https://github.com/coingecko

#### Rewards Information
Rewards generated by this task request will be sent as liquid STEEM to the task solver once the task is completed, as decided by the project owner.

The task will be considered considered completed after it has been merged by CoinGecko developement team and when the solver published a Utopian post, explaining what they did in order to solve the task.
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 62 others
properties (23)
authorutopian.tasks
permlinkcoingecko-task-request-public-websocket-api-connections-for-binance
categoryutopian-io
json_metadata{"tags":["utopian-io","task-development","coingecko","rubygem","websocket"],"users":["ticker","miniticker","depth","trade"],"image":["https://steemitimages.com/0x0/https://cdn.steemitimages.com/DQmb1qRjsYXwawCHsjhwehMUDrQe9xZhc5iD8gegQMHuNuf/utopian%20coingecko%20collab.png"],"links":["https://coingecko.com","https://github.com/coingecko/cryptoexchange","https://www.coingecko.com","https://github.com/coingecko/cryptoexchange/pull/1008","https://github.com/binance-exchange/binance-official-api-docs/blob/master/web-socket-streams.md","https://github.com/vcr/vcr","https://github.com/binance-exchange/binance-official-api-docs/blob/master/web-socket-streams.md#all-market-mini-tickers-stream","https://github.com/coingecko/cryptoexchange/wiki/Implementing-a-New-Exchange-(Websocket-API)","https://github.com/coingecko/cryptoexchange/wiki/Implementing-a-New-Exchange-","https://discord.gg/pKGV9sp","https://github.com/coingecko"],"app":"steemit/0.1","format":"markdown"}
created2018-11-30 13:39:15
last_update2018-11-30 13:39:15
depth0
children1
last_payout2018-12-07 13:39:15
cashout_time1969-12-31 23:59:59
total_payout_value66.776 HBD
curator_payout_value21.102 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length5,480
author_reputation38,345,857,993,507
root_title"Coingecko Task Request: Public Websocket API Connections for Binance"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd0
post_id76,149,054
net_rshares144,656,573,021,430
author_curate_reward""
vote details (126)
@mediawizards ·
Reading about it.....😇 

Posted using [Partiko Android](https://steemit.com/@partiko-android)
properties (22)
authormediawizards
permlinkmediawizards-re-utopian-tasks-coingecko-task-request-public-websocket-api-connections-for-binance-20181130t155139995z
categoryutopian-io
json_metadata{"app":"partiko"}
created2018-11-30 15:51:39
last_update2018-11-30 15:51:39
depth1
children0
last_payout2018-12-07 15:51:39
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length93
author_reputation22,927,285,597,690
root_title"Coingecko Task Request: Public Websocket API Connections for Binance"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id76,155,382
net_rshares0