waves_ruby_client 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c55f9b34b037fbd72ab4046612f66eba23b6fb30
4
+ data.tar.gz: fb54057820388f47a52c89ce32142c9f5f3d004f
5
+ SHA512:
6
+ metadata.gz: e432d2540a21416d76888c0d2a1c74edc5db95899e5ae3899d811494b514d870fa15c5d764e3d9ff60bbf351586940f9f1c847ec22da91ea9ba00d7ac4079939
7
+ data.tar.gz: 9440c0c82e694942ff39f00cc3d370e2a03bd85a3fca3184c992d5ad067211f26caab92dfed160cea189eaf4c3d7ffc6896f986af9e253ab5d8244f1aab6c5be
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1 @@
1
+ 2.4.1
@@ -0,0 +1,7 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.1
5
+ before_install: gem install bundler -v 1.14.6
6
+ script:
7
+ - bundle exec rake spec
@@ -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 pgrosselfinger@arri.de. 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
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in waves_ruby_client.gemspec
6
+ gemspec
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ # A sample Guardfile
4
+ # More info at https://github.com/guard/guard#readme
5
+
6
+ ## Uncomment and set this to only include directories you want to watch
7
+ # directories %w(app lib config test spec features) \
8
+ # .select{|d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist")}
9
+
10
+ ## Note: if you are using the `directories` clause above and you are not
11
+ ## watching the project directory ('.'), then you will want to move
12
+ ## the Guardfile to a watched dir and symlink it back, e.g.
13
+ #
14
+ # $ mkdir config
15
+ # $ mv Guardfile config/
16
+ # $ ln -s config/Guardfile .
17
+ #
18
+ # and, you'll have to watch "config/Guardfile" instead of "Guardfile"
19
+
20
+ # Note: The cmd option is now required due to the increasing number of ways
21
+ # rspec may be run, below are examples of the most common uses.
22
+ # * bundler: 'bundle exec rspec'
23
+ # * bundler binstubs: 'bin/rspec'
24
+ # * spring: 'bin/rspec' (This will use spring if running and you have
25
+ # installed the spring binstubs per the docs)
26
+ # * zeus: 'zeus rspec' (requires the server to be started separately)
27
+ # * 'just' rspec: 'rspec'
28
+
29
+ guard :rspec, cmd: 'bundle exec rspec' do
30
+ require 'guard/rspec/dsl'
31
+ dsl = Guard::RSpec::Dsl.new(self)
32
+
33
+ # Feel free to open issues for suggestions and improvements
34
+
35
+ # RSpec files
36
+ rspec = dsl.rspec
37
+ watch(rspec.spec_helper) { rspec.spec_dir }
38
+ watch(rspec.spec_support) { rspec.spec_dir }
39
+ watch(rspec.spec_files)
40
+
41
+ # Ruby files
42
+ ruby = dsl.ruby
43
+ dsl.watch_spec_files_for(ruby.lib_files)
44
+
45
+ # Rails files
46
+ rails = dsl.rails(view_extensions: %w[erb haml slim])
47
+ dsl.watch_spec_files_for(rails.app_files)
48
+ dsl.watch_spec_files_for(rails.views)
49
+
50
+ watch(rails.controllers) do |m|
51
+ [
52
+ rspec.spec.call("routing/#{m[1]}_routing"),
53
+ rspec.spec.call("controllers/#{m[1]}_controller"),
54
+ rspec.spec.call("acceptance/#{m[1]}")
55
+ ]
56
+ end
57
+
58
+ # Rails config changes
59
+ watch(rails.spec_helper) { rspec.spec_dir }
60
+ watch(rails.routes) { "#{rspec.spec_dir}/routing" }
61
+ watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }
62
+
63
+ # Capybara features specs
64
+ watch(rails.view_dirs) { |m| rspec.spec.call("features/#{m[1]}") }
65
+ watch(rails.layouts) { |m| rspec.spec.call("features/#{m[1]}") }
66
+
67
+ # Turnip features and steps
68
+ watch(%r{^spec/acceptance/(.+)\.feature$})
69
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
70
+ Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance'
71
+ end
72
+ end
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Philipp Großelfinger
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.
@@ -0,0 +1,130 @@
1
+ # WavesRubyClient
2
+
3
+ [![Build Status](https://travis-ci.org/phigrofi/waves_ruby_client.svg?branch=master)](https://travis-ci.org/phigrofi/waves_ruby_client)
4
+
5
+ With the waves ruby client gem, You can access some of the [Waves platform](https://wavesplatform.com/) API methods.
6
+
7
+ It was mainly build to create orders and can be used for automatic trading algorithms.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'waves_ruby_client'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install waves_ruby_client
24
+
25
+ ## Usage
26
+
27
+ The gem requires the following environment variables
28
+
29
+ * WAVES_PUBLIC_KEY: your waves public key
30
+ * WAVES_PRIVATE_KEY: your waves private key, necessary for signing requests
31
+ * WAVES_ADDRESS: your waves address
32
+
33
+ Optionally you can override the waves API URL (https://nodes.wavesnodes.com) and
34
+ the matcher public key (7kPFrHDiGw1rCm7LPszuECwWYL3dMf6iMifLRDJQZMzy) by setting the following environement variables:
35
+
36
+ * WAVES_API_URL
37
+ * WAVES_MATCHER_PUBLIC_KEY
38
+
39
+ ### Order book
40
+
41
+ Shows current the current order book
42
+
43
+ ```ruby
44
+ book = WavesRubyClient::OrderBook.btc_waves
45
+ book.refresh
46
+ book.bids
47
+ => [{ price: 0.00082101, amount: 104 }, ...] # sorted by price descending
48
+ book.asks
49
+ => [{ price: 0.00083, amount: 50 }, ...] # sorted by price ascending
50
+ ```
51
+
52
+ ### Order
53
+
54
+ An Order object has the following attributes:
55
+
56
+ * id
57
+ * price
58
+ * amount
59
+ * timestamp
60
+ * type (sell|buy)
61
+ * status (Accepted|PartiallyFilled|Filled|NotFound|Cancelled)
62
+
63
+ #### Get user orders
64
+
65
+ All orders:
66
+ ```ruby
67
+ WavesRubyClient::Order.all
68
+ ```
69
+
70
+ or orders with status (Accepted|PartiallyFilled)
71
+
72
+ ```ruby
73
+ WavesRubyClient::Order.active
74
+ ```
75
+
76
+ #### Place/Cancel/Delete limit order
77
+
78
+ ```ruby
79
+ order = WavesRubyClient::Order.new(price: 0.0008, amount: 10)
80
+ order.place # raises exception if not successful
81
+ order.cancel
82
+ order.delete
83
+ ```
84
+
85
+ #### Order status
86
+
87
+ ```ruby
88
+ order = WavesRubyClient::Order.new(price: 0.0008, amount: 10)
89
+ order.place
90
+ order.refresh_status
91
+ order.status
92
+ => 'Accepted'
93
+ order.pending?
94
+ => true
95
+ ```
96
+
97
+ ### Transaction
98
+
99
+ WavesRubyClient can list unconfirmed transactions. This can be used to wait for
100
+ the transaction of a filled order after placing the next order.
101
+
102
+ ```ruby
103
+ # order was filled
104
+ sleep(10) while WavesRubyClient::Transaction.my_unconfirmed_exchanges.any?
105
+
106
+ ```
107
+
108
+ ### Wallet
109
+
110
+ Lists user's balances for waves and bitcoins.
111
+
112
+ ```ruby
113
+ WavesRubyClient::Wallet.balance
114
+ => { waves: 5002.3, btc: 1200.3 }
115
+ ```
116
+
117
+ ## Development
118
+
119
+ 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.
120
+
121
+ 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).
122
+
123
+ ## Contributing
124
+
125
+ Bug reports and pull requests are welcome on GitHub at https://github.com/phigrofi/waves_ruby_client.
126
+ 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.
127
+
128
+
129
+ ## License
130
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'waves_ruby_client'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)
@@ -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,109 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BTC
4
+ # Base58 is used for compact human-friendly representation of Bitcoin addresses and private keys.
5
+ # Typically Base58-encoded text also contains a checksum (so-called "Base58Check").
6
+ # Addresses look like 19FGfswVqxNubJbh1NW8A4t51T9x9RDVWQ.
7
+ # Private keys look like 5KQntKuhYWSRXNqp2yhdXzjekYAR7US3MT1715Mbv5CyUKV6hVe.
8
+ #
9
+ # Here is what Satoshi said about Base58:
10
+ # Why base-58 instead of standard base-64 encoding?
11
+ # - Don't want 0OIl characters that look the same in some fonts and
12
+ # could be used to create visually identical looking account numbers.
13
+ # - A string with non-alphanumeric characters is not as easily accepted as an account number.
14
+ # - E-mail usually won't line-break if there's no punctuation to break at.
15
+ # - Double-clicking selects the whole number as one word if it's all alphanumeric.
16
+ #
17
+ module Base58
18
+ extend self
19
+
20
+ ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
21
+
22
+ # Converts binary string into its Base58 representation.
23
+ # If string is empty returns an empty string.
24
+ # If string is nil raises ArgumentError
25
+ def base58_from_data(data)
26
+ raise ArgumentError, 'Data is missing' unless data
27
+ leading_zeroes = 0
28
+ int = 0
29
+ base = 1
30
+ data.bytes.reverse_each do |byte|
31
+ if byte == 0
32
+ leading_zeroes += 1
33
+ else
34
+ leading_zeroes = 0
35
+ int += base * byte
36
+ end
37
+ base *= 256
38
+ end
39
+ ('1' * leading_zeroes) + base58_from_int(int)
40
+ end
41
+
42
+ # Converts binary string into its Base58 representation.
43
+ # If string is empty returns an empty string.
44
+ # If string is nil raises ArgumentError.
45
+ def data_from_base58(string)
46
+ raise ArgumentError, 'String is missing' unless string
47
+ int = int_from_base58(string)
48
+ bytes = []
49
+ while int > 0
50
+ remainder = int % 256
51
+ int /= 256
52
+ bytes.unshift(remainder)
53
+ end
54
+ data = BTC::Data.data_from_bytes(bytes)
55
+ byte_for_1 = '1'.bytes.first
56
+ BTC::Data.ensure_ascii_compatible_encoding(string).bytes.each do |byte|
57
+ break if byte != byte_for_1
58
+ data = "\x00" + data
59
+ end
60
+ data
61
+ end
62
+
63
+ def base58check_from_data(data)
64
+ raise ArgumentError, 'Data is missing' unless data
65
+ base58_from_data(data + BTC.hash256(data)[0, 4])
66
+ end
67
+
68
+ def data_from_base58check(string)
69
+ data = data_from_base58(string)
70
+ if data.bytesize < 4
71
+ raise FormatError, "Invalid Base58Check string: too short string #{string.inspect}"
72
+ end
73
+ payload_size = data.bytesize - 4
74
+ payload = data[0, payload_size]
75
+ checksum = data[payload_size, 4]
76
+ if checksum != BTC.hash256(payload)[0, 4]
77
+ raise FormatError, "Invalid Base58Check string: checksum invalid in #{string.inspect}"
78
+ end
79
+ payload
80
+ end
81
+
82
+ private
83
+
84
+ def base58_from_int(int)
85
+ raise ArgumentError, 'Integer is missing' unless int
86
+ string = ''
87
+ base = ALPHABET.size
88
+ while int > 0
89
+ int, remainder = int.divmod(base)
90
+ string = ALPHABET[remainder] + string
91
+ end
92
+ string
93
+ end
94
+
95
+ def int_from_base58(string)
96
+ raise ArgumentError, 'String is missing' unless string
97
+ int = 0
98
+ base = ALPHABET.size
99
+ string.reverse.each_char.with_index do |char, index|
100
+ char_index = ALPHABET.index(char)
101
+ unless char_index
102
+ raise FormatError, "Invalid Base58 character: #{char.inspect} at index #{index} (full string: #{string.inspect})"
103
+ end
104
+ int += char_index * (base**index)
105
+ end
106
+ int
107
+ end
108
+ end
109
+ end