Class: Cryptoexchange::Services::Pairs

Inherits:
Object
  • Object
show all
Defined in:
lib/cryptoexchange/services/pairs.rb

Direct Known Subclasses

Exchanges::Abcc::Services::Pairs, Exchanges::Abucoins::Services::Pairs, Exchanges::Acx::Services::Pairs, Exchanges::Aex::Services::Pairs, Exchanges::Airswap::Services::Pairs, Exchanges::Allbit::Services::Pairs, Exchanges::Allcoin::Services::Pairs, Exchanges::Alluma::Services::Pairs, Exchanges::Alterdice::Services::Pairs, Exchanges::Altilly::Services::Pairs, Exchanges::Altmarkets::Services::Pairs, Exchanges::Anx::Services::Pairs, Exchanges::Aphelion::Services::Pairs, Exchanges::Axnet::Services::Pairs, Exchanges::B2bx::Services::Pairs, Exchanges::Bancor::Services::Pairs, Exchanges::Bankera::Services::Pairs, Exchanges::Bcex::Services::Pairs, Exchanges::Bcoin::Services::Pairs, Exchanges::Bgogo::Services::Pairs, Exchanges::Bibox::Services::Pairs, Exchanges::Bigone::Services::Pairs, Exchanges::Bilaxy::Services::Pairs, Exchanges::Binance::Services::Pairs, Exchanges::Bishang::Services::Pairs, Exchanges::Bisq::Services::Pairs, Exchanges::Bit2c::Services::Pairs, Exchanges::BitZ::Services::Pairs, Exchanges::Bitbank::Services::Pairs, Exchanges::Bitbay::Services::Pairs, Exchanges::Bitbegin::Services::Pairs, Exchanges::Bitbns::Services::Pairs, Exchanges::Bitbox::Services::Pairs, Exchanges::BitboxPrivate::Services::Pairs, Exchanges::Bitconnect::Services::Pairs, Exchanges::Bitebtc::Services::Pairs, Exchanges::Bitex::Services::Pairs, Exchanges::Bitexlive::Services::Pairs, Exchanges::Bitfex::Services::Pairs, Exchanges::Bitfinex::Services::Pairs, Exchanges::Bitflyer::Services::Pairs, Exchanges::Bitforex::Services::Pairs, Exchanges::Bithash::Services::Pairs, Exchanges::Bithumb::Services::Pairs, Exchanges::Bitibu::Services::Pairs, Exchanges::Bitinfi::Services::Pairs, Exchanges::Bitinka::Services::Pairs, Exchanges::Bitker::Services::Pairs, Exchanges::Bitkonan::Services::Pairs, Exchanges::Bitkub::Services::Pairs, Exchanges::Bitlish::Services::Pairs, Exchanges::Bitmart::Services::Pairs, Exchanges::Bitmax::Services::Pairs, Exchanges::Bitmex::Services::Pairs, Exchanges::Bitonbay::Services::Pairs, Exchanges::Bitpaction::Services::Pairs, Exchanges::Bitrabbit::Services::Pairs, Exchanges::Bitrue::Services::Pairs, Exchanges::BitsBlockchain::Services::Pairs, Exchanges::Bitsane::Services::Pairs, Exchanges::Bitso::Services::Pairs, Exchanges::Bitstamp::Services::Pairs, Exchanges::Bitsten::Services::Pairs, Exchanges::Bittrex::Services::Pairs, Exchanges::Bkex::Services::Pairs, Exchanges::Bleutrade::Services::Pairs, Exchanges::Blockonix::Services::Pairs, Exchanges::Blokmy::Services::Pairs, Exchanges::Braziliex::Services::Pairs, Exchanges::BtcAlpha::Services::Pairs, Exchanges::BtcExchange::Services::Pairs, Exchanges::BtcTradeUa::Services::Pairs, Exchanges::Btcbox::Services::Pairs, Exchanges::Btcc::Services::Pairs, Exchanges::Btcmarkets::Services::Pairs, Exchanges::Btcsquare::Services::Pairs, Exchanges::Btcturk::Services::Pairs, Exchanges::Bter::Services::Pairs, Exchanges::Buyucoin::Services::Pairs, Exchanges::Bw::Services::Pairs, Exchanges::BxThailand::Services::Pairs, Exchanges::Bytex::Services::Pairs, Exchanges::C2cx::Services::Pairs, Exchanges::CPatex::Services::Pairs, Exchanges::Ccex::Services::Pairs, Exchanges::Cex::Services::Pairs, Exchanges::Cfinex::Services::Pairs, Exchanges::Chaince::Services::Pairs, Exchanges::Chainex::Services::Pairs, Exchanges::Chainrift::Services::Pairs, Exchanges::Chaoex::Services::Pairs, Exchanges::Chbtc::Services::Pairs, Exchanges::Cobinhood::Services::Pairs, Exchanges::Coin2001::Services::Pairs, Exchanges::CoinEgg::Services::Pairs, Exchanges::CoinExchange::Services::Pairs, Exchanges::Coinall::Services::Pairs, Exchanges::Coinasset::Services::Pairs, Exchanges::Coinbe::Services::Pairs, Exchanges::Coinbene::Services::Pairs, Exchanges::Coinchangex::Services::Pairs, Exchanges::Coincheck::Services::Pairs, Exchanges::Coindeal::Services::Pairs, Exchanges::Coindirect::Services::Pairs, Exchanges::Coineal::Services::Pairs, Exchanges::Coinex::Services::Pairs, Exchanges::Coinfalcon::Services::Pairs, Exchanges::Coinfield::Services::Pairs, Exchanges::Coingi::Services::Pairs, Exchanges::Coinhouse::Services::Pairs, Exchanges::Coinhub::Services::Pairs, Exchanges::Coinjar::Services::Pairs, Exchanges::Coinmate::Services::Pairs, Exchanges::Coinmex::Services::Pairs, Exchanges::Coinnest::Services::Pairs, Exchanges::Coinnox::Services::Pairs, Exchanges::Coinone::Services::Pairs, Exchanges::Coinpark::Services::Pairs, Exchanges::Coinplace::Services::Pairs, Exchanges::Coinrail::Services::Pairs, Exchanges::Coinroom::Services::Pairs, Exchanges::CoinsMarkets::Services::Pairs, Exchanges::Coinsbank::Services::Pairs, Exchanges::Coinsbit::Services::Pairs, Exchanges::Coinstock::Services::Pairs, Exchanges::Coinsuper::Services::Pairs, Exchanges::Cointiger::Services::Pairs, Exchanges::Coinut::Services::Pairs, Exchanges::Coinzest::Services::Pairs, Exchanges::Coss::Services::Pairs, Exchanges::Cpdax::Services::Pairs, Exchanges::Credoex::Services::Pairs, Exchanges::Crex24::Services::Pairs, Exchanges::Crxzone::Services::Pairs, Exchanges::Cryptagio::Services::Pairs, Exchanges::Cryptaldash::Services::Pairs, Exchanges::Cryptex::Services::Pairs, Exchanges::CryptoBridge::Services::Pairs, Exchanges::CryptoHub::Services::Pairs, Exchanges::Cryptobulls::Services::Pairs, Exchanges::Cryptology::Services::Pairs, Exchanges::Cryptonit::Services::Pairs, Exchanges::Cryptopia::Services::Pairs, Exchanges::Crytrex::Services::Pairs, Exchanges::Cybex::Services::Pairs, Exchanges::Dakuce::Services::Pairs, Exchanges::Dcoin::Services::Pairs, Exchanges::Ddex::Services::Pairs, Exchanges::Deex::Services::Pairs, Exchanges::Dextop::Services::Pairs, Exchanges::Digifinex::Services::Pairs, Exchanges::Dobitrade::Services::Pairs, Exchanges::Dragonex::Services::Pairs, Exchanges::Dsx::Services::Pairs, Exchanges::Ercdex::Services::Pairs, Exchanges::Escodex::Services::Pairs, Exchanges::EtherDelta::Services::Pairs, Exchanges::Etherflyer::Services::Pairs, Exchanges::Ethex::Services::Pairs, Exchanges::Ethfinex::Services::Pairs, Exchanges::Everbloom::Services::Pairs, Exchanges::Exmo::Services::Pairs, Exchanges::Exrates::Services::Pairs, Exchanges::Extstock::Services::Pairs, Exchanges::Exx::Services::Pairs, Exchanges::F1cx::Services::Pairs, Exchanges::Fatbtc::Services::Pairs, Exchanges::Fcoin::Services::Pairs, Exchanges::Fex::Services::Pairs, Exchanges::FiftyEightCoin::Services::Pairs, Exchanges::Finexbox::Services::Pairs, Exchanges::Fisco::Services::Pairs, Exchanges::Forkdelta::Services::Pairs, Exchanges::Freiexchange::Services::Pairs, Exchanges::Gate::Services::Pairs, Exchanges::Gatecoin::Services::Pairs, Exchanges::Gbx::Services::Pairs, Exchanges::Gdac::Services::Pairs, Exchanges::Gdax::Services::Pairs, Exchanges::Gemini::Services::Pairs, Exchanges::Getbtc::Services::Pairs, Exchanges::Gobaba::Services::Pairs, Exchanges::Golix::Services::Pairs, Exchanges::Gopax::Services::Pairs, Exchanges::Graviex::Services::Pairs, Exchanges::Hadax::Services::Pairs, Exchanges::HbTop::Services::Pairs, Exchanges::Hikenex::Services::Pairs, Exchanges::Hitbtc::Services::Pairs, Exchanges::Hotbit::Services::Pairs, Exchanges::Hpx::Services::Pairs, Exchanges::Huobi::Services::Pairs, Exchanges::Ice3x::Services::Pairs, Exchanges::Idax::Services::Pairs, Exchanges::Idcm::Services::Pairs, Exchanges::Idex::Services::Pairs, Exchanges::Incorex::Services::Pairs, Exchanges::Indodax::Services::Pairs, Exchanges::InfinityCoin::Services::Pairs, Exchanges::Instantbitex::Services::Pairs, Exchanges::Iqfinex::Services::Pairs, Exchanges::Ironex::Services::Pairs, Exchanges::Itbit::Services::Pairs, Exchanges::Jex::Services::Pairs, Exchanges::Joyso::Services::Pairs, Exchanges::Jubi::Services::Pairs, Exchanges::KKex::Services::Pairs, Exchanges::Kairex::Services::Pairs, Exchanges::Kkcoin::Services::Pairs, Exchanges::Koinex::Services::Pairs, Exchanges::Koinok::Services::Pairs, Exchanges::Korbit::Services::Pairs, Exchanges::Kraken::Services::Pairs, Exchanges::Kryptono::Services::Pairs, Exchanges::Kucoin::Services::Pairs, Exchanges::Kuna::Services::Pairs, Exchanges::KyberNetwork::Services::Pairs, Exchanges::Lakebtc::Services::Pairs, Exchanges::Latoken::Services::Pairs, Exchanges::Lbank::Services::Pairs, Exchanges::Letsdocoinz::Services::Pairs, Exchanges::Liqui::Services::Pairs, Exchanges::Litebiteu::Services::Pairs, Exchanges::Livecoin::Services::Pairs, Exchanges::Luno::Services::Pairs, Exchanges::Lykke::Services::Pairs, Exchanges::Maplechange::Services::Pairs, Exchanges::MaxMaicoin::Services::Pairs, Exchanges::MercadoBitcoin::Services::Pairs, Exchanges::Mercatox::Services::Pairs, Exchanges::Myspeedtrade::Services::Pairs, Exchanges::Nanex::Services::Pairs, Exchanges::NanuExchange::Services::Pairs, Exchanges::Nebula::Services::Pairs, Exchanges::Negociecoins::Services::Pairs, Exchanges::Neraex::Services::Pairs, Exchanges::Newdex::Services::Pairs, Exchanges::Ninecoin::Services::Pairs, Exchanges::Nlexch::Services::Pairs, Exchanges::Novadax::Services::Pairs, Exchanges::Novadex::Services::Pairs, Exchanges::Novaexchange::Services::Pairs, Exchanges::Nusax::Services::Pairs, Exchanges::Oasisdex::Services::Pairs, Exchanges::Oax::Services::Pairs, Exchanges::Octaex::Services::Pairs, Exchanges::Okcoin::Services::Pairs, Exchanges::Okex::Services::Pairs, Exchanges::Omnitrade::Services::Pairs, Exchanges::Ooobtc::Services::Pairs, Exchanges::Openledger::Services::Pairs, Exchanges::Orderbook::Services::Pairs, Exchanges::OreBz::Services::Pairs, Exchanges::Otcbtc::Services::Pairs, Exchanges::P2pb2b::Services::Pairs, Exchanges::Paribu::Services::Pairs, Exchanges::Paroexchange::Services::Pairs, Exchanges::Paymium::Services::Pairs, Exchanges::Poloniex::Services::Pairs, Exchanges::Purcow::Services::Pairs, Exchanges::Qbtc::Services::Pairs, Exchanges::Qryptos::Services::Pairs, Exchanges::Quadrigacx::Services::Pairs, Exchanges::Quoine::Services::Pairs, Exchanges::RadarRelay::Services::Pairs, Exchanges::Raisex::Services::Pairs, Exchanges::Rfinex::Services::Pairs, Exchanges::Rightbtc::Services::Pairs, Exchanges::SafeTrade::Services::Pairs, Exchanges::Secondbtc::Services::Pairs, Exchanges::Sigen::Services::Pairs, Exchanges::Simex::Services::Pairs, Exchanges::Singularx::Services::Pairs, Exchanges::Sistemkoin::Services::Pairs, Exchanges::SouthXchange::Services::Pairs, Exchanges::StellarTerm::Services::Pairs, Exchanges::StocksExchange::Services::Pairs, Exchanges::Swiftex::Services::Pairs, Exchanges::Switcheo::Services::Pairs, Exchanges::Syex::Services::Pairs, Exchanges::Szzc::Services::Pairs, Exchanges::Tdax::Services::Pairs, Exchanges::Therocktrading::Services::Pairs, Exchanges::Thetokenstore::Services::Pairs, Exchanges::Thinkbit::Services::Pairs, Exchanges::Tideal::Services::Pairs, Exchanges::Tidebit::Services::Pairs, Exchanges::Tidex::Services::Pairs, Exchanges::Tokenjar::Services::Pairs, Exchanges::Tokenomy::Services::Pairs, Exchanges::TokensNet::Services::Pairs, Exchanges::Tokok::Services::Pairs, Exchanges::Topbtc::Services::Pairs, Exchanges::TradeOgre::Services::Pairs, Exchanges::TradeSatoshi::Services::Pairs, Exchanges::Tradeio::Services::Pairs, Exchanges::Trademn::Services::Pairs, Exchanges::TrocaNinja::Services::Pairs, Exchanges::TrustDex::Services::Pairs, Exchanges::TrxMarket::Services::Pairs, Exchanges::TuxExchange::Services::Pairs, Exchanges::Uex::Services::Pairs, Exchanges::Upbit::Services::Pairs, Exchanges::Vaultmex::Services::Pairs, Exchanges::Vbitex::Services::Pairs, Exchanges::Vebitcoin::Services::Pairs, Exchanges::Vertpig::Services::Pairs, Exchanges::Viabtc::Services::Pairs, Exchanges::Waves::Services::Pairs, Exchanges::Wazirx::Services::Pairs, Exchanges::Wcx::Services::Pairs, Exchanges::Wex::Services::Pairs, Exchanges::Worldcore::Services::Pairs, Exchanges::Yobit::Services::Pairs, Exchanges::Yuanbao::Services::Pairs, Exchanges::Yunbi::Services::Pairs, Exchanges::Yunex::Services::Pairs, Exchanges::Zaif::Services::Pairs, Exchanges::Zb::Services::Pairs, Exchanges::Zbg::Services::Pairs, Exchanges::Zebpay::Services::Pairs, Exchanges::Zeniex::Services::Pairs, Exchanges::Zgtop::Services::Pairs

Constant Summary collapse

PAIRS_URL =
nil
HTTP_METHOD =
'GET'
POST_PARAMS =
nil
MARKET =
nil

Instance Method Summary collapse

Instance Method Details

#default_override_exist?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/cryptoexchange/services/pairs.rb', line 68

def default_override_exist?
  File.exist? default_override_path
end

#default_override_pathObject



60
61
62
# File 'lib/cryptoexchange/services/pairs.rb', line 60

def default_override_path
  File.join(File.dirname(__dir__), "exchanges/#{exchange_class::NAME}/#{exchange_class::NAME}.yml")
end

#exchange_classObject



72
73
74
75
# File 'lib/cryptoexchange/services/pairs.rb', line 72

def exchange_class
  exchange_name = self.class.name.split('::')[2]
  Object.const_get "Cryptoexchange::Exchanges::#{exchange_name}::Market"
end

#fetchObject



11
12
13
14
15
16
17
18
19
20
# File 'lib/cryptoexchange/services/pairs.rb', line 11

def fetch
  # If PAIRS_URL provided, use that to fetch market pairs
  return fetch_via_api if self.class::PAIRS_URL

  # If gem user has an overriden yaml, use that
  return fetch_via_override(user_override_path) if user_override_exist?

  # Falls back to default overriden yaml
  return fetch_via_override(default_override_path) if default_override_exist?
end

#fetch_via_api(endpoint = self.class::PAIRS_URL, params = self.class::POST_PARAMS) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/cryptoexchange/services/pairs.rb', line 22

def fetch_via_api(endpoint = self.class::PAIRS_URL, params = self.class::POST_PARAMS)
  begin
    fetch_response = self.class::HTTP_METHOD == 'POST' ? http_post(endpoint, params) : http_get(endpoint)
    if fetch_response.code == 200
      fetch_response.parse :json
    elsif fetch_response.code == 400
      raise Cryptoexchange::HttpBadRequestError, { response: fetch_response }
    else
      raise Cryptoexchange::HttpResponseError, { response: fetch_response }
    end
  rescue HTTP::ConnectionError => e
    raise Cryptoexchange::HttpConnectionError, { error: e, response: fetch_response }
  rescue HTTP::TimeoutError => e
    raise Cryptoexchange::HttpTimeoutError, { error: e, response: fetch_response }
  rescue JSON::ParserError => e
    raise Cryptoexchange::JsonParseError, { error: e, response: fetch_response }
  rescue TypeError => e
    raise Cryptoexchange::TypeFormatError, { error: e, response: fetch_response }
  end
end

#fetch_via_api_using_post(endpoint = self.class::PAIRS_URL, headers = false, body = false) ⇒ Object



43
44
45
46
47
48
49
50
# File 'lib/cryptoexchange/services/pairs.rb', line 43

def fetch_via_api_using_post(endpoint = self.class::PAIRS_URL, headers = false, body = false)
  fetch_response = if headers && body
                     HTTP.timeout(:write => 2, :connect => 5, :read => 8).headers(headers).post(endpoint, body: body)
                   else
                     HTTP.timeout(:write => 2, :connect => 5, :read => 8).post(endpoint)
                   end
  JSON.parse(fetch_response.to_s)
end

#fetch_via_override(path) ⇒ Object



52
53
54
# File 'lib/cryptoexchange/services/pairs.rb', line 52

def fetch_via_override(path)
  YAML.load_file(path)[:pairs]
end

#http_get(endpoint) ⇒ Object



77
78
79
# File 'lib/cryptoexchange/services/pairs.rb', line 77

def http_get(endpoint)
  HTTP.timeout(:write => 2, :connect => 15, :read => 18).follow.get(endpoint)
end

#http_post(endpoint, params) ⇒ Object



81
82
83
# File 'lib/cryptoexchange/services/pairs.rb', line 81

def http_post(endpoint, params)
  HTTP.timeout(:write => 2, :connect => 5, :read => 8).post(endpoint, json: params)
end

#user_override_exist?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/cryptoexchange/services/pairs.rb', line 64

def user_override_exist?
  File.exist? user_override_path
end

#user_override_pathObject



56
57
58
# File 'lib/cryptoexchange/services/pairs.rb', line 56

def user_override_path
  "config/cryptoexchange/#{exchange_class::NAME}.yml"
end