ru_bittrex 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/ruby.yml +23 -0
  3. data/.gitignore +9 -0
  4. data/Gemfile +2 -0
  5. data/Gemfile.lock +27 -0
  6. data/LICENSE.txt +21 -0
  7. data/README.md +134 -0
  8. data/Rakefile +10 -0
  9. data/bin/console +13 -0
  10. data/bin/setup +6 -0
  11. data/credentials.example.yml +4 -0
  12. data/lib/ru_bittrex.rb +47 -0
  13. data/lib/ru_bittrex/account.rb +24 -0
  14. data/lib/ru_bittrex/address.rb +26 -0
  15. data/lib/ru_bittrex/balance.rb +25 -0
  16. data/lib/ru_bittrex/client.rb +69 -0
  17. data/lib/ru_bittrex/client_api.rb +96 -0
  18. data/lib/ru_bittrex/client_helper.rb +18 -0
  19. data/lib/ru_bittrex/configuration.rb +14 -0
  20. data/lib/ru_bittrex/currency.rb +32 -0
  21. data/lib/ru_bittrex/deposit.rb +37 -0
  22. data/lib/ru_bittrex/helpers.rb +10 -0
  23. data/lib/ru_bittrex/market.rb +32 -0
  24. data/lib/ru_bittrex/order.rb +5 -0
  25. data/lib/ru_bittrex/summary.rb +28 -0
  26. data/lib/ru_bittrex/ticker.rb +24 -0
  27. data/lib/ru_bittrex/version.rb +3 -0
  28. data/ru_bittrex.gemspec +29 -0
  29. data/test/fixtures/account.json +5 -0
  30. data/test/fixtures/address.json +5 -0
  31. data/test/fixtures/balance.json +6 -0
  32. data/test/fixtures/currency.json +13 -0
  33. data/test/fixtures/deposit.json +13 -0
  34. data/test/fixtures/market.json +12 -0
  35. data/test/fixtures/summary.json +9 -0
  36. data/test/fixtures/ticker.json +6 -0
  37. data/test/ru_bittrex/account_test.rb +31 -0
  38. data/test/ru_bittrex/address_test.rb +30 -0
  39. data/test/ru_bittrex/balance_test.rb +32 -0
  40. data/test/ru_bittrex/client_api_test.rb +61 -0
  41. data/test/ru_bittrex/client_helper_test.rb +48 -0
  42. data/test/ru_bittrex/client_test.rb +45 -0
  43. data/test/ru_bittrex/configuration_test.rb +61 -0
  44. data/test/ru_bittrex/currency_test.rb +38 -0
  45. data/test/ru_bittrex/deposit_test.rb +47 -0
  46. data/test/ru_bittrex/helpers_test.rb +17 -0
  47. data/test/ru_bittrex/market_test.rb +38 -0
  48. data/test/ru_bittrex/summary_test.rb +35 -0
  49. data/test/ru_bittrex/ticker_test.rb +31 -0
  50. data/test/ru_bittrex_test.rb +7 -0
  51. data/test/test_helper.rb +10 -0
  52. metadata +178 -0
@@ -0,0 +1,96 @@
1
+ module RuBittrex
2
+ module ClientApi
3
+
4
+ ## Accounts
5
+
6
+ def account
7
+ Account.get(cl)
8
+ end
9
+
10
+ def account_volume
11
+ Account.volume(cl)
12
+ end
13
+
14
+ ## Addresses
15
+
16
+ def addresses
17
+ Address.all(cl)
18
+ end
19
+
20
+ def address(currency)
21
+ Address.get(currency, cl)
22
+ end
23
+
24
+ ## Balances
25
+
26
+ def balances
27
+ Balance.all(cl)
28
+ end
29
+
30
+ def balance(currency)
31
+ Balance.get(currency, cl)
32
+ end
33
+
34
+ ## Currencies
35
+
36
+ def currencies
37
+ Currency.all(cl)
38
+ end
39
+
40
+ def currency(symbol)
41
+ Currency.get(symbol, cl)
42
+ end
43
+
44
+ ## Deposits
45
+
46
+ def open_deposits(params = {})
47
+ Deposit.open(params.merge(cl))
48
+ end
49
+
50
+ def closed_deposits(params = {})
51
+ Deposit.closed(params.merge(cl))
52
+ end
53
+
54
+ def deposit(id)
55
+ Deposit.get(id, cl)
56
+ end
57
+
58
+ ## Markets
59
+
60
+ def markets
61
+ Market.all(cl)
62
+ end
63
+
64
+ def market(symbol)
65
+ Market.get(symbol, cl)
66
+ end
67
+
68
+ ## Summaries
69
+
70
+ def summaries
71
+ Summary.all(cl)
72
+ end
73
+
74
+ def summary(market)
75
+ Summary.get(market, cl)
76
+ end
77
+
78
+ ## Tickers
79
+
80
+ def tickers
81
+ Ticker.all(cl)
82
+ end
83
+
84
+ def ticker(market)
85
+ Ticker.get(market, cl)
86
+ end
87
+
88
+ ## TODO: "markets/#{market}/orderbook" and "markets/#{market}/trades"
89
+
90
+ private
91
+
92
+ def cl
93
+ { client: self }
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,18 @@
1
+ module RuBittrex
2
+ module ClientHelper
3
+ private
4
+
5
+ def client(custom_client = nil)
6
+ custom_client || RuBittrex.client
7
+ end
8
+
9
+ def _get(path, params)
10
+ custom_client = params.delete(:client)
11
+ client(custom_client).get(path, params)
12
+ end
13
+
14
+ def collection(data)
15
+ data.map { |record| new(record) }
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,14 @@
1
+ module RuBittrex
2
+ class Configuration
3
+ attr_accessor :api_key, :secret
4
+
5
+ def initialize
6
+ @api_key = nil
7
+ @secret = nil
8
+ end
9
+
10
+ def auth
11
+ { api_key: @api_key, secret: @secret }
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,32 @@
1
+ module RuBittrex
2
+ class Currency
3
+ extend ClientHelper
4
+
5
+ attr_reader :symbol, :name, :coin_type, :status, :min_confirmations, :notice,
6
+ :tx_fee, :logo_url, :prohibited_in, :address, :terms_of_service, :raw
7
+ alias_method :terms, :terms_of_service
8
+
9
+ def initialize(attrs = {})
10
+ @symbol = attrs["symbol"]
11
+ @name = attrs["name"]
12
+ @coin_type = attrs["coinType"]
13
+ @status = attrs["status"]
14
+ @min_confirmations = attrs["minConfirmations"]
15
+ @notice = attrs["notice"]
16
+ @tx_fee = attrs["txFee"]
17
+ @logo_url = attrs["logoUrl"]
18
+ @prohibited_in = attrs["prohibitedIn"]
19
+ @address = attrs["baseAddress"]
20
+ @terms_of_service = attrs["associatedTermsOfService"]
21
+ @raw = attrs
22
+ end
23
+
24
+ def self.all(params = {})
25
+ collection _get('currencies', params)
26
+ end
27
+
28
+ def self.get(currency, params = {})
29
+ new _get("currencies/#{currency}", params)
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,37 @@
1
+ module RuBittrex
2
+ class Deposit
3
+ extend ClientHelper
4
+ include Helpers
5
+
6
+ attr_reader :id, :currency, :quantity, :address, :address_tag,
7
+ :tx_id, :confirmations, :updated_at, :completed_at,
8
+ :status, :source, :raw
9
+
10
+ def initialize(attrs = {})
11
+ @id = attrs["id"]
12
+ @currency = attrs["currencySymbol"]
13
+ @quantity = attrs["quantity"]
14
+ @address = attrs["cryptoAddress"]
15
+ @address_tag = attrs["cryptoAddressTag"]
16
+ @tx_id = attrs["txId"]
17
+ @confirmations = attrs["confirmations"]
18
+ @updated_at = extract_timestamp(attrs["updatedAt"])
19
+ @completed_at = extract_timestamp(attrs["completedAt"])
20
+ @status = attrs["status"]
21
+ @source = attrs["source"]
22
+ @raw = attrs
23
+ end
24
+
25
+ def self.closed(params = {})
26
+ collection _get('deposits/closed', params)
27
+ end
28
+
29
+ def self.open(params = {})
30
+ collection _get('deposits/open', params)
31
+ end
32
+
33
+ def self.get(id, params = {})
34
+ new _get("deposits/#{id}", params)
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,10 @@
1
+ require 'date'
2
+
3
+ module RuBittrex
4
+ module Helpers
5
+ def extract_timestamp(value)
6
+ return if value.nil? or value.strip.empty?
7
+ DateTime.parse value
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,32 @@
1
+ module RuBittrex
2
+ class Market
3
+ extend ClientHelper
4
+ include Helpers
5
+
6
+ attr_reader :symbol, :base_currency, :quote_currency, :min_trade, :precision,
7
+ :status, :created_at, :notice, :prohibited_in, :terms_of_service, :raw
8
+ alias_method :terms, :terms_of_service
9
+
10
+ def initialize(attrs = {})
11
+ @symbol = attrs["symbol"]
12
+ @base_currency = attrs["baseCurrencySymbol"]
13
+ @quote_currency = attrs["quoteCurrencySymbol"]
14
+ @min_trade = attrs["minTradeSize"]
15
+ @precision = attrs["precision"]
16
+ @status = attrs["status"]
17
+ @created_at = extract_timestamp(attrs["createdAt"])
18
+ @notice = attrs["notice"]
19
+ @prohibited_in = attrs["prohibitedIn"]
20
+ @terms_of_service = attrs["associatedTermsOfService"]
21
+ @raw = attrs
22
+ end
23
+
24
+ def self.all(params = {})
25
+ collection _get('markets', params)
26
+ end
27
+
28
+ def self.get(market, params = {})
29
+ new _get("markets/#{market}", params)
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,5 @@
1
+ module RuBittrex
2
+ class Order
3
+ extend ClientHelper
4
+ end
5
+ end
@@ -0,0 +1,28 @@
1
+ module RuBittrex
2
+ class Summary
3
+ extend ClientHelper
4
+ include Helpers
5
+
6
+ attr_reader :symbol, :high, :low, :volume, :quote_volume, :percent_change,
7
+ :updated_at, :raw
8
+
9
+ def initialize(attrs = {})
10
+ @symbol = attrs["symbol"]
11
+ @high = attrs["high"]
12
+ @low = attrs["low"]
13
+ @volume = attrs["volume"]
14
+ @quote_volume = attrs["quoteVolume"]
15
+ @percent_change = attrs["percentChange"]
16
+ @updated_at = extract_timestamp(attrs["updatedAt"])
17
+ @raw = attrs
18
+ end
19
+
20
+ def self.all(params = {})
21
+ collection _get('markets/summaries', params)
22
+ end
23
+
24
+ def self.get(market, params = {})
25
+ new _get("markets/#{market}/summary", params)
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,24 @@
1
+ module RuBittrex
2
+ class Ticker
3
+ extend ClientHelper
4
+ include Helpers
5
+
6
+ attr_reader :symbol, :last_rate, :bid_rate, :ask_rate, :raw
7
+
8
+ def initialize(attrs = {})
9
+ @symbol = attrs["symbol"]
10
+ @last_rate = attrs["lastTradeRate"]
11
+ @bid_rate = attrs["bidRate"]
12
+ @ask_rate = attrs["askRate"]
13
+ @raw = attrs
14
+ end
15
+
16
+ def self.all(params = {})
17
+ collection _get('markets/tickers', params)
18
+ end
19
+
20
+ def self.get(market, params = {})
21
+ new _get("markets/#{market}/ticker", params)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,3 @@
1
+ module RuBittrex
2
+ VERSION = "0.2.0"
3
+ end
@@ -0,0 +1,29 @@
1
+ require_relative 'lib/ru_bittrex/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "ru_bittrex"
5
+ spec.version = RuBittrex::VERSION
6
+ spec.authors = ["david metta"]
7
+ spec.email = ["davideliemetta@gmail.com"]
8
+ spec.summary = "bittrex API wrapper"
9
+ spec.description = "this gem is a ruby wrapper for the bittrex API"
10
+ spec.homepage = "https://github.com/davidmetta/ru_bittrex"
11
+ spec.license = "MIT"
12
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
13
+
14
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
15
+ spec.metadata["homepage_uri"] = spec.homepage
16
+ spec.metadata["source_code_uri"] = "https://github.com/davidmetta/ru_bittrex.git"
17
+ spec.metadata["changelog_uri"] = "https://github.com/davidmetta/ru_bittrex.git"
18
+
19
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) { `git ls-files -z`.split("\x0") }
20
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
21
+ spec.bindir = "bin"
22
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.add_dependency 'faraday', "~> 1.0.1"
26
+ spec.add_development_dependency "rake", "~> 12.0"
27
+ spec.add_development_dependency "minitest", "~> 5.0"
28
+ spec.add_development_dependency "mocha", "~> 1.11.2"
29
+ end
@@ -0,0 +1,5 @@
1
+ {
2
+ "accountId": "2r34rgreg",
3
+ "updated": "2018-08-10T00:00:00Z",
4
+ "volume30days": "1555.5050"
5
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "status": "ACTIVE",
3
+ "currencySymbol": "BTC",
4
+ "cryptoAddress": "242tgf4tgty45gtg"
5
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "currencySymbol": "BTC",
3
+ "total": "1.4567",
4
+ "available": "1.4567",
5
+ "updatedAt": "2018-08-10T00:00:00Z"
6
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "symbol": "BTC",
3
+ "name": "Bitcoin",
4
+ "coinType": "BITCOIN",
5
+ "status": "ONLINE",
6
+ "minConfirmations": "10",
7
+ "notice": "example notice",
8
+ "txFee": "0.005",
9
+ "logoUrl": "https://example.com/bitcoin.png",
10
+ "prohibitedIn": ["US"],
11
+ "baseAddress": "sfw35y4eer6eyhegsye",
12
+ "associatedTermsOfService": []
13
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "id": "rf3fr-r3fr45w-fry55-g54wr",
3
+ "currencySymbol": "BTC",
4
+ "quantity": "1.3345",
5
+ "cryptoAddress": "35243tg57hh7yre53e5wt35at5",
6
+ "cryptoAddressTag": "",
7
+ "txId": "sfawrg67u85a4tt3w6uw",
8
+ "confirmations": "30",
9
+ "updatedAt": "2018-08-10T00:00:00Z",
10
+ "completedAt": "2018-08-10T00:00:00Z",
11
+ "status": "COMPLETED",
12
+ "source": "BLOCKCHAIN"
13
+ }
@@ -0,0 +1,12 @@
1
+ {
2
+ "symbol": "BCH-ETH",
3
+ "baseCurrencySymbol": "BCH",
4
+ "quoteCurrencySymbol": "ETH",
5
+ "minTradeSize": "0.004",
6
+ "precision": "10",
7
+ "status": "ONLINE",
8
+ "createdAt": "2018-08-10T00:00:00Z",
9
+ "notice": "example notice",
10
+ "prohibitedIn": ["US"],
11
+ "associatedTermsOfService": []
12
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "symbol": "4ART-BTC",
3
+ "high": "0.00003",
4
+ "low": "0.000005",
5
+ "volume": "14455.56",
6
+ "quoteVolume": "14.5543",
7
+ "percentChange": "-2.76",
8
+ "updatedAt": "2018-08-10T00:00:00Z"
9
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "symbol": "4ART-BTC",
3
+ "lastTradeRate": "0.0035",
4
+ "bidRate": "0.00356",
5
+ "askRate": "0.00346"
6
+ }
@@ -0,0 +1,31 @@
1
+ require "date"
2
+ require "test_helper"
3
+
4
+ module RuBittrex
5
+ class AccountTest < Minitest::Test
6
+ def test_account_structure
7
+ data = fixture(:account)
8
+ account = Account.new(data)
9
+
10
+ assert_equal "2r34rgreg", account.id
11
+ assert_equal DateTime.parse("2018-08-10T00:00:00Z"), account.updated_at
12
+ assert_equal "1555.5050", account.volume
13
+ end
14
+
15
+ def test_get_account
16
+ data = fixture(:account)
17
+ account = Account.new(data)
18
+
19
+ Account.expects(:get).returns(account)
20
+ assert_equal account, Account.get
21
+ end
22
+
23
+ def test_account_volume
24
+ data = fixture(:account)
25
+ account = Account.new(data)
26
+
27
+ Account.expects(:volume).returns(account)
28
+ assert_equal account, Account.volume
29
+ end
30
+ end
31
+ end