it_bit_sdk 0.1.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ec081a8af72f65f081cd40b64e63220b3bce201f
4
+ data.tar.gz: c32c335508bc8404b80d9db9c2444cd828023687
5
+ SHA512:
6
+ metadata.gz: 91047745adfe47b148ce2b05bb668afc700e9941d31c7b3479e79c8df2355521b72c7bd81171aefd2883dbbe0184ea21e9278353ef029bdcdd9dc9358a4d050f
7
+ data.tar.gz: c1d743e7cb84ebb7f6a57ebd04484c9f592f40dfc7a486f74107ec9c2618a01a29cfb94cf1b7c435012d0832217df5d456a71916f894d3e049d0961c7fff39bd
data/.gitignore ADDED
@@ -0,0 +1,50 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ # Used by dotenv library to load environment variables.
14
+ # .env
15
+
16
+ ## Specific to RubyMotion:
17
+ .dat*
18
+ .repl_history
19
+ build/
20
+ *.bridgesupport
21
+ build-iPhoneOS/
22
+ build-iPhoneSimulator/
23
+
24
+ ## Specific to RubyMotion (use of CocoaPods):
25
+ #
26
+ # We recommend against adding the Pods directory to your .gitignore. However
27
+ # you should judge for yourself, the pros and cons are mentioned at:
28
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
29
+ #
30
+ # vendor/Pods/
31
+
32
+ ## Documentation cache and generated files:
33
+ /.yardoc/
34
+ /_yardoc/
35
+ /doc/
36
+ /rdoc/
37
+
38
+ ## Environment normalization:
39
+ /.bundle/
40
+ /vendor/bundle
41
+ /lib/bundler/man/
42
+
43
+ # for a library or gem, you might want to ignore these files since the code is
44
+ # intended to run in multiple environments; otherwise, check them in:
45
+ # Gemfile.lock
46
+ # .ruby-version
47
+ # .ruby-gemset
48
+
49
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
50
+ .rvmrc
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rspec_status ADDED
@@ -0,0 +1,15 @@
1
+ example_id | status | run_time |
2
+ ------------------------------------------------------------------------------------- | ------ | --------------------- |
3
+ ./spec/it_bit_sdk/market_spec.rb[1:1] | passed | 0.0075 seconds |
4
+ ./spec/it_bit_sdk/market_spec.rb[1:2] | passed | 0.00632 seconds |
5
+ ./spec/it_bit_sdk/market_spec.rb[1:3] | passed | 0.05939 seconds |
6
+ ./spec/it_bit_sdk/services/bitcoin/withdrawal/request/check_schedule_spec.rb[1:1:1:1] | passed | 0.01953 seconds |
7
+ ./spec/it_bit_sdk/services/bitcoin/withdrawal/request/check_schedule_spec.rb[1:1:2:1] | passed | 0.00094 seconds |
8
+ ./spec/it_bit_sdk/trading/funding_history_spec.rb[1:1] | passed | 0.00559 seconds |
9
+ ./spec/it_bit_sdk/trading/order_spec.rb[1:1] | passed | 0.00407 seconds |
10
+ ./spec/it_bit_sdk/trading/trade_spec.rb[1:1] | passed | 0.00347 seconds |
11
+ ./spec/it_bit_sdk/trading/wallet_spec.rb[1:1] | passed | 16 minutes 30 seconds |
12
+ ./spec/it_bit_sdk/trading/wallet_spec.rb[1:2] | passed | 0.01235 seconds |
13
+ ./spec/it_bit_sdk/trading/wallet_spec.rb[1:3] | passed | 0.00652 seconds |
14
+ ./spec/it_bit_sdk_spec.rb[1:1] | passed | 0.00066 seconds |
15
+ ./spec/it_bit_sdk_spec.rb[1:2] | passed | 0.0003 seconds |
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.4
5
+ before_install: gem install bundler -v 1.16.0
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at nandooliveira.al@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in it_bit_sdk.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,90 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ it_bit_sdk (0.1.0)
5
+ activesupport
6
+ rest-client
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activesupport (5.1.4)
12
+ concurrent-ruby (~> 1.0, >= 1.0.2)
13
+ i18n (~> 0.7)
14
+ minitest (~> 5.1)
15
+ tzinfo (~> 1.1)
16
+ addressable (2.5.2)
17
+ public_suffix (>= 2.0.2, < 4.0)
18
+ coderay (1.1.2)
19
+ concurrent-ruby (1.0.5)
20
+ crack (0.4.3)
21
+ safe_yaml (~> 1.0.0)
22
+ diff-lcs (1.3)
23
+ domain_name (0.5.20170404)
24
+ unf (>= 0.0.5, < 1.0.0)
25
+ hashdiff (0.3.7)
26
+ http-cookie (1.0.3)
27
+ domain_name (~> 0.5)
28
+ i18n (0.9.1)
29
+ concurrent-ruby (~> 1.0)
30
+ method_source (0.9.0)
31
+ mime-types (3.1)
32
+ mime-types-data (~> 3.2015)
33
+ mime-types-data (3.2016.0521)
34
+ minitest (5.11.1)
35
+ netrc (0.11.0)
36
+ pry (0.11.3)
37
+ coderay (~> 1.1.0)
38
+ method_source (~> 0.9.0)
39
+ public_suffix (3.0.1)
40
+ rake (10.5.0)
41
+ rest-client (2.0.2)
42
+ http-cookie (>= 1.0.2, < 2.0)
43
+ mime-types (>= 1.16, < 4.0)
44
+ netrc (~> 0.8)
45
+ rspec (3.7.0)
46
+ rspec-core (~> 3.7.0)
47
+ rspec-expectations (~> 3.7.0)
48
+ rspec-mocks (~> 3.7.0)
49
+ rspec-core (3.7.0)
50
+ rspec-support (~> 3.7.0)
51
+ rspec-expectations (3.7.0)
52
+ diff-lcs (>= 1.2.0, < 2.0)
53
+ rspec-support (~> 3.7.0)
54
+ rspec-mocks (3.7.0)
55
+ diff-lcs (>= 1.2.0, < 2.0)
56
+ rspec-support (~> 3.7.0)
57
+ rspec-support (3.7.0)
58
+ safe_yaml (1.0.4)
59
+ shoulda-matchers (3.1.2)
60
+ activesupport (>= 4.0.0)
61
+ thread_safe (0.3.6)
62
+ timecop (0.9.1)
63
+ tzinfo (1.2.4)
64
+ thread_safe (~> 0.1)
65
+ unf (0.1.4)
66
+ unf_ext
67
+ unf_ext (0.0.7.4)
68
+ vcr (4.0.0)
69
+ webmock (3.2.1)
70
+ addressable (>= 2.3.6)
71
+ crack (>= 0.3.2)
72
+ hashdiff
73
+
74
+ PLATFORMS
75
+ ruby
76
+
77
+ DEPENDENCIES
78
+ bundler (~> 1.16)
79
+ it_bit_sdk!
80
+ pry
81
+ rake (~> 10.0)
82
+ rspec (~> 3.0)
83
+ rspec-mocks
84
+ shoulda-matchers
85
+ timecop
86
+ vcr (~> 4.0)
87
+ webmock
88
+
89
+ BUNDLED WITH
90
+ 1.16.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Fernando Oliveira
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # ItBit SDK
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/it_bit_sdk`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'it_bit_sdk'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install it_bit_sdk
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/it_bit_sdk. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
40
+
41
+ ## Code of Conduct
42
+
43
+ Everyone interacting in the ItBit SDK project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/it_bit_sdk/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "it_bit_sdk"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,48 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "it_bit_sdk/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "it_bit_sdk"
8
+ spec.version = ItBitSDK::VERSION
9
+ spec.authors = ["Fernando Oliveira"]
10
+ spec.email = ["nandooliveira.al@gmail.com"]
11
+
12
+ spec.summary = %q{itBit gem SDK.}
13
+ spec.description = %q{itBit gem SDK.}
14
+ spec.homepage = "https://github.com/husky-misc/itBit-ruby-sdk"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ # if spec.respond_to?(:metadata)
20
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
21
+ # else
22
+ # raise "RubyGems 2.0 or newer is required to protect against " \
23
+ # "public gem pushes."
24
+ # end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
+ f.match(%r{^(test|spec|features)/})
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ spec.add_dependency "activesupport"
34
+ spec.add_dependency "rest-client"
35
+
36
+ spec.add_development_dependency "bundler", "~> 1.16"
37
+ spec.add_development_dependency "rake", "~> 10.0"
38
+ spec.add_development_dependency "rspec", "~> 3.0"
39
+ spec.add_development_dependency "vcr", "~> 4.0"
40
+ spec.add_development_dependency "webmock"
41
+ spec.add_development_dependency "rspec-mocks"
42
+ spec.add_development_dependency "timecop"
43
+ spec.add_development_dependency "shoulda-matchers"
44
+
45
+ spec.add_development_dependency "pry"
46
+
47
+
48
+ end
@@ -0,0 +1,47 @@
1
+ require 'rest_client'
2
+ require 'json'
3
+ require_relative 'message_signer'
4
+ require "addressable/uri"
5
+
6
+ module ItBitSDK
7
+ class Base
8
+ BASE_URL = "https://api.itbit.com/v1"
9
+
10
+ def timestamp
11
+ Time.now.to_i
12
+ end
13
+
14
+ def next_nonce
15
+ timestamp
16
+ end
17
+
18
+ def send_request(verb, path, options = {})
19
+ timestamp = (Time.now.to_f * 1000).round.to_s
20
+ nonce = next_nonce
21
+ payload = options.empty? || verb == :get ? nil : JSON.dump(options)
22
+ query = options.any? && verb == :get ? "?#{URI.encode_www_form(options)}" : ''
23
+ url = "#{BASE_URL}#{path}#{query.gsub("%E2%80%8B", "")}"
24
+
25
+ signature = ::ItBitSDK::MessageSigner.new.sign_message(verb, url, payload, nonce, timestamp)
26
+ headers = {
27
+ authorization: "#{ItBitSDK.client_key}:#{signature}",
28
+ x_auth_timestamp: timestamp,
29
+ x_auth_nonce: nonce,
30
+ content_type: 'application/json'
31
+ }
32
+
33
+ begin
34
+ response = RestClient::Request.execute(
35
+ :method => verb,
36
+ :url => url,
37
+ :payload => payload,
38
+ :headers => headers,
39
+ :ssl_version => 'SSLv23')
40
+ rescue => e
41
+ response = e.response.body
42
+ end
43
+
44
+ JSON.parse(response.to_str) if response.to_s
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,23 @@
1
+ module ItBitSDK
2
+ class Order
3
+ attr_accessor :id, :wallet_id, :side, :instrument, :currency, :type, :amount, :price, :amount_filled, :volume_weighted_average_price, :created_time, :status, :display_amount, :metadata, :client_order_identifier
4
+
5
+ def initialize(params:)
6
+ @id = params['id']
7
+ @wallet_id = params['wallet_id']
8
+ @side = params['side']
9
+ @instrument = params['instrument']
10
+ @currency = params['currency']
11
+ @type = params['type']
12
+ @amount = params['amout']
13
+ @price = params['prive']
14
+ @amount_filled = params['amountFilled']
15
+ @volume_weighted_average_price = params['volumeWeightedAveragePrice']
16
+ @created_time = params['createTime']
17
+ @status = params['status']
18
+ @display_amount = params['displayAmount']
19
+ @metadata = params['metadata']
20
+ @client_order_identifier = params['clientOrderIdentifier']
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,10 @@
1
+ module ItBitSDK
2
+ class OrderBook
3
+ attr_accessor :bids, :asks
4
+
5
+ def initialize(params:)
6
+ @bids = params['bids']
7
+ @asks = params['asks']
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,24 @@
1
+ module ItBitSDK
2
+ class Ticker
3
+ attr_accessor :pair, :bid, :bid_amt, :ask, :ask_amt, :last_price, :last_amt, :volume_24h, :volume_today, :high_today, :high_24h, :low_24h, :low_today, :open_today, :vwap_today, :vwap_24h
4
+
5
+ def initialize(params:)
6
+ @pair = params['pair']
7
+ @bid = params['bid']
8
+ @bid_amt = params['bidAmt']
9
+ @ask = params['ask']
10
+ @ask_amt = params['askAmt']
11
+ @last_price = params['lastPrice']
12
+ @last_amt = params['lastAmt']
13
+ @volume_24h = params['volume24h']
14
+ @volume_today = params['volume_today']
15
+ @high_24h = params['high24h']
16
+ @high_today = params['high_today']
17
+ @low_24h = params['low24h']
18
+ @low_today = params['lowToday']
19
+ @open_today = params['openToday']
20
+ @vwap_today = params['vwapToday']
21
+ @vwap_24h = params['vwap24h']
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,12 @@
1
+ module ItBitSDK
2
+ class Trade
3
+ attr_accessor :timestamp, :match_number, :price, :amount
4
+
5
+ def initialize(params:)
6
+ @timestamp = Time.parse(params['timestamp'])
7
+ @match_number = params['matchNumber']
8
+ @price = params['price'].to_f
9
+ @amount = params['amount'].to_f
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,19 @@
1
+ module ItBitSDK
2
+ module Trades
3
+ class FundingHistory
4
+ attr_accessor :destination_address, :withdrawal_id, :holding_period_completion_date, :time, :currency, :transaction_type, :amount, :wallet_name, :status
5
+
6
+ def initialize(params:)
7
+ @destination_address = params['destinationAddress']
8
+ @withdrawal_id = params['withdrawalId']
9
+ @holding_period_completion_date = params['holdingPeriodCompletionDate']
10
+ @time = params['time']
11
+ @currency = params['currency']
12
+ @transaction_type = params['transactionType']
13
+ @amount = params['amount']
14
+ @wallet_name = params['walletName']
15
+ @status = params['status']
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,23 @@
1
+ module ItBitSDK
2
+ module Trades
3
+ class Trade
4
+ attr_accessor :order_id, :timestamp, :instrument, :direction, :currency_1, :currency_1_amount, :currency_2, :currency_2_amount, :rate, :commission_paid, :commission_currency, :rebates_applied, :rebate_currency
5
+
6
+ def initialize(params:)
7
+ @order_id = params['orderId']
8
+ @timestamp = params['timestamp']
9
+ @instrument = params['instrument']
10
+ @direction = params['direction']
11
+ @currency_1 = params['currency1']
12
+ @currency_1_amount = params['currency1Amount']
13
+ @currency_2 = params['currency2']
14
+ @currency_2_amount = params['currency2Amount']
15
+ @rate = params['rate']
16
+ @commission_paid = params['commissionPaid']
17
+ @commission_currency = params['commissionCurrency']
18
+ @rebates_applied = params['rebatesApplied']
19
+ @rebate_currency = params['rebateCurrency']
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,22 @@
1
+ module ItBitSDK
2
+ class Wallet
3
+ attr_accessor :id, :user_id, :name, :balances
4
+
5
+ class Balance
6
+ attr_accessor :available_balance, :total_balance, :currency
7
+
8
+ def initialize(params:)
9
+ @available_balance = params['availableBalance'].to_f
10
+ @total_balance = params['totalBalance'].to_f
11
+ @currency = params['currency']
12
+ end
13
+ end
14
+
15
+ def initialize(params:)
16
+ @id = params['id']
17
+ @user_id = params['userId']
18
+ @name = params['name']
19
+ @balances = params['balances'].collect { |balance| ::ItBitSDK::Wallet::Balance.new(params: balance) }
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,29 @@
1
+ require 'it_bit_sdk/base'
2
+ require 'it_bit_sdk/domain/ticker'
3
+ require 'it_bit_sdk/domain/order_book'
4
+ require 'it_bit_sdk/domain/trade'
5
+
6
+ module ItBitSDK
7
+ class Market < ItBitSDK::Base
8
+ def initialize(symbol:)
9
+ super()
10
+
11
+ @symbol = symbol
12
+ end
13
+
14
+ def ticker
15
+ response = send_request('get', "/markets/#{@symbol}/ticker")
16
+ ::ItBitSDK::Ticker.new(params: response)
17
+ end
18
+
19
+ def order_book
20
+ response = send_request('get', "/markets/#{@symbol}/order_book")
21
+ ::ItBitSDK::OrderBook.new(params: response)
22
+ end
23
+
24
+ def trades(since)
25
+ response = send_request('get', "/markets/#{@symbol}/trades?since=#{since}")
26
+ response['recentTrades'].collect { |trade| ::ItBitSDK::Trade.new(params: trade) }
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,19 @@
1
+ require 'json'
2
+ require 'digest'
3
+ require 'openssl'
4
+ require 'base64'
5
+
6
+ module ItBitSDK
7
+ class MessageSigner
8
+ def make_message(verb, url, body, nonce, timestamp)
9
+ [verb, url, body, nonce.to_s, timestamp.to_s].to_json
10
+ end
11
+
12
+ def sign_message(verb, url, json_body, nonce, timestamp)
13
+ message = JSON.dump([verb.upcase, url, json_body || '', nonce.to_s, timestamp])
14
+ hash_digest = OpenSSL::Digest::SHA256.digest(nonce.to_s + message)
15
+ hmac_digest = OpenSSL::HMAC.digest(OpenSSL::Digest::SHA512.new, ItBitSDK.secret, url + hash_digest)
16
+ Base64.strict_encode64(hmac_digest)
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,42 @@
1
+ module ItBitSDK
2
+ module Services
3
+ module Bitcoin
4
+ module Withdrawal
5
+ module Request
6
+ class CheckSchedule
7
+ def initialize
8
+ @time_ranges = [
9
+ { start: datetime_for('Singapore', 9), end: datetime_for('Singapore', 10) },
10
+ { start: datetime_for('Singapore', 12), end: datetime_for('Singapore', 13) },
11
+ { start: datetime_for('Singapore', 15), end: datetime_for('Singapore', 15, 30) },
12
+ { start: datetime_for('Singapore', 22), end: datetime_for('Singapore', 23) },
13
+ { start: datetime_for('Singapore', 1), end: datetime_for('Singapore', 2) },
14
+ { start: datetime_for('Singapore', 4), end: datetime_for('Singapore', 5) },
15
+ { start: datetime_for('Eastern Time (US & Canada)', 9), end: datetime_for('Eastern Time (US & Canada)', 10) },
16
+ { start: datetime_for('Eastern Time (US & Canada)', 12), end: datetime_for('Eastern Time (US & Canada)', 13) },
17
+ { start: datetime_for('Eastern Time (US & Canada)', 15), end: datetime_for('Eastern Time (US & Canada)', 15, 30) }
18
+ { start: datetime_for('Eastern Time (US & Canada)', 20), end: datetime_for('Eastern Time (US & Canada)', 21) }
19
+ { start: datetime_for('Eastern Time (US & Canada)', 0), end: datetime_for('Eastern Time (US & Canada)', 1) }
20
+ { start: datetime_for('Eastern Time (US & Canada)', 2), end: datetime_for('Eastern Time (US & Canada)', 3) }
21
+ ]
22
+ end
23
+
24
+ def call
25
+ @time_ranges.each do |range|
26
+ return range if (range[:start]..range[:end]).cover?(Time.now.utc)
27
+ end
28
+
29
+ nil
30
+ end
31
+
32
+ private
33
+
34
+ def datetime_for(timezone, hours, minutes = 0)
35
+ Time.now.in_time_zone(timezone).change({ hour: hours, min: minutes }).utc
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,24 @@
1
+ require 'it_bit_sdk/base'
2
+ require 'it_bit_sdk/domain/trades/funding_history'
3
+
4
+ module ItBitSDK
5
+ module Trading
6
+ class FundingHistory < ItBitSDK::Base
7
+ def history(wallet_id, opts = {})
8
+ params = {}
9
+ %w(page per_page).each do |a|
10
+ params[a.camelize(:lower)] = opts[a.to_sym].to_i if opts[a.to_sym]
11
+ end
12
+
13
+ response = send_request(:get, "/wallets/#{wallet_id}/funding_history", params)
14
+
15
+ {
16
+ total_number_of_records: response['totalNumberOfRecords'].to_i,
17
+ current_page_number: response['currentPageNumber'].to_i,
18
+ records_per_page: response['recordsPerPage'].to_i,
19
+ funding_history: response['fundingHistory'].collect{|x| ::ItBitSDK::Trades::FundingHistory::new(params: x) }
20
+ }
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,61 @@
1
+ require 'it_bit_sdk/base'
2
+ require 'it_bit_sdk/domain/order'
3
+
4
+ module ItBitSDK
5
+ module Trading
6
+ class Order < ItBitSDK::Base
7
+ def orders(wallet_id, opts = {})
8
+ params = {}
9
+ params[:instrument] = opts[:instrument].upcase if opts[:instrument]
10
+ params[:page] = opts[:page].to_i if opts[:page]
11
+ params[:perPage] = opts[:per_page].to_i if opts[:per_page]
12
+ params[:status] = opts[:status] if opts[:status]
13
+
14
+ send_request(:get, "/wallets/#{wallet_id}/orders", params)
15
+ .collect { |o| ::ItBitSDK::Order.new(params: o) }
16
+ end
17
+
18
+ def order(id, wallet_id)
19
+ ::ItBitSDK::Order.new(params: send_request(:get, "/wallets/#{wallet_id}/orders/#{id}"))
20
+ end
21
+
22
+ def create!(wallet_id, side, instrument, amount, price, options = {})
23
+ params = {
24
+ side: side,
25
+ instrument: instrument.to_s.upcase,
26
+ amount: amount.to_d.to_s('F'),
27
+ price: price.to_d.to_s('F'),
28
+ type: options[:type] || :limit,
29
+ currency: options[:currency].try(:upcase) || 'XBT'
30
+ }
31
+ %w(metadata client_order_identifier).each do |a|
32
+ params[a.camelize(:lower)] = options[a.to_sym] if options[a.to_sym]
33
+ end
34
+
35
+ order = ::ItBitSDK::Order.new(params: send_request(:post, "/wallets/#{wallet_id}/orders", params))
36
+ retries = 0
37
+ while options[:wait] && order.status == :submitted
38
+ sleep 0.2
39
+ begin
40
+ order = order(order.id, wallet_id)
41
+ rescue StandardError => e
42
+ end
43
+ retries += 1
44
+ if retries > 5000 # Wait 15 minutes for the order to be accepted.
45
+ raise StandardError.new(
46
+ "Timed out waiting for #{base_path} ##{order.id}")
47
+ end
48
+ end
49
+ return order
50
+ end
51
+
52
+ def cancel!(id, wallet_id)
53
+ send_request(:delete, "/wallets/#{wallet_id}/orders/#{id}")
54
+ self.status = :cancelling
55
+ return self
56
+ rescue RestClient::UnprocessableEntity
57
+ return nil
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,25 @@
1
+ require 'it_bit_sdk/base'
2
+ require 'it_bit_sdk/domain/trades/trade'
3
+
4
+ module ItBitSDK
5
+ module Trading
6
+ class Trade < ItBitSDK::Base
7
+ def trades(wallet_id, opts = {})
8
+ params = {}
9
+ %w(range_start range_end page per_page last_execution_id).each do |a|
10
+ params[a.camelize(:lower)] = opts[a.to_sym].to_i if opts[a.to_sym]
11
+ end
12
+
13
+ response = send_request(:get, "/wallets/#{wallet_id}/trades", params)
14
+
15
+ {
16
+ total_number_of_records: response['totalNumberOfRecords'].to_i,
17
+ current_page_number: response['currentPageNumber'].to_i,
18
+ latest_execution_id: response['latestExecutionId'].to_i,
19
+ records_per_page: response['recordsPerPage'].to_i,
20
+ trading_history: response['tradingHistory'].collect{|x| ::ItBitSDK::Trades::Trade::new(params: x) }
21
+ }
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,25 @@
1
+ require 'it_bit_sdk/base'
2
+ require 'it_bit_sdk/domain/wallet'
3
+
4
+ module ItBitSDK
5
+ module Trading
6
+ class Wallet < ::ItBitSDK::Base
7
+ def wallets(page: 1, per_page: 50)
8
+ send_request(:get, "/wallets", userId: ::ItBitSDK.user_id)
9
+ .collect { |wallet| ::ItBitSDK::Wallet.new(params: wallet) }
10
+ end
11
+
12
+ def create!(name)
13
+ ::ItBitSDK::Wallet.new(params: send_request(:post, "/wallets", name: name, user_id: ::ItBitSDK.user_id))
14
+ end
15
+
16
+ def wallet(wallet_id)
17
+ ::ItBitSDK::Wallet.new(params: send_request(:get, "/wallets/#{wallet_id}"))
18
+ end
19
+
20
+ def balance(wallet_id, currency_code)
21
+ ::ItBitSDK::Wallet::Balance.new(params: send_request(:get, "/wallets/#{wallet_id}/balances/#{currency_code}"))
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,3 @@
1
+ module ItBitSDK
2
+ VERSION = "0.1.0"
3
+ end
data/lib/it_bit_sdk.rb ADDED
@@ -0,0 +1,37 @@
1
+ require "it_bit_sdk/version"
2
+ require 'active_support/all'
3
+ require 'json'
4
+ require 'rest_client'
5
+ require 'bigdecimal'
6
+ require 'digest/sha2'
7
+ require 'base64'
8
+
9
+ Dir[File.expand_path("../itBit-ruby-sdk/*.rb", __FILE__)].each {|f| require f}
10
+
11
+ module ItBitSDK
12
+ mattr_accessor :client_key
13
+ mattr_accessor :secret
14
+ mattr_accessor :user_id
15
+
16
+ extend ::ActiveSupport::Autoload
17
+
18
+ autoload :Market
19
+
20
+ module Trading
21
+ extend ::ActiveSupport::Autoload
22
+ autoload :Order
23
+ autoload :Trade
24
+ autoload :Wallet
25
+ end
26
+
27
+ module Services
28
+ module Bitcoin
29
+ module Withdrawal
30
+ module Request
31
+ extend ::ActiveSupport::Autoload
32
+ autoload :CheckSchedule
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
metadata ADDED
@@ -0,0 +1,228 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: it_bit_sdk
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Fernando Oliveira
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-03-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rest-client
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.16'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.16'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: vcr
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '4.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '4.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: webmock
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec-mocks
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: timecop
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: shoulda-matchers
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: pry
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ description: itBit gem SDK.
168
+ email:
169
+ - nandooliveira.al@gmail.com
170
+ executables: []
171
+ extensions: []
172
+ extra_rdoc_files: []
173
+ files:
174
+ - ".gitignore"
175
+ - ".rspec"
176
+ - ".rspec_status"
177
+ - ".travis.yml"
178
+ - CODE_OF_CONDUCT.md
179
+ - Gemfile
180
+ - Gemfile.lock
181
+ - LICENSE.txt
182
+ - README.md
183
+ - Rakefile
184
+ - bin/console
185
+ - bin/setup
186
+ - it_bit_sdk.gemspec
187
+ - lib/it_bit_sdk.rb
188
+ - lib/it_bit_sdk/base.rb
189
+ - lib/it_bit_sdk/domain/order.rb
190
+ - lib/it_bit_sdk/domain/order_book.rb
191
+ - lib/it_bit_sdk/domain/ticker.rb
192
+ - lib/it_bit_sdk/domain/trade.rb
193
+ - lib/it_bit_sdk/domain/trades/funding_history.rb
194
+ - lib/it_bit_sdk/domain/trades/trade.rb
195
+ - lib/it_bit_sdk/domain/wallet.rb
196
+ - lib/it_bit_sdk/market.rb
197
+ - lib/it_bit_sdk/message_signer.rb
198
+ - lib/it_bit_sdk/services/bitcoin/withdrawal/request/check_schedule.rb
199
+ - lib/it_bit_sdk/trading/funding_history.rb
200
+ - lib/it_bit_sdk/trading/order.rb
201
+ - lib/it_bit_sdk/trading/trade.rb
202
+ - lib/it_bit_sdk/trading/wallet.rb
203
+ - lib/it_bit_sdk/version.rb
204
+ homepage: https://github.com/husky-misc/itBit-ruby-sdk
205
+ licenses:
206
+ - MIT
207
+ metadata: {}
208
+ post_install_message:
209
+ rdoc_options: []
210
+ require_paths:
211
+ - lib
212
+ required_ruby_version: !ruby/object:Gem::Requirement
213
+ requirements:
214
+ - - ">="
215
+ - !ruby/object:Gem::Version
216
+ version: '0'
217
+ required_rubygems_version: !ruby/object:Gem::Requirement
218
+ requirements:
219
+ - - ">="
220
+ - !ruby/object:Gem::Version
221
+ version: '0'
222
+ requirements: []
223
+ rubyforge_project:
224
+ rubygems_version: 2.6.14
225
+ signing_key:
226
+ specification_version: 4
227
+ summary: itBit gem SDK.
228
+ test_files: []