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

Commit

Permalink
Merge pull request #164 from weh/feature/litebiteu
Browse files Browse the repository at this point in the history
Implement LiteBit.eu Ticker
  • Loading branch information
tmlee authored Oct 18, 2017
2 parents 8d26e3d + 36dc467 commit 5a29d74
Show file tree
Hide file tree
Showing 8 changed files with 248 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ Or install it yourself as:
| Kraken | Y | | | | Y |
| LakeBTC | Y | | | | Y |
| Liqui | Y | | | | Y |
| LiteBit.eu | Y | | | | Y |
| Livecoin | Y | | | | Y |
| Luno | Y | | | | Y |
| MercadoBitcoin | Y | | | | User-Defined|
Expand Down
8 changes: 8 additions & 0 deletions lib/cryptoexchange/exchanges/litebiteu/market.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module Cryptoexchange::Exchanges
module Litebiteu
class Market
NAME = 'litebiteu'
API_URL = 'https://api.litebit.eu'
end
end
end
50 changes: 50 additions & 0 deletions lib/cryptoexchange/exchanges/litebiteu/services/market.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
module Cryptoexchange::Exchanges
module Litebiteu
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::Litebiteu::Market::API_URL}/markets"
end

def adapt_all(output)
fetch_timestamp = DateTime.now.to_time.to_i

output['result'].map do |base, market|
market_pair = Cryptoexchange::Models::MarketPair.new(
base: base.upcase,
target: 'EUR',
market: Bithumb::Market::NAME
)
adapt(market, market_pair, fetch_timestamp)
end
end

def adapt(market, market_pair, fetch_timestamp)
ticker = Cryptoexchange::Models::Ticker.new

ticker.base = market_pair.base
ticker.target = market_pair.target
ticker.market = Litebiteu::Market::NAME
ticker.ask = NumericHelper.to_d(market['buy'])
ticker.bid = NumericHelper.to_d(market['sell'])
ticker.volume = NumericHelper.to_d(market['volume'])
ticker.last = (ticker.ask + ticker.bid) / 2
ticker.timestamp = fetch_timestamp
ticker.payload = market
ticker
end
end
end
end
end
31 changes: 31 additions & 0 deletions lib/cryptoexchange/exchanges/litebiteu/services/pairs.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module Cryptoexchange::Exchanges
module Litebiteu
module Services
class Pairs < Cryptoexchange::Services::Pairs
PAIRS_URL = "#{Cryptoexchange::Exchanges::Litebiteu::Market::API_URL}/markets"

def fetch
output = super
adapt(output)
end

def adapt(output)
market_pairs = []

output['result'].each do |currency, _|

if currency
market_pairs << Cryptoexchange::Models::MarketPair.new(
base: currency.upcase,
target: 'EUR',
market: Litebiteu::Market::NAME
)
end
end

market_pairs
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.

32 changes: 32 additions & 0 deletions spec/exchanges/litebiteu/integration/market_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
require 'spec_helper'

RSpec.describe 'Litebiteu integration specs' do
client = Cryptoexchange::Client.new

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

pair = pairs.first
expect(pair.base).to eq 'BTC'
expect(pair.target).to eq 'EUR'
expect(pair.market).to eq 'litebiteu'
end

it 'fetch ticker' do
btc_eur_pair = Cryptoexchange::Models::MarketPair.new(base: 'BTC', target: 'EUR', market: 'litebiteu')
ticker = client.ticker(btc_eur_pair)

expect(ticker.base).to eq 'BTC'
expect(ticker.target).to eq 'EUR'
expect(ticker.market).to eq 'litebiteu'

expect(ticker.bid).to be_a Numeric
expect(ticker.ask).to be_a Numeric
expect(ticker.volume).to be_a Numeric
expect(ticker.last).to be_a Numeric
expect(ticker.timestamp).to be_a Numeric
expect(DateTime.strptime(ticker.timestamp.to_s, '%s').year).to eq Date.today.year
expect(ticker.payload).to_not be nil
end
end
6 changes: 6 additions & 0 deletions spec/exchanges/litebiteu/market_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
require 'spec_helper'

RSpec.describe Cryptoexchange::Exchanges::Litebiteu::Market do
it { expect(described_class::NAME).to eq 'litebiteu' }
it { expect(described_class::API_URL).to eq 'https://api.litebit.eu' }
end

0 comments on commit 5a29d74

Please sign in to comment.