Class: Cryptoexchange::Exchanges::Binance::Services::Pairs

Inherits:
Services::Pairs
  • Object
show all
Defined in:
lib/cryptoexchange/exchanges/binance/services/pairs.rb

Constant Summary collapse

PAIRS_URL =
"#{Cryptoexchange::Exchanges::Binance::Market::API_URL}/ticker/allPrices"
TARGETS =
['BTC', 'ETH', 'BNB', 'USDT']

Constants inherited from Services::Pairs

Services::Pairs::HTTP_METHOD, Services::Pairs::MARKET, Services::Pairs::POST_PARAMS

Instance Method Summary collapse

Methods inherited from Services::Pairs

#default_override_exist?, #default_override_path, #exchange_class, #fetch_via_api, #fetch_via_api_using_post, #fetch_via_override, #http_get, #http_post, #user_override_exist?, #user_override_path

Instance Method Details

#adapt(output) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/cryptoexchange/exchanges/binance/services/pairs.rb', line 13

def adapt(output)
  market_pairs = []
  output.each do |pair|
    symbol = pair['symbol']
    base, target = strip_pairs(symbol)
    next unless base && target
    market_pairs << Cryptoexchange::Models::MarketPair.new(
                      base: base,
                      target: target,
                      market: Binance::Market::NAME
                    )
  end
  market_pairs
end

#fetchObject



8
9
10
11
# File 'lib/cryptoexchange/exchanges/binance/services/pairs.rb', line 8

def fetch
  output = super
  adapt(output)
end

#strip_pairs(pair_symbol) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/cryptoexchange/exchanges/binance/services/pairs.rb', line 28

def strip_pairs(pair_symbol)
  #Match last 3 or 4 if it hits target
  last_4 = pair_symbol[-4..-1]
  last_3 = pair_symbol[-3..-1]

  if TARGETS.include? last_4
    base = pair_symbol[0..-5]
    target = last_4
  elsif TARGETS.include? last_3
    base = pair_symbol[0..-4]
    target = last_3
  end

  [base, target]
end