Class: Cryptoexchange::Exchanges::Cybex::Services::Pairs

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

Constant Summary collapse

PAIRS_URL =
"#{Cryptoexchange::Exchanges::Cybex::Market::API_URL}"
HTTP_METHOD =
'POST'
POST_PARAMS =
{ "jsonrpc": "2.0", "method": "list_assets", "params": ["A", 100], "id": 1 }
OMITTED_SYMBOLS =
['ANGEL', 'JADE', 'JAMES']
MAIN_TARGET_SYMBOLS =
['USDT', 'BTC', 'ETH', 'CYB']

Constants inherited from Services::Pairs

Services::Pairs::MARKET

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(pair_list) ⇒ Object



33
34
35
36
37
38
39
40
41
42
# File 'lib/cryptoexchange/exchanges/cybex/services/pairs.rb', line 33

def adapt(pair_list)
  pair_list.map do |pair|
    base, target = pair
    Cryptoexchange::Models::MarketPair.new(
      base:   base,
      target: target,
      market: Cybex::Market::NAME
    )
  end
end

#fetchObject



12
13
14
15
16
# File 'lib/cryptoexchange/exchanges/cybex/services/pairs.rb', line 12

def fetch
  output    = super
  pair_list = list_all_combinations(output)
  adapt(pair_list)
end

#list_all_combinations(output) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/cryptoexchange/exchanges/cybex/services/pairs.rb', line 18

def list_all_combinations(output)
  pairs_list = []
  symbols    = output['result'].map { |asset| asset['symbol'] }
  symbols    = symbols - OMITTED_SYMBOLS
  symbols.delete_if { |sym| !/\A(#{Cryptoexchange::Exchanges::Cybex::Market::OMITTED_GATEWAY}\.)/.match(sym).nil? }
  symbols      = symbols.map { |a| a.split('.').last }
  symbol_pairs = symbols.product(MAIN_TARGET_SYMBOLS)
  symbol_pairs.map do |pair|
    next if pair[0] == pair[1] || pair[0] == 'USDT'
    next if /(BTC|ETH|CYB)/.match(pair[0]) && /(BTC|ETH|CYB)/.match(pair[1])
    pairs_list << pair
  end
  pairs_list
end