bitcurex 0.0.1

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: 4089533bd2b41c49a2a5850e2b73d736208b58c8
4
+ data.tar.gz: 33f1262c835dbaced8a2567ad47e15c39a0ada18
5
+ SHA512:
6
+ metadata.gz: 9cd3df69b528260a532bbade4c082b3539e216f8afd2fd342b432ba50c15307babd476880e7e12c252acf1d5250c1806c62a3081f0727cf153db786b84dc3687
7
+ data.tar.gz: 7f9b77ed4c9207ebded554ec60091f1dff0fea40ecd6ae2810de5192d034124c2931d0e0a823cdfbf3379ef5fadce6d3835be4e693fba8379166dcbcca00a4eb
@@ -0,0 +1,21 @@
1
+ *.gem
2
+ *.rbc
3
+ *.yml
4
+ .bundle
5
+ .config
6
+ .yardoc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
19
+ .idea/
20
+ .rspec
21
+ .rvmrc
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in bitcurex.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Adrian Dulić
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # Bitcurex
2
+
3
+ Bitcurex API
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'bitcurex'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install bitcurex
18
+
19
+ ## Usage
20
+
21
+ Use with caution!
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,72 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'optparse'
4
+ require 'ap'
5
+
6
+ $:.unshift(File.join(File.dirname(__FILE__), "/../lib"))
7
+ require 'bitcurex'
8
+
9
+ parser = OptionParser.new do |o|
10
+ o.banner = "USAGE: #{$0} [options]"
11
+
12
+ o.on("-o", "--orderbook [CURRENCY]", "Show orderbook") do |p|
13
+ @orderbook ||= Bitcurex::Market.orderbook(p)
14
+ ap "Bids"
15
+ ap @orderbook[:bids][0...3]
16
+ ap "Asks"
17
+ ap @orderbook[:asks][0...3]
18
+ end
19
+
20
+ o.on("-t", "--trades [CURRENCY]", "Show trades") do |p|
21
+ ap Bitcurex::Market.trades(p)[0...3]
22
+ end
23
+
24
+ o.on("-s", "--stats [CURRENCY]", "Show statistics") do |p|
25
+ ap Bitcurex::Market.ticker(p)
26
+ end
27
+
28
+ o.on("--balance", "Show account balance") do |p|
29
+ ap @account.balance
30
+ end
31
+
32
+ o.on("--address", "Show account address") do |p|
33
+ ap @account.address
34
+ end
35
+
36
+ o.on("--orders", "Show account orders") do |p|
37
+ ap @account.orders
38
+ end
39
+
40
+ o.on("--transactions", "List transaction") do |p|
41
+ ap @account.transactions
42
+ end
43
+
44
+ o.on("--bid AMOUNT,PRICE", Array, "Bid BTC") do |p|
45
+ ap @account.bid(*p)
46
+ end
47
+
48
+ o.on("--ask AMOUNT,PRICE", Array, "Ask BTC") do |p|
49
+ ap @account.ask(*p)
50
+ end
51
+
52
+ o.on("--cancel OID,TYPE", Array, "Cancel order") do |p|
53
+ ap @account.cancel(*p)
54
+ end
55
+
56
+ o.on("-c", "--config FILE", "Load configuration file") do |p|
57
+ Bitcurex.configure(YAML::load_file(p))
58
+ end
59
+
60
+ o.on("-v", "--verbose", "Be more talkative") do |p|
61
+ Bitcurex.configure(:verbose => p)
62
+ end
63
+
64
+ o.on("-h", "--help", "Show help documentation") do |p|
65
+ puts o
66
+ exit
67
+ end
68
+ end
69
+
70
+ Bitcurex.configure(YAML::load_file('bitcurex.yml')) unless Bitcurex.configured?
71
+ @account = Bitcurex::Account.setup
72
+ parser.parse!
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'bitcurex/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "bitcurex"
8
+ gem.version = Bitcurex::VERSION
9
+ gem.authors = ["Adrian Dulić", "Michał Ciemięga"]
10
+ gem.email = ["adulic@gmail.com"]
11
+ gem.description = %q{Bitcurex API}
12
+ gem.summary = %q{Bitcurex API}
13
+ gem.homepage = "https://github.com/adriandulic/bitcurex"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency 'oj', '~> 2.5.5'
21
+ gem.add_dependency 'httparty', '~> 0.13.1'
22
+
23
+ gem.add_development_dependency 'awesome_print'
24
+ gem.add_development_dependency 'rspec', '~> 3.0.0'
25
+ end
@@ -0,0 +1,2 @@
1
+ key: <your_api_key>
2
+ secret: <your_api_secret>
@@ -0,0 +1,32 @@
1
+ require "bitcurex/version"
2
+ require "httparty"
3
+ require "oj"
4
+
5
+ module Bitcurex
6
+ autoload :API, 'bitcurex/api'
7
+ autoload :Market, 'bitcurex/market'
8
+ autoload :Account, 'bitcurex/account'
9
+
10
+ ASK = 1
11
+ BID = 2
12
+ PLN = 'PLN'
13
+ EUR = 'EUR'
14
+ BTC = 'BTC'
15
+ TYPES = { 1 => 'ASK', 2 => 'BID' }
16
+
17
+ class << self
18
+ attr_accessor :key, :secret, :verbose
19
+
20
+ def configure(options = {})
21
+ options.each { |k,v| send("#{k}=", v) if respond_to?(k) }
22
+ end
23
+
24
+ def configured?
25
+ !!(key && secret)
26
+ end
27
+
28
+ def verbose?
29
+ !!verbose
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,75 @@
1
+ module Bitcurex
2
+ class Account
3
+ attr_accessor :key, :secret, :params, :headers
4
+
5
+ def self.setup(params = {})
6
+ new(params[:key] || Bitcurex.key, params[:secret] || Bitcurex.secret)
7
+ end
8
+
9
+ def initialize(key, secret)
10
+ @key, @secret = key, secret
11
+ @params = { :nonce => nonce }
12
+ @headers = { 'Rest-Key' => @key }
13
+ end
14
+
15
+ def balance
16
+ send('/getFunds')
17
+ end
18
+
19
+ def orders
20
+ send('/getOrders')
21
+ end
22
+
23
+ def transactions
24
+ send('/getTransactions')
25
+ end
26
+
27
+ def bid(amount, price)
28
+ send('/buyBTC', :amount => amount, :price => price)
29
+ end
30
+
31
+ def ask(amount, price)
32
+ send('/sellBTC', :amount => amount, :price => price)
33
+ end
34
+
35
+ def cancel(oid, type = Bitcurex::ASK)
36
+ send('/cancelOrder', :oid => oid, :type => type)
37
+ end
38
+
39
+ def withdraw(type, amount)
40
+ send('/withdraw', :type => type, :amount => amount)
41
+ end
42
+
43
+ def address
44
+ { :address => balance.fetch(:address) }
45
+ end
46
+
47
+ private
48
+
49
+ def send(path, params = {})
50
+ @params = @params.merge(params)
51
+ @headers = @headers.merge({ 'Rest-Sign' => signature })
52
+ API::Account.post(path, { :body => @params, :headers => @headers })
53
+ end
54
+
55
+ def nonce
56
+ (t = Time.now; t.to_i.to_s + t.usec.to_s)
57
+ end
58
+
59
+ def signature
60
+ Base64.strict_encode64(hash_hmac)
61
+ end
62
+
63
+ def hash_hmac
64
+ OpenSSL::HMAC.digest('sha512', decoded_secret, encoded_params)
65
+ end
66
+
67
+ def encoded_params
68
+ URI.encode_www_form(@params)
69
+ end
70
+
71
+ def decoded_secret
72
+ Base64.decode64(@secret)
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,42 @@
1
+ module Bitcurex
2
+ module API
3
+ class Base
4
+ include HTTParty
5
+ headers 'User-Agent' => "Mozilla/4.0 (compatible; Bitcurex ruby client; #{RUBY_PLATFORM}; ruby/#{RUBY_VERSION})"
6
+ default_timeout 30
7
+ debug_output $stdout if Bitcurex.verbose?
8
+
9
+ class OjParser < HTTParty::Parser
10
+ def parse
11
+ processed = Oj.load(body)
12
+ processed.is_a?(Hash) ? symbolize_keys(processed) : processed
13
+ end
14
+
15
+ private
16
+
17
+ def symbolize_keys(hash)
18
+ hash.inject({}) do |options, (key, value)|
19
+ options[(key.to_sym rescue key) || key] = value
20
+ options
21
+ end
22
+ end
23
+ end
24
+
25
+ parser(OjParser)
26
+ end
27
+
28
+ module Market
29
+ class EUR < Base
30
+ base_uri 'https://bitcurex.com/data'
31
+ end
32
+
33
+ class PLN < Base
34
+ base_uri 'https://pln.bitcurex.com/data'
35
+ end
36
+ end
37
+
38
+ class Account < Base
39
+ base_uri 'https://pln.bitcurex.com/api/0'
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,37 @@
1
+ module Bitcurex
2
+ class Market
3
+ class << self
4
+ def orderbook(cur = nil)
5
+ res = market(cur).get("/orderbook.json")
6
+ {
7
+ :bids => res.fetch(:bids).map { |b| [b[0].to_f, b[1].to_f] }.sort_by { |b| b[0] }.reverse,
8
+ :asks => res.fetch(:asks).map { |a| [a[0].to_f, a[1].to_f] }.sort_by { |b| b[0] }
9
+ }
10
+ end
11
+
12
+ def trades(cur = nil)
13
+ res = market(cur).get("/trades.json")
14
+ res.map do |trade|
15
+ trade.tap { |t|
16
+ t.store('date', Time.at(t.fetch('date')))
17
+ t.store('price', Float(t.fetch('price')))
18
+ t.store('amount', Float(t.fetch('amount')))
19
+ t.store('type', Bitcurex::TYPES.fetch(t.fetch('type')))
20
+ }
21
+ end.sort_by { |t| t.fetch('date') }.reverse
22
+ end
23
+
24
+ def ticker(cur = nil)
25
+ market(cur).get("/ticker.json").tap { |t|
26
+ t.store(:time, Time.at(t.fetch(:time)))
27
+ }
28
+ end
29
+
30
+ private
31
+
32
+ def market(cur)
33
+ API::Market.const_get(cur || Bitcurex::PLN)
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,3 @@
1
+ module Bitcurex
2
+ VERSION = "0.0.1"
3
+ end
File without changes
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bitcurex
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Adrian Dulić
8
+ - Michał Ciemięga
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-07-16 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: oj
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: 2.5.5
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: 2.5.5
28
+ - !ruby/object:Gem::Dependency
29
+ name: httparty
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: 0.13.1
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: 0.13.1
42
+ - !ruby/object:Gem::Dependency
43
+ name: awesome_print
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: rspec
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: 3.0.0
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: 3.0.0
70
+ description: Bitcurex API
71
+ email:
72
+ - adulic@gmail.com
73
+ executables:
74
+ - bitcurex
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - ".gitignore"
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - bin/bitcurex
84
+ - bitcurex.gemspec
85
+ - bitcurex.yml.example
86
+ - lib/bitcurex.rb
87
+ - lib/bitcurex/account.rb
88
+ - lib/bitcurex/api.rb
89
+ - lib/bitcurex/market.rb
90
+ - lib/bitcurex/version.rb
91
+ - spec/spec_helper.rb
92
+ homepage: https://github.com/adriandulic/bitcurex
93
+ licenses: []
94
+ metadata: {}
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ requirements: []
110
+ rubyforge_project:
111
+ rubygems_version: 2.2.2
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: Bitcurex API
115
+ test_files:
116
+ - spec/spec_helper.rb