|
| 1 | +require 'spec_helper' |
| 2 | +require 'webmock/rspec' |
| 3 | +require 'hashdiff' |
| 4 | +require_relative '../../lib/bitfinex' |
| 5 | + |
| 6 | +RSpec.describe 'Bitfinex::RESTv1 Integration' do |
| 7 | + before do |
| 8 | + # Stub the account info request |
| 9 | + stub_request(:post, "https://api.bitfinex.com/v1/account_infos") |
| 10 | + .with(body: '{}') |
| 11 | + .to_return( |
| 12 | + status: 200, |
| 13 | + body: '[ |
| 14 | + { |
| 15 | + "leo_fee_disc_c2c":"0.0", |
| 16 | + "leo_fee_disc_c2s":"0.0", |
| 17 | + "leo_fee_disc_c2f":"0.0", |
| 18 | + "leo_fee_disc_c2d":"0.0", |
| 19 | + "leo_fee_disc_abs_c2c":"0.0", |
| 20 | + "leo_fee_disc_abs_c2s":"0.0", |
| 21 | + "leo_fee_disc_abs_c2f":"0.0", |
| 22 | + "leo_fee_disc_abs_c2d":"0.0", |
| 23 | + "leo_fee_maker_disc_abs_c2d":"0.0", |
| 24 | + "maker_fees":"0.1", |
| 25 | + "taker_fees":"0.2", |
| 26 | + "fees":[ |
| 27 | + {"pairs":"BTC", "maker_fees":"0.1", "taker_fees":"0.2"}, |
| 28 | + {"pairs":"ETH", "maker_fees":"0.1", "taker_fees":"0.2"}, |
| 29 | + {"pairs":"IOT", "maker_fees":"0.1", "taker_fees":"0.2"}, |
| 30 | + {"pairs":"XRP", "maker_fees":"0.1", "taker_fees":"0.2"}, |
| 31 | + {"pairs":"REP", "maker_fees":"0.1", "taker_fees":"0.2"}, |
| 32 | + {"pairs":"GRG", "maker_fees":"0.1", "taker_fees":"0.2"}, |
| 33 | + {"pairs":"ZRX", "maker_fees":"0.1", "taker_fees":"0.2"}, |
| 34 | + {"pairs":"MLN", "maker_fees":"0.1", "taker_fees":"0.2"}, |
| 35 | + {"pairs":"SAN", "maker_fees":"0.1", "taker_fees":"0.2"}, |
| 36 | + {"pairs":"AMP", "maker_fees":"0.1", "taker_fees":"0.2"}, |
| 37 | + {"pairs":"DUSK", "maker_fees":"0.1", "taker_fees":"0.2"}, |
| 38 | + {"pairs":"LNX", "maker_fees":"0.1", "taker_fees":"0.2"}, |
| 39 | + {"pairs":"EOS", "maker_fees":"0.1", "taker_fees":"0.2"}, |
| 40 | + {"pairs":"TESTBTC", "maker_fees":"0.1", "taker_fees":"0.2"}, |
| 41 | + {"pairs":"TESTUSDT", "maker_fees":"0.1", "taker_fees":"0.2"}, |
| 42 | + {"pairs":"TESTUSD", "maker_fees":"0.1", "taker_fees":"0.2"}, |
| 43 | + {"pairs":"ETH2P", "maker_fees":"0.1", "taker_fees":"0.2"} |
| 44 | + ] |
| 45 | + } |
| 46 | + ]', |
| 47 | + headers: { 'Content-Type' => 'application/json' } |
| 48 | + ) |
| 49 | + |
| 50 | + # Stub the account fees request |
| 51 | + stub_request(:post, "https://api.bitfinex.com/v1/account_fees") |
| 52 | + .with(body: '{}') |
| 53 | + .to_return( |
| 54 | + status: 200, |
| 55 | + body: '{"withdraw":{"BTC":"0.000001","ETH":"0.0","IOT":"0.0","XRP":"0.0","GRG":"0.025367","ZRX":"0.00000249","MLN":"0.00036065","SAN":"33.819","AMP":"5.3018","DUSK":"0.08371","LNX":"0.000001","EOS":"0.0","TESTBTC":"0.0","TESTUSDT":"0.0","TESTUSD":"0.0","EXO":"0.0","BMN":"0.0"}}', |
| 56 | + headers: { 'Content-Type' => 'application/json' } |
| 57 | + ) |
| 58 | + end |
| 59 | + |
| 60 | + let(:client) do |
| 61 | + Bitfinex::RESTv1.new({ |
| 62 | + api_key: 'dummy_api_key', |
| 63 | + api_secret: 'dummy_api_secret', |
| 64 | + url: 'https://api.bitfinex.com', |
| 65 | + }) |
| 66 | + end |
| 67 | + |
| 68 | + it 'fetches account info' do |
| 69 | + response = client.account_info |
| 70 | + expect(response).not_to be_nil |
| 71 | + expect(response).to be_a(Array) |
| 72 | + expect(response.first['maker_fees']).to eq('0.1') |
| 73 | + expect(response.first['taker_fees']).to eq('0.2') |
| 74 | + expect(response.first['fees']).to be_a(Array) |
| 75 | + expect(response.first['fees'].first['pairs']).to eq('BTC') |
| 76 | + end |
| 77 | + |
| 78 | + it 'fetches fees' do |
| 79 | + response = client.fees |
| 80 | + expect(response).not_to be_nil |
| 81 | + expect(response).to be_a(Hash) |
| 82 | + expect(response['withdraw']['BTC']).to eq('0.000001') |
| 83 | + expect(response['withdraw']['ETH']).to eq('0.0') |
| 84 | + expect(response['withdraw']['GRG']).to eq('0.025367') |
| 85 | + end |
| 86 | +end |
0 commit comments