flashboy 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/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +41 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/flashboy.gemspec +28 -0
- data/lib/ext/hash.rb +15 -0
- data/lib/flashboy.rb +34 -0
- data/lib/flashboy/ask.rb +12 -0
- data/lib/flashboy/bid.rb +12 -0
- data/lib/flashboy/bitfinex.rb +33 -0
- data/lib/flashboy/bittrex.rb +34 -0
- data/lib/flashboy/cex.rb +33 -0
- data/lib/flashboy/client.rb +56 -0
- data/lib/flashboy/exchange.rb +45 -0
- data/lib/flashboy/gdax.rb +33 -0
- data/lib/flashboy/gemini.rb +30 -0
- data/lib/flashboy/kraken.rb +35 -0
- data/lib/flashboy/order.rb +10 -0
- data/lib/flashboy/order_book.rb +11 -0
- data/lib/flashboy/poloniex.rb +31 -0
- data/lib/flashboy/quoine.rb +33 -0
- data/lib/flashboy/quote.rb +14 -0
- data/lib/flashboy/version.rb +3 -0
- metadata +129 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5bdef52969250e0352db625ab7d35e59f36f6479
|
4
|
+
data.tar.gz: e4a75faf8e32ff53e4124c125a08a8d706800658
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 273be5d6cfa97257f2a3246308d88442b58d7452fe59963e935f7d6fb8be0bec3c1f02253e0f478c60cee01e0d39eaec582ca494af255b6c9adf0bf7ab814059
|
7
|
+
data.tar.gz: 6bb6c3ff510472947d1d61518883be46224d1d0ab814abc3662c4290704e947beda9dd8589260b6a9d28e026840e4f180d580e0a780aa02ba047f7bc38cf5455
|
data/.gitignore
ADDED
data/.rspec
ADDED
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 matthew@coinbase.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
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Matthew Werner
|
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,41 @@
|
|
1
|
+
# Flashboy
|
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/flashboy`. 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 'flashboy'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install flashboy
|
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]/flashboy. 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
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
41
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "flashboy"
|
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
data/flashboy.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'flashboy/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "flashboy"
|
8
|
+
spec.version = Flashboy::VERSION
|
9
|
+
spec.authors = ["Matthew Werner"]
|
10
|
+
spec.email = ["m@mjw.io"]
|
11
|
+
|
12
|
+
spec.summary = %q{Connect with cryptocurrency exchanges}
|
13
|
+
spec.description = %q{Connect with cryptocurrency exchanges}
|
14
|
+
spec.homepage = "https://github.com/mwerner/flashboy"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_dependency 'faraday'
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.14"
|
26
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
27
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
28
|
+
end
|
data/lib/ext/hash.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# Hash - Core Extensions
|
2
|
+
class Hash
|
3
|
+
def recursively_symbolize_keys!
|
4
|
+
return self unless respond_to?(:keys)
|
5
|
+
keys.each do |k|
|
6
|
+
ks = k.respond_to?(:to_sym) ? k.to_sym : k
|
7
|
+
self[ks] = self.delete k # Preserve order even when k == ks
|
8
|
+
self[ks].recursively_symbolize_keys! if self[ks].kind_of? Hash
|
9
|
+
if self[ks].kind_of?(Array) && !self[ks].first.kind_of?(Array)
|
10
|
+
self[ks].map!{|v| self[ks].kind_of?(Hash) ? v.recursively_symbolize_keys! : v }
|
11
|
+
end
|
12
|
+
end
|
13
|
+
self
|
14
|
+
end
|
15
|
+
end
|
data/lib/flashboy.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'flashboy/version'
|
2
|
+
require 'faraday'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
require 'ext/hash'
|
6
|
+
|
7
|
+
module Flashboy
|
8
|
+
autoload :Ask, 'flashboy/ask'
|
9
|
+
autoload :Bid, 'flashboy/bid'
|
10
|
+
autoload :Client, 'flashboy/client'
|
11
|
+
autoload :Exchange, 'flashboy/exchange'
|
12
|
+
autoload :Order, 'flashboy/order'
|
13
|
+
autoload :OrderBook, 'flashboy/order_book'
|
14
|
+
autoload :Quote, 'flashboy/quote'
|
15
|
+
|
16
|
+
autoload :Bitfinex, 'flashboy/bitfinex'
|
17
|
+
autoload :Bittrex, 'flashboy/bittrex'
|
18
|
+
autoload :Cex, 'flashboy/cex'
|
19
|
+
autoload :Gdax, 'flashboy/gdax'
|
20
|
+
autoload :Gemini, 'flashboy/gemini'
|
21
|
+
autoload :Kraken, 'flashboy/kraken'
|
22
|
+
autoload :Poloniex, 'flashboy/poloniex'
|
23
|
+
autoload :Quoine, 'flashboy/quoine'
|
24
|
+
|
25
|
+
def self.quote(pair)
|
26
|
+
exchanges.map do |exchange|
|
27
|
+
exchange.new.quote(pair)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.exchanges
|
32
|
+
[Bitfinex, Bittrex, Cex, Gdax, Gemini, Kraken, Poloniex, Quoine]
|
33
|
+
end
|
34
|
+
end
|
data/lib/flashboy/ask.rb
ADDED
data/lib/flashboy/bid.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
module Flashboy
|
2
|
+
class Bitfinex < Exchange
|
3
|
+
name 'Bitfinex'
|
4
|
+
docs 'http://docs.bitfinex.com'
|
5
|
+
host 'https://api.bitfinex.com'
|
6
|
+
quote_path { |pair| "v1/pubticker/#{pair}.json" } #ethbtc
|
7
|
+
order_book_path { |pair| "v1/book/#{pair}.json" }
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def formatted_pair(pair)
|
12
|
+
currency, base = super(pair)
|
13
|
+
"#{currency}#{base}".upcase
|
14
|
+
end
|
15
|
+
|
16
|
+
def parse_quote(quote, pair)
|
17
|
+
{
|
18
|
+
bid: quote[:bid],
|
19
|
+
last: quote[:last_price],
|
20
|
+
ask: quote[:ask],
|
21
|
+
volume: quote[:volume],
|
22
|
+
timestamp: quote[:timestamp]
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
def parse_order_book(order, pair)
|
27
|
+
{
|
28
|
+
bids: order[:bids].map{|order| { price: order[:price], amount: order[:amount] } },
|
29
|
+
asks: order[:asks].map{|order| { price: order[:price], amount: order[:amount] } }
|
30
|
+
}
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Flashboy
|
2
|
+
class Bittrex < Exchange
|
3
|
+
name 'Bittrex'
|
4
|
+
docs 'https://bittrex.com/Home/Api'
|
5
|
+
host 'https://bittrex.com'
|
6
|
+
quote_path { |pair| "api/v1.1/public/getticker?market=#{pair}" } #BTC-ETH
|
7
|
+
order_book_path { |pair| "api/v1.1/public/getorderbook?market=#{pair}&type=both&depth=10" }
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def formatted_pair(pair)
|
12
|
+
currency, base = super(pair)
|
13
|
+
"#{base}-#{currency}".upcase
|
14
|
+
end
|
15
|
+
|
16
|
+
def parse_quote(quote, pair)
|
17
|
+
data = quote[:result]
|
18
|
+
{
|
19
|
+
bid: data[:Bid],
|
20
|
+
last: data[:Last],
|
21
|
+
ask: data[:Ask],
|
22
|
+
volume: data[:volume],
|
23
|
+
timestamp: data[:timestamp]
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
def parse_order_book(order, pair)
|
28
|
+
{
|
29
|
+
bids: order[:result][:buy].map{|o| { price: o[:Rate], amount: o[:Quantity] } },
|
30
|
+
asks: order[:result][:sell].map{|o| { price: o[:Rate], amount: o[:Quantity] } }
|
31
|
+
}
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/flashboy/cex.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
module Flashboy
|
2
|
+
class Cex < Exchange
|
3
|
+
name 'CEX'
|
4
|
+
docs 'https://cex.io/rest-api'
|
5
|
+
host 'https://cex.io/api'
|
6
|
+
quote_path { |pair| "ticker/#{pair}" } #ETH/BTC
|
7
|
+
order_book_path { |pair| "order_book/#{pair}/?depth=10" }
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def formatted_pair(pair)
|
12
|
+
currency, base = super(pair)
|
13
|
+
"#{currency}/#{base}".upcase
|
14
|
+
end
|
15
|
+
|
16
|
+
def parse_quote(quote, pair)
|
17
|
+
{
|
18
|
+
bid: quote[:bid],
|
19
|
+
last: quote[:last],
|
20
|
+
ask: quote[:ask],
|
21
|
+
volume: quote[:volume],
|
22
|
+
timestamp: quote[:timestamp]
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
def parse_order_book(order, pair)
|
27
|
+
{
|
28
|
+
bids: order[:bids].map{|(p, a)| { price: p, amount: a } },
|
29
|
+
asks: order[:asks].map{|(p, a)| { price: p, amount: a } }
|
30
|
+
}
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module Flashboy
|
2
|
+
class Client
|
3
|
+
def self.name(name = nil)
|
4
|
+
return @name if name.nil?
|
5
|
+
@name = name
|
6
|
+
end
|
7
|
+
|
8
|
+
def name
|
9
|
+
self.class.name
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.key
|
13
|
+
@name.to_s.downcase.gsub(' ', '_').to_sym
|
14
|
+
end
|
15
|
+
|
16
|
+
def key
|
17
|
+
self.class.key
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.docs(docs = nil)
|
21
|
+
return @docs if docs.nil?
|
22
|
+
@docs = docs
|
23
|
+
end
|
24
|
+
|
25
|
+
def docs
|
26
|
+
self.class.docs
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.host(host = nil)
|
30
|
+
return @host if host.nil?
|
31
|
+
@host = host
|
32
|
+
end
|
33
|
+
|
34
|
+
def host
|
35
|
+
self.class.host
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.quote_path(pair = nil, &path)
|
39
|
+
return @quote_path.call(pair) unless block_given?
|
40
|
+
@quote_path = path
|
41
|
+
end
|
42
|
+
|
43
|
+
def quote_path(pair)
|
44
|
+
self.class.quote_path(pair)
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.order_book_path(pair = nil, &path)
|
48
|
+
return @order_book_path.call(pair) unless block_given?
|
49
|
+
@order_book_path = path
|
50
|
+
end
|
51
|
+
|
52
|
+
def order_book_path(pair)
|
53
|
+
self.class.order_book_path(pair)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Flashboy
|
2
|
+
class Exchange < Client
|
3
|
+
def quote(pair)
|
4
|
+
id = formatted_pair(pair)
|
5
|
+
data = request quote_path(id)
|
6
|
+
Quote.new parse_quote(data, id).merge(
|
7
|
+
pair: pair,
|
8
|
+
exchange: name
|
9
|
+
)
|
10
|
+
end
|
11
|
+
|
12
|
+
def order_book(pair)
|
13
|
+
id = formatted_pair(pair)
|
14
|
+
data = request order_book_path(id)
|
15
|
+
OrderBook.new parse_order_book(data, id).merge(
|
16
|
+
pair: pair,
|
17
|
+
exchange: name
|
18
|
+
)
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def formatted_pair(pair)
|
24
|
+
currency, base = pair.split('-')
|
25
|
+
if [currency, base].compact.empty?
|
26
|
+
raise ArgumentError, 'You must provide the currency pair as CURRENCY-BASE'
|
27
|
+
end
|
28
|
+
[currency, base]
|
29
|
+
end
|
30
|
+
|
31
|
+
def request(path)
|
32
|
+
response = connection.get(path).body
|
33
|
+
data = JSON.parse(response)
|
34
|
+
data.recursively_symbolize_keys!
|
35
|
+
end
|
36
|
+
|
37
|
+
def connection
|
38
|
+
@connection ||= Faraday.new(url: host) do |faraday|
|
39
|
+
faraday.request :url_encoded # form-encode POST params
|
40
|
+
# faraday.response :logger # log requests to STDOUT
|
41
|
+
faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Flashboy
|
2
|
+
class Gdax < Exchange
|
3
|
+
name 'GDAX'
|
4
|
+
docs 'https://docs.gdax.com'
|
5
|
+
host 'https://api.gdax.com'
|
6
|
+
quote_path { |pair| "products/#{pair}/ticker" } #ETH-BTC
|
7
|
+
order_book_path { |pair| "products/#{pair}/book" }
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def formatted_pair(pair)
|
12
|
+
currency, base = super(pair)
|
13
|
+
"#{currency}-#{base}".upcase
|
14
|
+
end
|
15
|
+
|
16
|
+
def parse_quote(quote, pair)
|
17
|
+
{
|
18
|
+
bid: quote[:bid],
|
19
|
+
last: quote[:price],
|
20
|
+
ask: quote[:ask],
|
21
|
+
volume: quote[:volume],
|
22
|
+
timestamp: quote[:time]
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
def parse_order_book(order, pair)
|
27
|
+
{
|
28
|
+
bids: order[:bids].map{|order| { price: order[:price], amount: order[:amount] } },
|
29
|
+
asks: order[:asks].map{|order| { price: order[:price], amount: order[:amount] } }
|
30
|
+
}
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Flashboy
|
2
|
+
class Gemini < Exchange
|
3
|
+
name 'Gemini'
|
4
|
+
docs 'https://docs.gemini.com/rest-api'
|
5
|
+
host 'https://api.gemini.com/v1'
|
6
|
+
quote_path { |pair| "pubticker/#{pair}" } #ethbtc
|
7
|
+
order_book_path { |pair| "book/#{pair}?depth=10" }
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def formatted_pair(pair)
|
12
|
+
currency, base = super(pair)
|
13
|
+
"#{currency}#{base}".downcase
|
14
|
+
end
|
15
|
+
|
16
|
+
def parse_quote(quote, pair)
|
17
|
+
{
|
18
|
+
bid: quote[:bid],
|
19
|
+
last: quote[:last],
|
20
|
+
ask: quote[:ask],
|
21
|
+
volume: (quote[:volume].first || [])[1],
|
22
|
+
timestamp: quote[:timestamp]
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
def parse_order_book(order, pair)
|
27
|
+
order
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Flashboy
|
2
|
+
class Kraken < Exchange
|
3
|
+
name 'Kraken'
|
4
|
+
docs 'http://docs.bitfinex.com'
|
5
|
+
host 'https://api.kraken.com'
|
6
|
+
quote_path { |pair| "0/public/Ticker?pair=#{pair}" } #ETHXBT
|
7
|
+
order_book_path { |pair| "0/public/Depth?pair=#{pair}" }
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def formatted_pair(pair)
|
12
|
+
currency, base = super(pair).map { |curr| curr == 'BTC' ? 'XBT' : curr }
|
13
|
+
"#{currency}#{base}".upcase
|
14
|
+
end
|
15
|
+
|
16
|
+
def parse_quote(quote, pair)
|
17
|
+
data = quote[:result].values.first
|
18
|
+
{
|
19
|
+
bid: (data[:b] || []).first,
|
20
|
+
last: (data[:c] || []).first,
|
21
|
+
ask: (data[:a] || []).first,
|
22
|
+
volume: (data[:v] || []).first,
|
23
|
+
timestamp: nil
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
def parse_order_book(order, pair)
|
28
|
+
data = order[:result].values.first
|
29
|
+
{
|
30
|
+
bids: data[:bids].map{|(p,a,t)| { price: p, amount: a } },
|
31
|
+
asks: data[:asks].map{|(p,a,t)| { price: p, amount: a } }
|
32
|
+
}
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Flashboy
|
2
|
+
class Poloniex < Exchange
|
3
|
+
name 'Poloniex'
|
4
|
+
docs 'https://poloniex.com/support/api/'
|
5
|
+
host 'https://poloniex.com'
|
6
|
+
quote_path { |pair| "public?command=returnTicker" } #BTC_ETH
|
7
|
+
order_book_path { |pair| "book/#{pair}?depth=10" }
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def formatted_pair(pair)
|
12
|
+
currency, base = super(pair)
|
13
|
+
"#{base}_#{currency}".upcase
|
14
|
+
end
|
15
|
+
|
16
|
+
def parse_quote(quote, pair)
|
17
|
+
data = quote[pair.to_sym]
|
18
|
+
{
|
19
|
+
bid: data[:highestBid],
|
20
|
+
last: data[:last],
|
21
|
+
ask: data[:lowestAsk],
|
22
|
+
volume: data[:baseVolume],
|
23
|
+
timestamp: nil
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
def parse_order_book(order, pair)
|
28
|
+
order
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Flashboy
|
2
|
+
class Quoine < Exchange
|
3
|
+
name 'Quoine'
|
4
|
+
docs 'https://developers.quoine.com/#introduction'
|
5
|
+
host 'https://api.quoine.com'
|
6
|
+
quote_path { |pair| "products/code/CASH/#{pair}" } #ETHBTC
|
7
|
+
order_book_path { |pair| "products/#{pair}/price_levels" }
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def formatted_pair(pair)
|
12
|
+
currency, base = super(pair)
|
13
|
+
"#{currency}#{base}".upcase
|
14
|
+
end
|
15
|
+
|
16
|
+
def parse_quote(quote, pair)
|
17
|
+
{
|
18
|
+
bid: quote[:market_bid],
|
19
|
+
last: quote[:last_traded_price],
|
20
|
+
ask: quote[:market_ask],
|
21
|
+
volume: quote[:volume_24h],
|
22
|
+
timestamp: nil
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
def parse_order_book(order, pair)
|
27
|
+
{
|
28
|
+
bids: [],
|
29
|
+
asks: []
|
30
|
+
}
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Flashboy
|
2
|
+
class Quote
|
3
|
+
attr_reader :exchange, :pair, :bid, :ask, :last, :volume
|
4
|
+
|
5
|
+
def initialize(data)
|
6
|
+
@exchange = data[:exchange].to_s
|
7
|
+
@pair = data[:pair].to_s
|
8
|
+
@bid = data[:bid].to_s.to_f
|
9
|
+
@ask = data[:ask].to_s.to_f
|
10
|
+
@last = data[:last].to_s.to_f
|
11
|
+
@volume = data[:volume].to_s.to_f
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: flashboy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matthew Werner
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-04-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
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: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.14'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.14'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
description: Connect with cryptocurrency exchanges
|
70
|
+
email:
|
71
|
+
- m@mjw.io
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- ".travis.yml"
|
79
|
+
- CODE_OF_CONDUCT.md
|
80
|
+
- Gemfile
|
81
|
+
- LICENSE.txt
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- bin/console
|
85
|
+
- bin/setup
|
86
|
+
- flashboy.gemspec
|
87
|
+
- lib/ext/hash.rb
|
88
|
+
- lib/flashboy.rb
|
89
|
+
- lib/flashboy/ask.rb
|
90
|
+
- lib/flashboy/bid.rb
|
91
|
+
- lib/flashboy/bitfinex.rb
|
92
|
+
- lib/flashboy/bittrex.rb
|
93
|
+
- lib/flashboy/cex.rb
|
94
|
+
- lib/flashboy/client.rb
|
95
|
+
- lib/flashboy/exchange.rb
|
96
|
+
- lib/flashboy/gdax.rb
|
97
|
+
- lib/flashboy/gemini.rb
|
98
|
+
- lib/flashboy/kraken.rb
|
99
|
+
- lib/flashboy/order.rb
|
100
|
+
- lib/flashboy/order_book.rb
|
101
|
+
- lib/flashboy/poloniex.rb
|
102
|
+
- lib/flashboy/quoine.rb
|
103
|
+
- lib/flashboy/quote.rb
|
104
|
+
- lib/flashboy/version.rb
|
105
|
+
homepage: https://github.com/mwerner/flashboy
|
106
|
+
licenses:
|
107
|
+
- MIT
|
108
|
+
metadata: {}
|
109
|
+
post_install_message:
|
110
|
+
rdoc_options: []
|
111
|
+
require_paths:
|
112
|
+
- lib
|
113
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
requirements: []
|
124
|
+
rubyforge_project:
|
125
|
+
rubygems_version: 2.5.2
|
126
|
+
signing_key:
|
127
|
+
specification_version: 4
|
128
|
+
summary: Connect with cryptocurrency exchanges
|
129
|
+
test_files: []
|