bittrex-pro 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +7 -0
  2. data/.circleci/config.yml +58 -0
  3. data/.gitignore +28 -0
  4. data/.ruby-version +1 -0
  5. data/Gemfile +2 -0
  6. data/LICENSE.txt +22 -0
  7. data/README.md +53 -0
  8. data/Rakefile +11 -0
  9. data/bittrex-pro.gemspec +30 -0
  10. data/config/application.yml.example +2 -0
  11. data/lib/bittrex.rb +32 -0
  12. data/lib/bittrex/client.rb +46 -0
  13. data/lib/bittrex/configuration.rb +33 -0
  14. data/lib/bittrex/currency.rb +27 -0
  15. data/lib/bittrex/deposit.rb +29 -0
  16. data/lib/bittrex/helpers.rb +10 -0
  17. data/lib/bittrex/market.rb +31 -0
  18. data/lib/bittrex/order.rb +94 -0
  19. data/lib/bittrex/quote.rb +26 -0
  20. data/lib/bittrex/summary.rb +38 -0
  21. data/lib/bittrex/version.rb +3 -0
  22. data/lib/bittrex/wallet.rb +32 -0
  23. data/lib/bittrex/withdrawal.rb +42 -0
  24. data/spec/fixtures/currency.json +7 -0
  25. data/spec/fixtures/deposit.json +9 -0
  26. data/spec/fixtures/market.json +12 -0
  27. data/spec/fixtures/open_order.json +17 -0
  28. data/spec/fixtures/order.json +16 -0
  29. data/spec/fixtures/quote.json +5 -0
  30. data/spec/fixtures/summary.json +16 -0
  31. data/spec/fixtures/wallet.json +9 -0
  32. data/spec/fixtures/withdrawal.json +13 -0
  33. data/spec/models/configuration_spec.rb +27 -0
  34. data/spec/models/currency_spec.rb +14 -0
  35. data/spec/models/deposit_spec.rb +16 -0
  36. data/spec/models/helper_spec.rb +36 -0
  37. data/spec/models/market_spec.rb +17 -0
  38. data/spec/models/order_spec.rb +45 -0
  39. data/spec/models/quote_spec.rb +13 -0
  40. data/spec/models/summary_spec.rb +22 -0
  41. data/spec/models/wallet_spec.rb +16 -0
  42. data/spec/models/withdrawal_spec.rb +20 -0
  43. data/spec/spec_helper.rb +24 -0
  44. data/spec/support/api_helper.rb +9 -0
  45. metadata +220 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3e046a1a29f0fd811cd343623b70b6ce253ae6a8
4
+ data.tar.gz: 0646266bc74adbc384e15231164684c35527435f
5
+ SHA512:
6
+ metadata.gz: fd05ac629f845e609d5f9987e4f72c2a72ebc6e4c0b75d592684df248e2ced4637794e4a48b4aca58e75aa825c5449d1da9ab1f16000932ba8de5a35f325b444
7
+ data.tar.gz: 26d9c4fc38bfeda1b2f74a5e5c0319c7fca6c12b1b37f46db7ead9a0f3640ecdee5a8b50e64355d1ae9e69825545eae3c1d3e64327fce41d70568635e2bd4608
@@ -0,0 +1,58 @@
1
+ # Ruby CircleCI 2.0 configuration file
2
+ #
3
+ # Check https://circleci.com/docs/2.0/language-ruby/ for more details
4
+ #
5
+ version: 2
6
+ jobs:
7
+ build:
8
+ docker:
9
+ # specify the version you desire here
10
+ - image: circleci/ruby:2.3.3-node-browsers
11
+
12
+ # Specify service dependencies here if necessary
13
+ # CircleCI maintains a library of pre-built images
14
+ # documented at https://circleci.com/docs/2.0/circleci-images/
15
+ # - image: circleci/postgres:9.4
16
+
17
+ working_directory: ~/repo
18
+
19
+ steps:
20
+ - checkout
21
+
22
+ # Download and cache dependencies
23
+ - restore_cache:
24
+ keys:
25
+ - v1-dependencies-{{ checksum "Gemfile.lock" }}
26
+ # fallback to using the latest cache if no exact match is found
27
+ - v1-dependencies-
28
+
29
+ - run:
30
+ name: install dependencies
31
+ command: |
32
+ bundle install --jobs=4 --retry=3 --path vendor/bundle
33
+
34
+ - save_cache:
35
+ paths:
36
+ - ./vendor/bundle
37
+ key: v1-dependencies-{{ checksum "Gemfile.lock" }}
38
+
39
+ # run tests!
40
+ - run:
41
+ name: run tests
42
+ command: |
43
+ mkdir /tmp/test-results
44
+ TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)"
45
+
46
+ bundle exec rspec --format progress \
47
+ --format RspecJunitFormatter \
48
+ --out /tmp/test-results/rspec.xml \
49
+ --format progress \
50
+ -- \
51
+ $TEST_FILES
52
+
53
+ # collect reports
54
+ - store_test_results:
55
+ path: /tmp/test-results
56
+ - store_artifacts:
57
+ path: /tmp/test-results
58
+ destination: test-results
@@ -0,0 +1,28 @@
1
+ .DS_Store
2
+ *.gem
3
+ *.rbc
4
+ .rspec
5
+ .bundle
6
+ .config
7
+ .yardoc
8
+ Gemfile.lock
9
+ InstalledFiles
10
+ _yardoc
11
+ coverage
12
+ doc/
13
+ lib/bundler/man
14
+ pkg
15
+ rdoc
16
+ spec/reports
17
+ test/tmp
18
+ test/version_tmp
19
+ tmp
20
+ *.bundle
21
+ *.so
22
+ *.o
23
+ *.a
24
+ mkmf.log
25
+ script
26
+
27
+ # Ignore application configuration
28
+ /config/application.yml
@@ -0,0 +1 @@
1
+ 2.4.2
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2018 American Trade Exchange, Inc.
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,53 @@
1
+ # Bittrex Pro
2
+
3
+ Unofficial gem for the Bittrex API
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'bittrex-pro'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install bittrex-pro
18
+
19
+ ## Usage
20
+
21
+ The gem uses a simple mapping of API resources to models, with a majority of the attributes mapped to corresponding attributes on the corresponding class. There are some translations into a more "rubyish" verbage, but for the most part things are directly mapped.
22
+
23
+ require 'rubygems'
24
+ require 'bittrex-pro'
25
+ >> Quote.current('BTC-LTC')
26
+ #=> #<Bittrex::Quote:0x000001015cd058 @market="BTC-LTC", @bid=0.015792, @ask=0.01602899, @last=0.015792, @raw={"Bid"=>0.015792, "Ask"=>0.01602899, "Last"=>0.015792}>
27
+
28
+ ## Authentication
29
+
30
+ You can authenticate access to your Bittrex account by configuring your implementation of the bittrex-pro gem. This is accomplished by using a config block at the top of your application.
31
+
32
+ Set up your keys at: https://bittrex.com/manage
33
+
34
+ Bittrex.config do |c|
35
+ c.key = 'my_api_key'
36
+ c.secret = 'my_api_secret'
37
+ end
38
+
39
+ ## Development
40
+
41
+ You can test out public API calls any time by running `bundle exec rake bittrex:console` and inputting your method.
42
+
43
+ If you want to test private API calls, you will need to create `config/application.yml` and add your Bittrex keys to it (`config/application.yml.example` provides a template for this).
44
+
45
+ Once you've added the API keys, run `bundle exec rake bittrex:console`
46
+
47
+ ## Contributing
48
+
49
+ 1. Fork it ( https://github.com/[my-github-username]/bittrex-pro/fork )
50
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
51
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
52
+ 4. Push to the branch (`git push origin my-new-feature`)
53
+ 5. Create a new Pull Request
@@ -0,0 +1,11 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'figaro'
3
+
4
+ Figaro.application.path = File.expand_path('../config/application.yml', __FILE__)
5
+ Figaro.load
6
+
7
+ namespace :bittrex do
8
+ task :console do
9
+ exec "irb -r bittrex -I ./lib"
10
+ end
11
+ end
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'bittrex/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "bittrex-pro"
8
+ spec.version = Bittrex::VERSION
9
+ spec.authors = ["Vertbase"]
10
+ spec.email = ["dev@vertbase.com"]
11
+ spec.summary = %q{API Client for the Bittrex API}
12
+ spec.description = %q{API Client for the Bittrex API}
13
+ spec.homepage = "https://github.com/vertbase/bittrex-pro"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency 'faraday', '>= 0.9.0'
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.6"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "rspec"
26
+ spec.add_development_dependency "rspec_junit_formatter"
27
+ spec.add_development_dependency "simplecov"
28
+ spec.add_development_dependency "mocha"
29
+ spec.add_development_dependency "figaro"
30
+ end
@@ -0,0 +1,2 @@
1
+ bittrex_api_key: xxx
2
+ bittrex_api_secret: yyy
@@ -0,0 +1,32 @@
1
+ require "bittrex/version"
2
+
3
+ module Bittrex
4
+ autoload :Helpers, 'bittrex/helpers'
5
+ autoload :Market, 'bittrex/market'
6
+ autoload :Client, 'bittrex/client'
7
+ autoload :Configuration, 'bittrex/configuration'
8
+ autoload :Currency, 'bittrex/currency'
9
+ autoload :Deposit, 'bittrex/deposit'
10
+ autoload :Order, 'bittrex/order'
11
+ autoload :Quote, 'bittrex/quote'
12
+ autoload :Summary, 'bittrex/summary'
13
+ autoload :Wallet, 'bittrex/wallet'
14
+ autoload :Withdrawal, 'bittrex/withdrawal'
15
+
16
+ def self.client
17
+ @client ||= Client.new(configuration.auth)
18
+ end
19
+
20
+ def self.config
21
+ yield configuration
22
+ @client = Client.new(configuration.auth)
23
+ end
24
+
25
+ def self.configuration
26
+ Configuration.instance
27
+ end
28
+
29
+ def self.root
30
+ File.expand_path('../..', __FILE__)
31
+ end
32
+ end
@@ -0,0 +1,46 @@
1
+ require 'faraday'
2
+ require 'base64'
3
+ require 'json'
4
+
5
+ module Bittrex
6
+ class Client
7
+ HOST = 'https://bittrex.com/api/v1.1'
8
+
9
+ attr_reader :key, :secret
10
+
11
+ def initialize(attrs = {})
12
+ @key = attrs[:key]
13
+ @secret = attrs[:secret]
14
+ end
15
+
16
+ def get(path, params = {}, headers = {})
17
+ nonce = Time.now.to_i
18
+ response = connection.get do |req|
19
+ url = "#{HOST}/#{path}"
20
+ req.params.merge!(params)
21
+ req.url(url)
22
+
23
+ if key
24
+ req.params[:apikey] = key
25
+ req.params[:nonce] = nonce
26
+ req.headers[:apisign] = signature( connection.build_exclusive_url(req.path, req.params), nonce)
27
+ end
28
+ end
29
+
30
+ JSON.parse(response.body)['result']
31
+ end
32
+
33
+ private
34
+
35
+ def signature(url, nonce)
36
+ OpenSSL::HMAC.hexdigest('sha512', secret, "#{url}")
37
+ end
38
+
39
+ def connection
40
+ @connection ||= Faraday.new(:url => HOST) do |faraday|
41
+ faraday.request :url_encoded
42
+ faraday.adapter Faraday.default_adapter
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,33 @@
1
+ require 'singleton'
2
+
3
+ module Bittrex
4
+ class Configuration
5
+ include Singleton
6
+
7
+ attr_accessor :key, :secret
8
+
9
+ @@defaults = {
10
+ key: ENV['bittrex_api_key'],
11
+ secret: ENV['bittrex_api_secret']
12
+ }
13
+
14
+ def self.defaults
15
+ @@defaults
16
+ end
17
+
18
+ def initialize
19
+ reset
20
+ end
21
+
22
+ def auth
23
+ {
24
+ key: key,
25
+ secret: secret
26
+ }
27
+ end
28
+
29
+ def reset
30
+ @@defaults.each_pair { |k, v| send("#{k}=", v) }
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,27 @@
1
+ module Bittrex
2
+ class Currency
3
+ attr_reader :name, :abbreviation, :minimum_confirmation, :transaction_fee, :active, :raw
4
+
5
+ alias_method :min_confirmation, :minimum_confirmation
6
+ alias_method :fee, :transaction_fee
7
+
8
+ def initialize(attrs = {})
9
+ @name = attrs['CurrencyLong']
10
+ @abbreviation = attrs['Currency']
11
+ @transaction_fee = attrs['TxFee']
12
+ @minimum_confirmation = attrs['MinConfirmation']
13
+ @active = attrs['IsActive']
14
+ @raw = attrs
15
+ end
16
+
17
+ def self.all
18
+ client.get('public/getcurrencies').map{|data| new(data) }
19
+ end
20
+
21
+ private
22
+
23
+ def self.client
24
+ @client ||= Bittrex.client
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,29 @@
1
+ module Bittrex
2
+ class Deposit
3
+ include Helpers
4
+
5
+ attr_reader :id, :transaction_id, :address, :quantity, :currency, :confirmations, :executed_at
6
+ attr_reader :raw
7
+
8
+ def initialize(attrs = {})
9
+ @id = attrs['Id']
10
+ @transaction_id = attrs['TxId']
11
+ @address = attrs['CryptoAddress']
12
+ @quantity = attrs['Amount']
13
+ @currency = attrs['Currency']
14
+ @confirmations = attrs['Confirmations']
15
+ @executed_at = extract_timestamp(attrs['LastUpdated'])
16
+ @raw = attrs
17
+ end
18
+
19
+ def self.all
20
+ client.get('account/getdeposithistory').map{|data| new(data) }
21
+ end
22
+
23
+ private
24
+
25
+ def self.client
26
+ @client ||= Bittrex.client
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,10 @@
1
+ require 'date'
2
+
3
+ module Bittrex
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,31 @@
1
+ require 'time'
2
+
3
+ module Bittrex
4
+ class Market
5
+ include Helpers
6
+
7
+ attr_reader :name, :currency, :base, :currency_name, :base_name, :minimum_trade, :active, :created_at, :raw
8
+
9
+ def initialize(attrs = {})
10
+ @name = attrs['MarketName']
11
+ @currency = attrs['MarketCurrency']
12
+ @base = attrs['BaseCurrency']
13
+ @currency_name = attrs['MarketCurrencyLong']
14
+ @base_name = attrs['BaseCurrencyLong']
15
+ @minimum_trade = attrs['MinTradeSize']
16
+ @active = attrs['IsActive']
17
+ @created_at = extract_timestamp(attrs['Created'])
18
+ @raw = attrs
19
+ end
20
+
21
+ def self.all
22
+ client.get('public/getmarkets').map{|data| new(data) }
23
+ end
24
+
25
+ private
26
+
27
+ def self.client
28
+ @client ||= Bittrex.client
29
+ end
30
+ end
31
+ end