Skip to content
This repository has been archived by the owner on Jun 22, 2020. It is now read-only.

implement hubi exchange #1199

Merged
merged 3 commits into from Jan 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -209,6 +209,7 @@ Or install it yourself as:
| HitBTC | Y | | | | Y | Y | hitbtc |
| Hotbit | Y | N | N | | Y | Y | hotbit |
| HPX | Y | Y | Y | | Y | | hpx |
| Hubi | Y | | | | Y | | hubi |
| Huobi | Y | | | | Y | Y | huobi |
| Ice3x | Y | Y | Y | | Y | | ice3x |
| Idax | Y | N | N | | Y | Y | idax |
Expand Down
12 changes: 12 additions & 0 deletions lib/cryptoexchange/exchanges/hubi/market.rb
@@ -0,0 +1,12 @@
module Cryptoexchange::Exchanges
module Hubi
class Market < Cryptoexchange::Models::Market
NAME = 'hubi'
API_URL = 'https://www.hubi.com/api/v1'

def self.trade_page_url(args={})
"https://www.hubi.com/#/exchange/#{args[:base]}_#{args[:target]}"
end
end
end
end
49 changes: 49 additions & 0 deletions lib/cryptoexchange/exchanges/hubi/services/market.rb
@@ -0,0 +1,49 @@
require 'bigdecimal'

module Cryptoexchange::Exchanges
module Hubi
module Services
class Market < Cryptoexchange::Services::Market
class << self
def supports_individual_ticker_query?
false
end
end

def fetch
output = super ticker_url
adapt_all(output)
end

def ticker_url
"#{Cryptoexchange::Exchanges::Hubi::Market::API_URL}/allticker"
end

def adapt_all(output)
timestamp = output['date']
output['ticker'].map do |output|
adapt(output, timestamp)
end
end

def adapt(output, timestamp)
base, target = output['symbol'].split('_')
ticker = Cryptoexchange::Models::Ticker.new
ticker.base = base
ticker.target = target
ticker.market = Hubi::Market::NAME
ticker.last = NumericHelper.to_d(output['last'])
ticker.volume = NumericHelper.to_d(output['vol'])
ticker.bid = NumericHelper.to_d(output['buy'])
ticker.ask = NumericHelper.to_d(output['sell'])
ticker.low = NumericHelper.to_d(output['low'])
ticker.high = NumericHelper.to_d(output['high'])
ticker.change = NumericHelper.to_d(output['change'])
ticker.timestamp = NumericHelper.to_d(timestamp / 1000)
ticker.payload = output
ticker
end
end
end
end
end
25 changes: 25 additions & 0 deletions lib/cryptoexchange/exchanges/hubi/services/pairs.rb
@@ -0,0 +1,25 @@
module Cryptoexchange::Exchanges
module Hubi
module Services
class Pairs < Cryptoexchange::Services::Pairs
PAIRS_URL = "#{Cryptoexchange::Exchanges::Hubi::Market::API_URL}/allticker"

def fetch
output = super
adapt(output)
end

def adapt(output)
output['ticker'].map do |pair|
base, target = pair['symbol'].split('_')
Cryptoexchange::Models::MarketPair.new(
base: base,
target: target,
market: Hubi::Market::NAME
)
end
end
end
end
end
end

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 42 additions & 0 deletions spec/exchanges/hubi/integration/market_spec.rb
@@ -0,0 +1,42 @@
require 'spec_helper'

RSpec.describe 'Hubi integration specs' do
let(:client) { Cryptoexchange::Client.new }
let(:btc_usdt_pair) { Cryptoexchange::Models::MarketPair.new(base: 'BTC', target: 'USDT', market: 'Hubi') }
let(:market) { 'hubi' }

it 'fetch pairs' do
pairs = client.pairs('hubi')
expect(pairs).not_to be_empty

pair = pairs.first
expect(pair.base).to_not be nil
expect(pair.target).to_not be nil
expect(pair.market).to eq 'hubi'
end

it 'fetch ticker' do
ticker = client.ticker(btc_usdt_pair)

expect(ticker.base).to eq 'BTC'
expect(ticker.target).to eq 'USDT'
expect(ticker.market).to eq 'hubi'

expect(ticker.bid).to be_a Numeric
expect(ticker.high).to be_a Numeric
expect(ticker.last).to be_a Numeric
expect(ticker.low).to be_a Numeric
expect(ticker.ask).to be_a Numeric
expect(ticker.change).to be_a Numeric
expect(ticker.volume).to be_a Numeric

expect(ticker.timestamp).to be_a Numeric
expect(2000..Date.today.year).to include(Time.at(ticker.timestamp).year)
expect(ticker.payload).to_not be nil
end

it 'give trade url' do
trade_page_url = client.trade_page_url market, base: btc_usdt_pair.base, target: btc_usdt_pair.target
expect(trade_page_url).to eq "https://www.hubi.com/#/exchange/BTC_USDT"
end
end
6 changes: 6 additions & 0 deletions spec/exchanges/hubi/market_spec.rb
@@ -0,0 +1,6 @@
require 'spec_helper'

RSpec.describe Cryptoexchange::Exchanges::Hubi::Market do
it { expect(described_class::NAME).to eq 'hubi' }
it { expect(described_class::API_URL).to eq 'https://www.hubi.com/api/v1' }
end