<commit_before>require 'spec_helper'

RSpec.describe 'Upbit integration specs' do
  let(:client) { Cryptoexchange::Client.new }
  let(:krw_btc_pair) { Cryptoexchange::Models::MarketPair.new(base: 'btc', target: 'krw', market: 'upbit') }

  it 'fetch pairs' do
    pairs = client.pairs('upbit')
    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 'upbit'
  end

  it 'give trade url' do
    trade_page_url = client.trade_page_url 'upbit', base: krw_btc_pair.base, target: krw_btc_pair.target
    expect(trade_page_url).to eq "https://upbit.com/exchange?code=CRIX.UPBIT.KRW-BTC"
  end

  it 'does not include non ACTIVE pairs' do
    pairs = client.pairs('upbit')
    expect((pairs.select { |p| p.base == 'TRIG' }).empty?).to be true
  end

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

    expect(ticker.base).to eq 'BTC'
    expect(ticker.target).to eq 'KRW'
    expect(ticker.market).to eq 'upbit'
    expect(ticker.last).to be_a Numeric
    expect(ticker.high).to be_a Numeric
    expect(ticker.low).to be_a Numeric
    expect(ticker.volume).to be_a Numeric
    expect(ticker.timestamp).to be nil
    
    expect(ticker.payload).to_not be nil
  end

  it 'fetch order book' do
    order_book = client.order_book(krw_btc_pair)

    expect(order_book.base).to eq 'BTC'
    expect(order_book.target).to eq 'KRW'
    expect(order_book.market).to eq 'upbit'
    expect(order_book.asks).to_not be_empty
    expect(order_book.bids).to_not be_empty
    expect(order_book.asks.first.price).to_not be_nil
    expect(order_book.bids.first.amount).to_not be_nil
    expect(order_book.timestamp).to be_a Numeric
    expect(order_book.payload).to_not be nil
  end

  it 'fetch trade' do
    trades = client.trades(krw_btc_pair)
    trade = trades.sample

    expect(trades).to_not be_empty
    expect(trade.base).to eq 'BTC'
    expect(trade.target).to eq 'KRW'
    expect(trade.market).to eq 'upbit'
    expect(['buy', 'sell']).to include trade.type
    expect(trade.price).to_not be_nil
    expect(trade.amount).to_not be_nil
    expect(trade.timestamp).to be_a Numeric
    expect(trade.payload).to_not be nil
  end
end
<commit_msg>Fix upbit orderbook spec<commit_after>require 'spec_helper'

RSpec.describe 'Upbit integration specs' do
  let(:client) { Cryptoexchange::Client.new }
  let(:krw_btc_pair) { Cryptoexchange::Models::MarketPair.new(base: 'btc', target: 'krw', market: 'upbit') }

  it 'fetch pairs' do
    pairs = client.pairs('upbit')
    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 'upbit'
  end

  it 'give trade url' do
    trade_page_url = client.trade_page_url 'upbit', base: krw_btc_pair.base, target: krw_btc_pair.target
    expect(trade_page_url).to eq "https://upbit.com/exchange?code=CRIX.UPBIT.KRW-BTC"
  end

  it 'does not include non ACTIVE pairs' do
    pairs = client.pairs('upbit')
    expect((pairs.select { |p| p.base == 'TRIG' }).empty?).to be true
  end

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

    expect(ticker.base).to eq 'BTC'
    expect(ticker.target).to eq 'KRW'
    expect(ticker.market).to eq 'upbit'
    expect(ticker.last).to be_a Numeric
    expect(ticker.high).to be_a Numeric
    expect(ticker.low).to be_a Numeric
    expect(ticker.volume).to be_a Numeric
    expect(ticker.timestamp).to be nil
    
    expect(ticker.payload).to_not be nil
  end

  it 'fetch order book' do
    order_book = client.order_book(krw_btc_pair)

    expect(order_book.base).to eq 'BTC'
    expect(order_book.target).to eq 'KRW'
    expect(order_book.market).to eq 'upbit'
    expect(order_book.asks).to_not be_empty
    expect(order_book.bids).to_not be_empty
    expect(order_book.asks.first.price).to_not be_nil
    expect(order_book.bids.first.amount).to_not be_nil
    expect(order_book.timestamp).to be nil
    expect(order_book.payload).to_not be nil
  end

  it 'fetch trade' do
    trades = client.trades(krw_btc_pair)
    trade = trades.sample

    expect(trades).to_not be_empty
    expect(trade.base).to eq 'BTC'
    expect(trade.target).to eq 'KRW'
    expect(trade.market).to eq 'upbit'
    expect(['buy', 'sell']).to include trade.type
    expect(trade.price).to_not be_nil
    expect(trade.amount).to_not be_nil
    expect(trade.timestamp).to be_a Numeric
    expect(trade.payload).to_not be nil
  end
end

{'fraction_non_alphanumeric': 0.121588639893499, 'fraction_numerical': 0.0, 'mean_word_length': 3.6666666666666665, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '926966', 'n_tokens_mistral': 1715, 'n_tokens_neox': 1654, 'n_words': 343}