bitx 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (9) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE +20 -0
  5. data/README.md +43 -0
  6. data/Rakefile +1 -0
  7. data/bitx.gemspec +23 -0
  8. data/lib/bitx.rb +75 -0
  9. metadata +93 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 13e2a9513a9793a95cc11fd1825af4c4ba821bf9
4
+ data.tar.gz: 7670ffa8ccc8785f061c4668a76705593eead385
5
+ SHA512:
6
+ metadata.gz: d999d9f6c64075e20a20844f6a68af0fa5f590fef835d69972696af90884e3cf7da1369e35fd6d1d5f690333b9ab40d2caf0fd47318d2d733605cd951e2ac461
7
+ data.tar.gz: 21dc0f53de29a64685022567a7da2947f1d01b1d1244b0f8de6d408a6cd90b90fe3eefbc8d3436be9e6fbed56283dc9515baa7b92b7f5a1ff4de06cc346c92cf
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in bitx-ruby.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Switchless
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ 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, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,43 @@
1
+ # BitX Ruby
2
+
3
+ Ruby wrapper for the BitX API.
4
+
5
+ Currently the public API (ticker, orderbook, trades) is wrapped.
6
+ TODO: Add the private API.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ gem 'bitx'
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install bitx
21
+
22
+ ## Usage
23
+
24
+ ```
25
+ require 'bitx'
26
+
27
+ # Fetch the ticker
28
+ BitX.new.ticker('XBTZAR')
29
+
30
+ # Fetch the order book
31
+ BitX.new.orderbook('XBTZAR')
32
+
33
+ # Fetch the latest trades
34
+ BitX.new.trades('XBTZAR')
35
+ ```
36
+
37
+ ## Contributing
38
+
39
+ 1. Fork it
40
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
41
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
42
+ 4. Push to the branch (`git push origin my-new-feature`)
43
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "bitx"
7
+ spec.version = '0.0.1'
8
+ spec.authors = ["Timothy Stranex"]
9
+ spec.email = ["timothy@switchless.com"]
10
+ spec.description = 'BitX API wrapper'
11
+ spec.summary = 'Ruby wrapper for the BitX API'
12
+ spec.homepage = "https://mybitx.com/api"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files`.split($/)
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.3"
21
+ spec.add_development_dependency "rake"
22
+ spec.add_runtime_dependency 'faraday'
23
+ end
@@ -0,0 +1,75 @@
1
+ require 'faraday'
2
+ require 'json'
3
+ require 'bigdecimal'
4
+
5
+ class BitX
6
+
7
+ class Error < StandardError
8
+ end
9
+
10
+ def ticker(pair)
11
+ t = get('/api/1/ticker', {pair: pair})
12
+ {
13
+ pair: pair,
14
+ timestamp: Time.at(t["timestamp"].to_i/1000),
15
+ ask: BigDecimal(t["ask"]),
16
+ bid: BigDecimal(t["bid"]),
17
+ last: BigDecimal(t["last_trade"]),
18
+ }
19
+ end
20
+
21
+ def orderbook(pair)
22
+ t = get('/api/1/orderbook', {pair: pair})
23
+
24
+ bids = []
25
+ t['bids'].each do |o|
26
+ bids << {
27
+ price: BigDecimal(o['price']),
28
+ volume: BigDecimal(o['volume'])
29
+ }
30
+ end
31
+
32
+ asks = []
33
+ t['asks'].each do |o|
34
+ asks << {
35
+ price: BigDecimal(o['price']),
36
+ volume: BigDecimal(o['volume'])
37
+ }
38
+ end
39
+
40
+ return {bids: bids, asks: asks}
41
+ end
42
+
43
+ def trades(pair)
44
+ t = get('/api/1/trades', {pair: pair})
45
+ trades = []
46
+ t['trades'].each do |trade|
47
+ trades << {
48
+ timestamp: Time.at(trade['timestamp'].to_i/1000),
49
+ price: BigDecimal(trade['price']),
50
+ volume: BigDecimal(trade['volume'])
51
+ }
52
+ end
53
+ trades
54
+ end
55
+
56
+ private
57
+
58
+ def conn
59
+ conn = Faraday.new(url: 'https://bitx.co.za')
60
+ conn.headers[:user_agent] = "bitx-ruby/0.0.1"
61
+ conn
62
+ end
63
+
64
+ def get(url, params)
65
+ r = conn.get(url, params)
66
+ if r.status != 200
67
+ raise BitX::Error.new("BitX error: #{r.status}")
68
+ end
69
+ t = JSON.parse r.body
70
+ if t['error']
71
+ raise BitX::Error.new('BitX error: ' + t['error'])
72
+ end
73
+ t
74
+ end
75
+ end
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bitx
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Timothy Stranex
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
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: faraday
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: BitX API wrapper
56
+ email:
57
+ - timothy@switchless.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - Gemfile
64
+ - LICENSE
65
+ - README.md
66
+ - Rakefile
67
+ - bitx.gemspec
68
+ - lib/bitx.rb
69
+ homepage: https://mybitx.com/api
70
+ licenses:
71
+ - MIT
72
+ metadata: {}
73
+ post_install_message:
74
+ rdoc_options: []
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - '>='
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ requirements: []
88
+ rubyforge_project:
89
+ rubygems_version: 2.0.14
90
+ signing_key:
91
+ specification_version: 4
92
+ summary: Ruby wrapper for the BitX API
93
+ test_files: []