waves_ruby_client 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/.ruby-version +1 -0
- data/.travis.yml +7 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Guardfile +72 -0
- data/LICENSE.txt +21 -0
- data/README.md +130 -0
- data/Rakefile +8 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/btc/base58.rb +109 -0
- data/lib/btc/data.rb +109 -0
- data/lib/sign/axlsign.rb +1154 -0
- data/lib/sign/int32.rb +63 -0
- data/lib/waves_ruby_client.rb +56 -0
- data/lib/waves_ruby_client/api.rb +19 -0
- data/lib/waves_ruby_client/asset.rb +25 -0
- data/lib/waves_ruby_client/conversion.rb +29 -0
- data/lib/waves_ruby_client/order.rb +104 -0
- data/lib/waves_ruby_client/order_book.rb +33 -0
- data/lib/waves_ruby_client/order_data/cancel.rb +36 -0
- data/lib/waves_ruby_client/order_data/place.rb +66 -0
- data/lib/waves_ruby_client/order_data/user_orders.rb +34 -0
- data/lib/waves_ruby_client/transaction.rb +19 -0
- data/lib/waves_ruby_client/version.rb +5 -0
- data/lib/waves_ruby_client/wallet.rb +17 -0
- data/waves_ruby_client.gemspec +34 -0
- metadata +171 -0
checksums.yaml
ADDED
@@ -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
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.4.1
|
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -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
data/Guardfile
ADDED
@@ -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
|
data/LICENSE.txt
ADDED
@@ -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.
|
data/README.md
ADDED
@@ -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).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -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__)
|
data/bin/setup
ADDED
data/lib/btc/base58.rb
ADDED
@@ -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
|