btcmrb 0.1.3 → 0.1.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 +26 -9
- data/lib/btcmrb/client.rb +19 -20
- data/lib/btcmrb/order.rb +104 -0
- data/lib/btcmrb/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c2566a4ef1fb0d3202c78ce8c47ffc2de7aaaeac
|
4
|
+
data.tar.gz: 4c73981d2d96c5fcdb12515b23407bdfd1a42e16
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4af5a8812bd5bb70875e0a85d0a53a930be60f4c7ac19f3273f3cdd9fe21759412ba3a2e67fffa7e09a3d55faede15c235e3be27302de9b30816470852262b81
|
7
|
+
data.tar.gz: 7a3fee908a4b72773d373ba0002b7e89393e5b06d677a581f8979448e9fda11e59ac6fbdd8489a2ef373fc5b6ef6ee1760914c02675052123a02578095f619df
|
data/README.md
CHANGED
@@ -1,12 +1,18 @@
|
|
1
|
-
#
|
1
|
+
# Btcmrb (BTC Markets Ruby)
|
2
|
+
|
2
3
|
|
3
4
|
## Description
|
4
5
|
Unofficial Ruby Gem for btcmarkets.net API and is still very much a work in progress.
|
5
6
|
|
6
7
|
## Installation
|
7
8
|
### Install the gem
|
8
|
-
|
9
|
-
|
9
|
+
Command line:
|
10
|
+
```
|
11
|
+
$ gem install btcmrb
|
12
|
+
```
|
13
|
+
Or in your application's Gemfile:
|
14
|
+
```
|
15
|
+
gem 'btcmrb', '~> 0.1.3'
|
10
16
|
```
|
11
17
|
### Create some environment variables
|
12
18
|
https://btcmarkets.net/account/apikey
|
@@ -18,9 +24,8 @@ export BTCM_SECRET="YOUR SECRET"
|
|
18
24
|
### Account Management API
|
19
25
|
https://github.com/BTCMarkets/API/wiki/Account-API
|
20
26
|
```ruby
|
21
|
-
# Example
|
22
|
-
balance_request = Btcmrb::Account.balance
|
23
27
|
client = Btcmrb.new
|
28
|
+
balance_request = Btcmrb::Account.balance
|
24
29
|
client.send_request(balance_request)
|
25
30
|
# => [{"balance":1000000000,"pendingFunds":0,"currency":"AUD"},{"balance":1000000000,"pendingFunds":0,"currency":"BTC"},{"balance":1000000000,"pendingFunds":0,"currency":"LTC"}]
|
26
31
|
```
|
@@ -28,21 +33,33 @@ client.send_request(balance_request)
|
|
28
33
|
### Market Data API
|
29
34
|
https://github.com/BTCMarkets/API/wiki/Market-data-API
|
30
35
|
```ruby
|
31
|
-
# Example
|
32
|
-
ticker_request = Btcmrb::Marketdata.tick
|
33
36
|
client = Btcmrb.new
|
37
|
+
ticker_request = Btcmrb::Marketdata.tick
|
34
38
|
client.send_request(ticker_request)
|
35
39
|
# => {"bestBid":844.0,"bestAsk":844.98,"lastPrice":845.0,"currency":"AUD","instrument":"BTC","timestamp":1476242958,"volume24h":172.60804}
|
36
40
|
|
37
|
-
orderbook_request = Btcmrb::Marketdata.orderbook
|
38
41
|
client = Btcmrb.new
|
42
|
+
orderbook_request = Btcmrb::Marketdata.orderbook
|
39
43
|
client.send_request(orderbook_request)
|
40
44
|
# => {"currency":"AUD","instrument":"BTC","timestamp":1476243360,"asks":[[844.98,0.45077821],[845.0,2.7069457],[848.68,2.58512],[848.76,0.29745]],"bids":[[844.0,0.00489636],[840.21,0.060724],[840.16,0.1180803],[840.1,0.32130103]]}
|
41
45
|
|
42
|
-
trades_requst = Btcmrb::Marketdata.trades
|
43
46
|
client = Btcmrb.new
|
47
|
+
trades_requst = Btcmrb::Marketdata.trades
|
44
48
|
client.send_request(trades_requst)
|
45
49
|
# => [{"tid":4432702312,"amount":0.01959674,"price":845.0,"date":1378878093},{"tid":59861212129,"amount":1.21434000,"price":845.15,"date":1377840783}]
|
46
50
|
```
|
51
|
+
|
52
|
+
### Trading API
|
53
|
+
https://github.com/BTCMarkets/API/wiki/Trading-API
|
54
|
+
```ruby
|
55
|
+
client = Btcmrb.new
|
56
|
+
all_orders = Btcmrb::Order.all
|
57
|
+
# this one doesn't work yet, not sure why not - would you care to submit a pull request?
|
58
|
+
client.send_request(all_orders)
|
59
|
+
# => {"success":true,"errorCode":null,"errorMessage":null,"orders":[{"id":1003245675,"currency":"AUD","instrument":"BTC","orderSide":"Bid","ordertype":"Limit","creationTime":1378862733366,"status":"Placed","errorMessage":null,"price":13000000000,"volume":10000000,"openVolume":10000000,"clientRequestId":null,"trades":[]},{"id":4345675,"currency":"AUD","instrument":"BTC","orderSide":"Ask","ordertype":"Limit","creationTime":1378636912705,"status":"Fully Matched","errorMessage":null,"price":13000000000,"volume":10000000,"openVolume":0,"clientRequestId":null,"trades":[{"id":5345677,"creationTime":1378636913151,"description":null,"price":13000000000,"volume":10000000,"fee":100000}]}]}
|
60
|
+
```
|
61
|
+
|
62
|
+
|
63
|
+
|
47
64
|
## License
|
48
65
|
MIT - For terms refer to LICENSE.md
|
data/lib/btcmrb/client.rb
CHANGED
@@ -12,10 +12,7 @@ module Btcmrb
|
|
12
12
|
BASE_URI = 'https://api.btcmarkets.net'
|
13
13
|
include HTTParty
|
14
14
|
|
15
|
-
attr_accessor :base_uri, :timestamp
|
16
|
-
|
17
15
|
def initialize
|
18
|
-
@base_uri = BASE_URI
|
19
16
|
end
|
20
17
|
|
21
18
|
def send_request(object)
|
@@ -38,7 +35,8 @@ module Btcmrb
|
|
38
35
|
{ :method => object[:verb],
|
39
36
|
:authentication => object[:auth],
|
40
37
|
:timestamp => timestamp,
|
41
|
-
:encoded_signature => encoded_signature
|
38
|
+
:encoded_signature => encoded_signature,
|
39
|
+
:body => object[:body]
|
42
40
|
})
|
43
41
|
end
|
44
42
|
|
@@ -51,38 +49,39 @@ module Btcmrb
|
|
51
49
|
end
|
52
50
|
|
53
51
|
def format_request(options)
|
54
|
-
default = options[:uri] + "\n" + options[:timestamp] + "\n"
|
52
|
+
default = options[:uri] + "\n" + options[:timestamp] + "\n"#+ '{"currency":"AUD", "instrument":"BTC", "limit":"10"}'
|
55
53
|
unless options[:body].empty?
|
56
|
-
default =
|
54
|
+
default = default + options[:body].to_json.to_s
|
57
55
|
end
|
58
56
|
default
|
59
57
|
end
|
60
58
|
|
61
59
|
def send(uri, options={})
|
62
60
|
response = nil
|
63
|
-
|
61
|
+
headers = {
|
64
62
|
'Accept-Charset' => 'UTF-8',
|
65
63
|
'Accept' => 'application/json',
|
66
64
|
'Content-Type' => 'application/json',
|
67
65
|
'User-Agent' => "BTCMRB Ruby Gem v#{Btcmrb::VERSION}"
|
68
66
|
}
|
69
67
|
|
70
|
-
if options[:authentication]
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
68
|
+
if options[:authentication]
|
69
|
+
headers.merge!(
|
70
|
+
{ 'apikey' => BTCM_ACCESS_KEY ,
|
71
|
+
'signature' => options[:encoded_signature],
|
72
|
+
'timestamp' => options[:timestamp]
|
75
73
|
}).to_json
|
76
|
-
|
74
|
+
end
|
75
|
+
|
76
|
+
if options[:authentication] && options[:method] == "POST"
|
77
|
+
HTTParty.post(BASE_URI + uri, :headers => headers, :body => options[:body].to_json)
|
78
|
+
|
77
79
|
elsif options[:authentication] && options[:method] == "GET"
|
78
|
-
|
79
|
-
|
80
|
-
'signature' => options[:encoded_signature],
|
81
|
-
'timestamp' => options[:timestamp]
|
82
|
-
}).to_json
|
83
|
-
HTTParty.get(BASE_URI + uri, headers: default_headers)
|
80
|
+
HTTParty.get(BASE_URI + uri, :headers => headers)
|
81
|
+
|
84
82
|
else
|
85
|
-
|
83
|
+
HTTParty.get(BASE_URI + uri)
|
84
|
+
|
86
85
|
end
|
87
86
|
end
|
88
87
|
|
data/lib/btcmrb/order.rb
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
module Btcmrb
|
2
|
+
class Order
|
3
|
+
|
4
|
+
def self.all
|
5
|
+
# Documentation
|
6
|
+
# POST "/order/history"
|
7
|
+
# since parameter - an order id.
|
8
|
+
# {"currency":"AUD","instrument":"BTC","limit":10,"since":33434568724}
|
9
|
+
# {"success":true,"errorCode":null,"errorMessage":null,"orders":[{"id":1003245675,"currency":"AUD","instrument":"BTC","orderSide":"Bid","ordertype":"Limit","creationTime":1378862733366,"status":"Placed","errorMessage":null,"price":13000000000,"volume":10000000,"openVolume":10000000,"clientRequestId":null,"trades":[]},{"id":4345675,"currency":"AUD","instrument":"BTC","orderSide":"Ask","ordertype":"Limit","creationTime":1378636912705,"status":"Fully Matched","errorMessage":null,"price":13000000000,"volume":10000000,"openVolume":0,"clientRequestId":null,"trades":[{"id":5345677,"creationTime":1378636913151,"description":null,"price":13000000000,"volume":10000000,"fee":100000}]}]}
|
10
|
+
|
11
|
+
|
12
|
+
# Implementation
|
13
|
+
{
|
14
|
+
:uri => "/order/history",
|
15
|
+
:body => {:currency => "AUD", :instrument => "BTC", :limit => 10},
|
16
|
+
:verb => "POST",
|
17
|
+
:auth => true
|
18
|
+
}
|
19
|
+
end
|
20
|
+
|
21
|
+
# Similar to Index, but only returns open orders
|
22
|
+
def open
|
23
|
+
# Documentation
|
24
|
+
# POST "/order/open"
|
25
|
+
# {"currency":"AUD","instrument":"BTC","limit":10,"since":33434568724}
|
26
|
+
# {"success":true,"errorCode":null,"errorMessage":null,"orders":[{"id":1003245675,"currency":"AUD","instrument":"BTC","orderSide":"Bid","ordertype":"Limit","creationTime":1378862733366,"status":"Placed","errorMessage":null,"price":13000000000,"volume":10000000,"openVolume":10000000,"clientRequestId":null,"trades":[]},{"id":4345675,"currency":"AUD","instrument":"BTC","orderSide":"Ask","ordertype":"Limit","creationTime":1378636912705,"status":"Fully Matched","errorMessage":null,"price":13000000000,"volume":10000000,"openVolume":0,"clientRequestId":null,"trades":[{"id":5345677,"creationTime":1378636913151,"description":null,"price":13000000000,"volume":10000000,"fee":100000}]}]}
|
27
|
+
|
28
|
+
|
29
|
+
# Implementation
|
30
|
+
# {
|
31
|
+
# :uri => "/order/open",
|
32
|
+
# :body => {"currency":"AUD","instrument":"BTC","limit":10,"since":33434568724}, # Sample Body
|
33
|
+
# :verb => "POST",
|
34
|
+
# :auth => true
|
35
|
+
# }
|
36
|
+
end
|
37
|
+
|
38
|
+
def trade_history
|
39
|
+
# Documentation
|
40
|
+
# POST "/order/trade/history"
|
41
|
+
# since parameter - a trade id.
|
42
|
+
# {"currency":"AUD","instrument":"BTC","limit":10,"since":33434568724}
|
43
|
+
|
44
|
+
|
45
|
+
# Implementation
|
46
|
+
# {
|
47
|
+
# :uri => "/order/trade/history",
|
48
|
+
# :body => {"currency":"AUD","instrument":"BTC","limit":10,"since":33434568724}, # Sample Body
|
49
|
+
# :verb => "POST",
|
50
|
+
# :auth => true
|
51
|
+
# }
|
52
|
+
end
|
53
|
+
|
54
|
+
def show
|
55
|
+
# Documentation
|
56
|
+
# POST "/order/detail"
|
57
|
+
# {"orderIds":[6840125478]}
|
58
|
+
|
59
|
+
|
60
|
+
# Implementation
|
61
|
+
# {
|
62
|
+
# :uri => "/order/detail",
|
63
|
+
# :body => {"orderIds":[6840125478]}, # Sample Body
|
64
|
+
# :verb => "POST",
|
65
|
+
# :auth => true
|
66
|
+
# }
|
67
|
+
end
|
68
|
+
|
69
|
+
def create
|
70
|
+
# Documentation
|
71
|
+
# POST "/order/create"
|
72
|
+
# The clientRequestId is not currently used but must be specified. Any string is valid.
|
73
|
+
# Price of $130 = 13000000000 (i.e x 100000000)
|
74
|
+
# Volume of 1 BTC = 100000000 (i.e x 100000000)
|
75
|
+
# {"currency":"AUD","instrument":"BTC","price":13000000000,"volume":10000000,"orderSide":"Bid","ordertype":"Limit","clientRequestId":"abc-cdf-1000"}
|
76
|
+
# => {"success":true,"errorCode":null,"errorMessage":null,"id":100,"clientRequestId":"abc-cdf-1000"}
|
77
|
+
# => {"success":false,"errorCode":3,"errorMessage":"Invalid argument.","id":0,"clientRequestId":"abc-cdf-1000"}
|
78
|
+
|
79
|
+
# Implementation
|
80
|
+
# {
|
81
|
+
# :uri => "/order/create",
|
82
|
+
# :body => {"currency":"AUD","instrument":"BTC","price":13000000000,"volume":10000000,"orderSide":"Bid","ordertype":"Limit","clientRequestId":"abc-cdf-1000"}, # Sample Body
|
83
|
+
# :verb => "POST",
|
84
|
+
# :auth => true
|
85
|
+
# }
|
86
|
+
end
|
87
|
+
|
88
|
+
def cancel
|
89
|
+
# Documentation
|
90
|
+
# POST "/order/cancel"
|
91
|
+
# {"orderIds":[6840125478]}
|
92
|
+
# => {"success":true,"errorCode":null,"errorMessage":null,"responses":[{"success":false,"errorCode":3,"errorMessage":"order does not exist.","id":6840125478}]}
|
93
|
+
|
94
|
+
# Implementation
|
95
|
+
# {
|
96
|
+
# :uri => "/order/cancel",
|
97
|
+
# :body => {"orderIds":[6840125478]}, # Sample Body
|
98
|
+
# :verb => "POST",
|
99
|
+
# :auth => true
|
100
|
+
# }
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
104
|
+
end
|
data/lib/btcmrb/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: btcmrb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Tennant
|
@@ -37,6 +37,7 @@ files:
|
|
37
37
|
- lib/btcmrb/account.rb
|
38
38
|
- lib/btcmrb/client.rb
|
39
39
|
- lib/btcmrb/marketdata.rb
|
40
|
+
- lib/btcmrb/order.rb
|
40
41
|
- lib/btcmrb/version.rb
|
41
42
|
homepage: https://github.com/tennantje/btcmrb
|
42
43
|
licenses:
|