btcturk 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +20 -13
- data/lib/btcturk.rb +96 -7
- data/lib/btcturk/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c35ab1a286023f149031e49ee63baa742adc3e63
|
4
|
+
data.tar.gz: 97de83d1b37d66339ed17bffe23c1d244de09e93
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 33c1dcd39c67510a3d23ad06e12ad44051efb80921d5e5ee0f2f723be212bff408bd22e92723cff363e0eb3efe60694761ee91c608415c7e6efee728bb16730a
|
7
|
+
data.tar.gz: a3b50cf5be543c78cc861f1082cbc2bbe6dbc6672d52de35e7c1d93e154a8f258ca7d36f3843fccf05d6d981885409b1603d3838002bfd92ab43e25683febeb9
|
data/README.md
CHANGED
@@ -44,26 +44,33 @@ BTCTurk::ticker
|
|
44
44
|
```
|
45
45
|
|
46
46
|
#### List all open orders:
|
47
|
-
|
48
|
-
|
47
|
+
```rb
|
48
|
+
BTCTurk::orderbook
|
49
|
+
```
|
49
50
|
|
50
51
|
#### List all trades:
|
51
|
-
|
52
|
-
|
52
|
+
```rb
|
53
|
+
BTCTurk::trades
|
54
|
+
```
|
53
55
|
|
54
56
|
#### List all trades after a specific trade-id:
|
55
57
|
```rb
|
56
58
|
BTCTurk::trades_since('532ded923ab47520bc5841d9')
|
59
|
+
```
|
57
60
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
61
|
+
#### See your balance:
|
62
|
+
```rb
|
63
|
+
BTCTurk::balance
|
64
|
+
```
|
65
|
+
|
66
|
+
#### See your open orders:
|
67
|
+
```rb
|
68
|
+
BTCTurk::orders
|
69
|
+
```
|
70
|
+
|
71
|
+
#### See your transaction history:
|
72
|
+
```rb
|
73
|
+
BTCTurk::orders
|
67
74
|
```
|
68
75
|
|
69
76
|
## Contributing
|
data/lib/btcturk.rb
CHANGED
@@ -1,5 +1,9 @@
|
|
1
|
+
require 'uri'
|
1
2
|
require 'json'
|
2
|
-
require '
|
3
|
+
require 'yaml'
|
4
|
+
require 'base64'
|
5
|
+
require 'openssl'
|
6
|
+
require 'net/http'
|
3
7
|
require 'btcturk/version'
|
4
8
|
|
5
9
|
module BTCTurk
|
@@ -7,24 +11,109 @@ module BTCTurk
|
|
7
11
|
BASE_URL = 'https://www.btcturk.com/api/'
|
8
12
|
|
9
13
|
def self.ticker
|
10
|
-
|
14
|
+
get 'ticker'
|
11
15
|
end
|
12
16
|
|
13
17
|
def self.orderbook
|
14
|
-
|
18
|
+
get 'orderbook'
|
15
19
|
end
|
16
20
|
|
17
21
|
def self.trades
|
18
|
-
|
22
|
+
get 'trades'
|
19
23
|
end
|
20
24
|
|
21
25
|
def self.trades_since(id)
|
22
|
-
|
26
|
+
get "trades?sinceid=#{id}"
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.balance
|
30
|
+
get 'balance'
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.orders
|
34
|
+
get 'openOrders'
|
35
|
+
end
|
36
|
+
|
37
|
+
# Check lines [61-64]
|
38
|
+
def self.transactions(offset = '0', limit = '100', sort = 'desc')
|
39
|
+
post 'userTransactions', offset, limit, sort
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.get(action)
|
43
|
+
@settings = get_config
|
44
|
+
|
45
|
+
uri = URI.parse(BASE_URL + action)
|
46
|
+
timestamp = Time.now.to_i.to_s
|
47
|
+
|
48
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
49
|
+
http.use_ssl = true
|
50
|
+
|
51
|
+
request = Net::HTTP::Get.new(uri.request_uri)
|
52
|
+
|
53
|
+
request['X-PCK'] = @settings[:api_key]
|
54
|
+
request['X-Stamp'] = timestamp
|
55
|
+
request['X-Signature'] = get_signature(timestamp)
|
56
|
+
|
57
|
+
response = http.request(request)
|
58
|
+
JSON.parse(response.body)
|
59
|
+
end
|
60
|
+
|
61
|
+
# User Transactions do not work at the moment
|
62
|
+
# Not sure if it's my code or the API to blame
|
63
|
+
# I'll try to solve it ASAP. In the meanwhile,
|
64
|
+
# Please do not hesitate to send pull requests!
|
65
|
+
|
66
|
+
def self.post(action, offset, limit, sort)
|
67
|
+
@settings = get_config
|
68
|
+
uri = URI.parse(BASE_URL + action)
|
69
|
+
timestamp = Time.now.to_i.to_s
|
70
|
+
|
71
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
72
|
+
http.use_ssl = true
|
73
|
+
|
74
|
+
request = Net::HTTP::Post.new(uri.request_uri)
|
75
|
+
|
76
|
+
request.set_form_data({'offset' => offset, 'limit' => limit, 'sort' => sort})
|
77
|
+
# request.set_body_internal({'offset' => offset, 'limit' => limit, 'sort' => sort})
|
78
|
+
# request.body = 'offset=0&limit=100&sort=desc'
|
79
|
+
|
80
|
+
request['X-PCK'] = @settings[:api_key]
|
81
|
+
request['X-Stamp'] = timestamp
|
82
|
+
request['X-Signature'] = get_signature(timestamp)
|
83
|
+
|
84
|
+
response = http.request(request)
|
85
|
+
response.body
|
86
|
+
end
|
87
|
+
|
88
|
+
def self.get_signature(timestamp)
|
89
|
+
message = @settings[:api_key] + timestamp
|
90
|
+
private_key = Base64.decode64(@settings[:private_key]).strip
|
91
|
+
digest = OpenSSL::HMAC.digest(OpenSSL::Digest.new('sha256'), private_key, message)
|
92
|
+
Base64.encode64(digest).strip
|
93
|
+
end
|
94
|
+
|
95
|
+
def self.set_config
|
96
|
+
settings = {}
|
97
|
+
printf('Please enter your API key: ')
|
98
|
+
settings[:api_key] = gets.chomp
|
99
|
+
printf('Please enter your Private key: ')
|
100
|
+
settings[:private_key] = gets.chomp
|
101
|
+
printf("(Saved under #{Dir.home}/.btcturk ...)\n\n")
|
102
|
+
|
103
|
+
File.open("#{Dir.home}/.btcturk", 'w') do |file|
|
104
|
+
file.write settings.to_yaml
|
105
|
+
end
|
23
106
|
|
107
|
+
get_config
|
24
108
|
end
|
25
109
|
|
26
|
-
def self.
|
27
|
-
|
110
|
+
def self.get_config
|
111
|
+
file = "#{Dir.home}/.btcturk"
|
112
|
+
if File.exist? file
|
113
|
+
YAML::load_file file
|
114
|
+
else
|
115
|
+
set_config
|
116
|
+
end
|
28
117
|
end
|
29
118
|
|
30
119
|
end
|
data/lib/btcturk/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: btcturk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kerem Bozdas
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-06-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: awesome_print
|
@@ -89,7 +89,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
89
89
|
version: '0'
|
90
90
|
requirements: []
|
91
91
|
rubyforge_project:
|
92
|
-
rubygems_version: 2.
|
92
|
+
rubygems_version: 2.2.2
|
93
93
|
signing_key:
|
94
94
|
specification_version: 4
|
95
95
|
summary: A simple ruby library to interface with BTCTurk API.
|