bitfex 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +2 -0
- data/.travis.yml +44 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +33 -0
- data/LICENSE +21 -0
- data/README.md +25 -0
- data/Rakefile +8 -0
- data/bitfex.gemspec +20 -0
- data/lib.rb +113 -0
- data/lib/bitfex.rb +6 -0
- data/lib/bitfex/api.rb +116 -0
- data/lib/bitfex/errors.rb +4 -0
- data/lib/bitfex/version.rb +8 -0
- data/test/test_bitfex.rb +153 -0
- data/test/test_helper.rb +2 -0
- metadata +89 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 48dee944d055d0fc34b02b5274318b5a29e8ba90
|
4
|
+
data.tar.gz: ce71b2da754d0fd723f43ecbb13bda6de494ea68
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b7a21692f5e32252b1d5532d937b2b7b899cf36a24d281859a1d17016ae7f26256e69fd530829e770677bb00b6df079446a02fd6789077a625b25fe0537ab668
|
7
|
+
data.tar.gz: 4a502dbc78d54f8979274a3bdbfee6690b91753e9dfb88fc1ad1b430d5be6088b68b9a7efdf6551575433d2ef75df1cace0c31f46042578781d6efac7195424d
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# Available ruby versions: http://rubies.travis-ci.org/
|
2
|
+
|
3
|
+
language: ruby
|
4
|
+
|
5
|
+
os:
|
6
|
+
- linux
|
7
|
+
- osx
|
8
|
+
|
9
|
+
rvm:
|
10
|
+
- "2.0.0"
|
11
|
+
- "2.1" # latest 2.1.x
|
12
|
+
- "2.2.5"
|
13
|
+
- "2.3.3"
|
14
|
+
- "2.4.0"
|
15
|
+
- "ruby-head"
|
16
|
+
- "jruby-9.0.5.0"
|
17
|
+
- "jruby-9.1.5.0"
|
18
|
+
- "jruby-head"
|
19
|
+
|
20
|
+
cache: bundler
|
21
|
+
|
22
|
+
script:
|
23
|
+
- bundle exec rake test
|
24
|
+
|
25
|
+
before_install:
|
26
|
+
- gem update --system
|
27
|
+
# bundler installation needed for jruby-head
|
28
|
+
# https://github.com/travis-ci/travis-ci/issues/5861
|
29
|
+
- gem install bundler
|
30
|
+
|
31
|
+
# Travis OS X support is pretty janky. These are some hacks to include tests
|
32
|
+
# only on versions that actually work.
|
33
|
+
# (last tested: 2016-11)
|
34
|
+
matrix:
|
35
|
+
# exclude: {}
|
36
|
+
# include: {}
|
37
|
+
|
38
|
+
allow_failures:
|
39
|
+
- rvm: 'ruby-head'
|
40
|
+
|
41
|
+
# return results as soon as mandatory versions are done
|
42
|
+
fast_finish: true
|
43
|
+
|
44
|
+
sudo: false
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
bitfex (1.0.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
addressable (2.5.2)
|
10
|
+
public_suffix (>= 2.0.2, < 4.0)
|
11
|
+
crack (0.4.3)
|
12
|
+
safe_yaml (~> 1.0.0)
|
13
|
+
hashdiff (0.3.7)
|
14
|
+
minitest (5.11.3)
|
15
|
+
public_suffix (3.0.2)
|
16
|
+
rake (12.3.0)
|
17
|
+
safe_yaml (1.0.4)
|
18
|
+
webmock (2.3.2)
|
19
|
+
addressable (>= 2.3.6)
|
20
|
+
crack (>= 0.3.2)
|
21
|
+
hashdiff
|
22
|
+
|
23
|
+
PLATFORMS
|
24
|
+
ruby
|
25
|
+
|
26
|
+
DEPENDENCIES
|
27
|
+
bitfex!
|
28
|
+
minitest (~> 5.11)
|
29
|
+
rake
|
30
|
+
webmock (~> 2.0)
|
31
|
+
|
32
|
+
BUNDLED WITH
|
33
|
+
1.13.6
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 BitFex.Trade
|
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 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,
|
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 THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# BitFex API for ruby
|
2
|
+
|
3
|
+
Simple implementation of BitFex.Trade API for ruby.
|
4
|
+
|
5
|
+
# Documentation
|
6
|
+
|
7
|
+
## Init
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
require 'bitfex'
|
11
|
+
|
12
|
+
client = Bitfex::Api.new()
|
13
|
+
# make auth
|
14
|
+
client.auth('user@example.com', 'password')
|
15
|
+
# call API methods
|
16
|
+
client.balances # => {'BTC' => 15.0}
|
17
|
+
```
|
18
|
+
|
19
|
+
## Methods
|
20
|
+
|
21
|
+
Methods documentation could be found in source =/
|
22
|
+
|
23
|
+
# Legal
|
24
|
+
|
25
|
+
Released under the MIT License: https://opensource.org/licenses/MIT
|
data/Rakefile
ADDED
data/bitfex.gemspec
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require './lib/bitfex/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = 'bitfex'
|
5
|
+
s.version = Bitfex::VERSION
|
6
|
+
s.date = '2018-02-25'
|
7
|
+
s.description = 'API wrapper for BitFex.Trade cryptocurrency stock exchange'
|
8
|
+
s.summary = 'API wrapper for BitFex.Trade'
|
9
|
+
s.authors = ['BitFex.Trade']
|
10
|
+
s.email = 'support@bitfex.trade'
|
11
|
+
s.files = `git ls-files -z`.split("\0")
|
12
|
+
s.test_files = `git ls-files -z test/`.split("\0")
|
13
|
+
s.homepage = 'https://bitfex.trade'
|
14
|
+
s.extra_rdoc_files = ['README.md']
|
15
|
+
s.license = 'MIT'
|
16
|
+
s.required_ruby_version = '>= 2.0.0'
|
17
|
+
|
18
|
+
s.add_development_dependency('webmock', '~> 2.0')
|
19
|
+
s.add_development_dependency('minitest', '~> 5.11')
|
20
|
+
end
|
data/lib.rb
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class BitfexApi
|
4
|
+
class AuthError < StandardError; end
|
5
|
+
|
6
|
+
# @param server_url [String] URL of the main server
|
7
|
+
def initialize(server_url: "https://bitfex.trade")
|
8
|
+
@_server_url = server_url
|
9
|
+
end
|
10
|
+
|
11
|
+
# @return [String] URL of the server
|
12
|
+
def server_url
|
13
|
+
@_server_url
|
14
|
+
end
|
15
|
+
|
16
|
+
# @param url [String] set URL of the server
|
17
|
+
def server_url=(url)
|
18
|
+
@_server_url = url
|
19
|
+
end
|
20
|
+
|
21
|
+
# Get token for API operations
|
22
|
+
# @param email [String] email
|
23
|
+
# @param password [String] password
|
24
|
+
def auth(email, password)
|
25
|
+
body = request_post("/auth", auth: { email: email, password: password })
|
26
|
+
return @token = body["jwt"] if body["jwt"]
|
27
|
+
raise AuthError.new
|
28
|
+
end
|
29
|
+
|
30
|
+
# Return account balances
|
31
|
+
# @return [Hash<String, Fixnum>] balances
|
32
|
+
def balances
|
33
|
+
response = request_get("/api/v1/user")
|
34
|
+
raise StandardError.new(response["errors"].to_json) unless response["success"]
|
35
|
+
response["balances"]
|
36
|
+
end
|
37
|
+
|
38
|
+
# Return list of orders for all pairs
|
39
|
+
# @return [Array<Hash>] list of orders (id, pair, amount, price, operation, completed, updated)
|
40
|
+
def orders_list
|
41
|
+
response = request_get("/api/v1/orders")
|
42
|
+
raise StandardError.new(response["errors"].to_json) unless response["success"]
|
43
|
+
response["orders"]
|
44
|
+
end
|
45
|
+
|
46
|
+
# Return list of my orders
|
47
|
+
# @return [Array<Hash>] list of my orders (id, pair, amount, price, operation, completed, updated)
|
48
|
+
def my_orders
|
49
|
+
response = request_get("/api/v1/orders/my")
|
50
|
+
raise StandardError.new(response["errors"].to_json) unless response["success"]
|
51
|
+
response["orders"]
|
52
|
+
end
|
53
|
+
|
54
|
+
# Delete order by id
|
55
|
+
# @param id [Fixnum] order ID
|
56
|
+
# @return TrueClass
|
57
|
+
# @raise StandardError(error json) if response not success
|
58
|
+
def delete_order(id)
|
59
|
+
response = request_delete("/api/v1/orders/#{id}")
|
60
|
+
raise StandardError.new(response["errors"].to_json) unless response["success"]
|
61
|
+
true
|
62
|
+
end
|
63
|
+
|
64
|
+
# Create new order
|
65
|
+
# @param operation [String] operation - one of (buy/sell)
|
66
|
+
# @param pair [String] pair (like BTC_RUR)
|
67
|
+
# @param amount [Decimal] amount in normal units (roubles or bitcoins)
|
68
|
+
# @param price [Decimal] price in normal units (roubles or bitcoins)
|
69
|
+
def create_order(operation, pair, amount, price)
|
70
|
+
response = request_post(
|
71
|
+
"/api/v1/orders",
|
72
|
+
order: {
|
73
|
+
pair: pair,
|
74
|
+
operation: operation,
|
75
|
+
amount: amount,
|
76
|
+
price: price
|
77
|
+
}
|
78
|
+
)
|
79
|
+
raise StandardError.new(response["error"].to_json) unless response["success"]
|
80
|
+
|
81
|
+
true
|
82
|
+
end
|
83
|
+
|
84
|
+
attr_reader :btc_rate, :token, :my_orders_list, :balance
|
85
|
+
|
86
|
+
private
|
87
|
+
|
88
|
+
def request_post(endpoint, body)
|
89
|
+
request(endpoint, Net::HTTP::Post, body)
|
90
|
+
end
|
91
|
+
|
92
|
+
def request_delete(endpoint, body = nil)
|
93
|
+
request(endpoint, Net::HTTP::Delete, body)
|
94
|
+
end
|
95
|
+
|
96
|
+
def request_get(endpoint)
|
97
|
+
request(endpoint, Net::HTTP::Get)
|
98
|
+
end
|
99
|
+
|
100
|
+
def request(endpoint, klass, body = nil)
|
101
|
+
url = @_server_url + endpoint
|
102
|
+
uri = URI.parse(url)
|
103
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
104
|
+
http.use_ssl = uri.port == 443
|
105
|
+
|
106
|
+
request = klass.new(uri.request_uri, "Content-Type" => "application/json")
|
107
|
+
|
108
|
+
request.add_field("Authorization", "Bearer #{token}") if token
|
109
|
+
request.body = JSON.dump(body) if body
|
110
|
+
response = http.request(request)
|
111
|
+
JSON.parse(response.body || "{}")
|
112
|
+
end
|
113
|
+
end
|
data/lib/bitfex.rb
ADDED
data/lib/bitfex/api.rb
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'net/http'
|
3
|
+
|
4
|
+
module Bitfex
|
5
|
+
class Api
|
6
|
+
attr_accessor :token
|
7
|
+
|
8
|
+
# @param server_url [String] URL of the main server
|
9
|
+
def initialize(server_url: 'https://bitfex.trade')
|
10
|
+
@_server_url = server_url
|
11
|
+
end
|
12
|
+
|
13
|
+
# @return [String] server url
|
14
|
+
def server_url
|
15
|
+
@_server_url
|
16
|
+
end
|
17
|
+
|
18
|
+
# @param url [String] set URL of the server
|
19
|
+
def server_url=(url)
|
20
|
+
@_server_url = url
|
21
|
+
end
|
22
|
+
|
23
|
+
# Get token for API operations
|
24
|
+
# @param email [String] email
|
25
|
+
# @param password [String] password
|
26
|
+
def auth(email, password)
|
27
|
+
body = request_post('/auth', auth: { email: email, password: password })
|
28
|
+
return @token = body['jwt'] if body['jwt']
|
29
|
+
raise AuthError.new
|
30
|
+
end
|
31
|
+
|
32
|
+
# Return account balances
|
33
|
+
# @return [Hash<String, Fixnum>] balances
|
34
|
+
def balances
|
35
|
+
response = request_get('/api/v1/user')
|
36
|
+
raise ApiError.new(response['errors'].to_json) unless response['success']
|
37
|
+
response['balances']
|
38
|
+
end
|
39
|
+
|
40
|
+
# Return list of orders for all pairs
|
41
|
+
# @return [Array<Hash>] list of orders (id, pair, amount, price, operation, completed, updated)
|
42
|
+
def orders_list
|
43
|
+
response = request_get('/api/v1/orders')
|
44
|
+
raise ApiError.new(response['errors'].to_json) unless response['success']
|
45
|
+
response['orders']
|
46
|
+
end
|
47
|
+
|
48
|
+
# Return list of my orders
|
49
|
+
# @return [Array<Hash>] list of my orders (id, pair, amount, price, operation, completed, updated)
|
50
|
+
def my_orders
|
51
|
+
response = request_get('/api/v1/orders/my')
|
52
|
+
raise ApiError.new(response['errors'].to_json) unless response['success']
|
53
|
+
response['orders']
|
54
|
+
end
|
55
|
+
|
56
|
+
# Delete order by id
|
57
|
+
# @param id [Fixnum] order ID
|
58
|
+
# @return [TrueClass]
|
59
|
+
# @raise ApiError(error_json) if response not success
|
60
|
+
def delete_order(id)
|
61
|
+
response = request_delete("/api/v1/orders/#{id}")
|
62
|
+
raise ApiError.new(response['errors'].to_json) unless response['success']
|
63
|
+
true
|
64
|
+
end
|
65
|
+
|
66
|
+
# Create new order
|
67
|
+
# @param operation [String] operation - one of (buy/sell)
|
68
|
+
# @param pair [String] pair (for example: BTC_RUR)
|
69
|
+
# @param amount [Decimal] amount in normal units (roubles or bitcoins)
|
70
|
+
# @param price [Decimal] price in normal units (roubles or bitcoins)
|
71
|
+
# @return [TrueClass]
|
72
|
+
# @raise ApiError(error_json) if response not success
|
73
|
+
def create_order(operation, pair, amount, price)
|
74
|
+
response = request_post(
|
75
|
+
'/api/v1/orders',
|
76
|
+
order: {
|
77
|
+
pair: pair,
|
78
|
+
operation: operation,
|
79
|
+
amount: amount,
|
80
|
+
price: price
|
81
|
+
}
|
82
|
+
)
|
83
|
+
raise ApiError.new(response['error'].to_json) unless response['success']
|
84
|
+
|
85
|
+
true
|
86
|
+
end
|
87
|
+
|
88
|
+
private
|
89
|
+
|
90
|
+
def request_post(endpoint, body)
|
91
|
+
request(endpoint, Net::HTTP::Post, body)
|
92
|
+
end
|
93
|
+
|
94
|
+
def request_delete(endpoint, body = nil)
|
95
|
+
request(endpoint, Net::HTTP::Delete, body)
|
96
|
+
end
|
97
|
+
|
98
|
+
def request_get(endpoint)
|
99
|
+
request(endpoint, Net::HTTP::Get)
|
100
|
+
end
|
101
|
+
|
102
|
+
def request(endpoint, klass, body = nil)
|
103
|
+
url = @_server_url + endpoint
|
104
|
+
uri = URI.parse(url)
|
105
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
106
|
+
http.use_ssl = uri.port == 443
|
107
|
+
|
108
|
+
request = klass.new(uri.request_uri, 'Content-Type' => 'application/json')
|
109
|
+
|
110
|
+
request.add_field('Authorization', "Bearer #{token}") if token
|
111
|
+
request.body = JSON.dump(body) if body
|
112
|
+
response = http.request(request)
|
113
|
+
JSON.parse(response.body || '{}')
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
data/test/test_bitfex.rb
ADDED
@@ -0,0 +1,153 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
require 'bitfex'
|
4
|
+
|
5
|
+
class BitfexTest < Minitest::Test
|
6
|
+
def test_initialize
|
7
|
+
client = Bitfex::Api.new(server_url: 'http://localhost/')
|
8
|
+
assert_equal 'http://localhost/', client.server_url
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_default_server_url
|
12
|
+
client = Bitfex::Api.new
|
13
|
+
assert_equal 'https://bitfex.trade', client.server_url
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_set_server_url
|
17
|
+
client = Bitfex::Api.new
|
18
|
+
client.server_url = 'https://google.com/'
|
19
|
+
assert_equal 'https://google.com/', client.server_url
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_auth_success
|
23
|
+
stub_request(:post, 'https://bitfex.trade/auth')
|
24
|
+
.with(body: '{"auth":{"email":"user@example.com","password":"123"}}')
|
25
|
+
.to_return(status: 200, body: '{"jwt":"token"}')
|
26
|
+
|
27
|
+
client = Bitfex::Api.new
|
28
|
+
assert_equal 'token', client.auth('user@example.com', '123')
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_auth_failure
|
32
|
+
stub_request(:post, 'https://bitfex.trade/auth')
|
33
|
+
.with(body: '{"auth":{"email":"user@example.com","password":"123"}}')
|
34
|
+
.to_return(status: 404, body: '{}')
|
35
|
+
|
36
|
+
assert_raises Bitfex::AuthError do
|
37
|
+
client = Bitfex::Api.new
|
38
|
+
client.auth('user@example.com', '123')
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_balances_success
|
43
|
+
stub_request(:get, "https://bitfex.trade/api/v1/user")
|
44
|
+
.with(headers: { 'Authorization' => 'Bearer 123' })
|
45
|
+
.to_return(status: 200, body: '{"success":true,"balances":{"BTC":10.5}}')
|
46
|
+
|
47
|
+
client = Bitfex::Api.new
|
48
|
+
client.token = '123'
|
49
|
+
assert_equal({'BTC' => 10.5}, client.balances)
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_balances_failure
|
53
|
+
stub_request(:get, "https://bitfex.trade/api/v1/user")
|
54
|
+
.with(headers: { 'Authorization' => 'Bearer 123' })
|
55
|
+
.to_return(status: 403, body: '{"success":false,"errors":["TEST"]}')
|
56
|
+
|
57
|
+
assert_raises Bitfex::ApiError do
|
58
|
+
client = Bitfex::Api.new
|
59
|
+
client.token = '123'
|
60
|
+
client.balances
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_orders_list_success
|
65
|
+
stub_request(:get, "https://bitfex.trade/api/v1/orders")
|
66
|
+
.with(headers: { 'Authorization' => 'Bearer 123' })
|
67
|
+
.to_return(status: 200, body: '{"success":true,"orders":[{"id":1}]}')
|
68
|
+
|
69
|
+
client = Bitfex::Api.new
|
70
|
+
client.token = '123'
|
71
|
+
assert_equal([{'id' => 1}], client.orders_list)
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_orders_list_faulure
|
75
|
+
stub_request(:get, "https://bitfex.trade/api/v1/orders")
|
76
|
+
.with(headers: { 'Authorization' => 'Bearer 123' })
|
77
|
+
.to_return(status: 403, body: '{"success":false,"errors":["TEST"]}')
|
78
|
+
|
79
|
+
assert_raises Bitfex::ApiError do
|
80
|
+
client = Bitfex::Api.new
|
81
|
+
client.token = '123'
|
82
|
+
client.orders_list
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_my_orders_success
|
87
|
+
stub_request(:get, "https://bitfex.trade/api/v1/orders/my")
|
88
|
+
.with(headers: { 'Authorization' => 'Bearer 123' })
|
89
|
+
.to_return(status: 200, body: '{"success":true,"orders":[{"id":1}]}')
|
90
|
+
|
91
|
+
client = Bitfex::Api.new
|
92
|
+
client.token = '123'
|
93
|
+
assert_equal([{'id' => 1}], client.my_orders)
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_my_orders_faulure
|
97
|
+
stub_request(:get, "https://bitfex.trade/api/v1/orders/my")
|
98
|
+
.with(headers: { 'Authorization' => 'Bearer 123' })
|
99
|
+
.to_return(status: 403, body: '{"success":false,"errors":["TEST"]}')
|
100
|
+
|
101
|
+
assert_raises Bitfex::ApiError do
|
102
|
+
client = Bitfex::Api.new
|
103
|
+
client.token = '123'
|
104
|
+
client.my_orders
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_delete_order_success
|
109
|
+
stub_request(:delete, 'https://bitfex.trade/api/v1/orders/1')
|
110
|
+
.with(headers: { 'Authorization' => 'Bearer 123' })
|
111
|
+
.to_return(status: 200, body: '{"success":true}')
|
112
|
+
|
113
|
+
client = Bitfex::Api.new
|
114
|
+
client.token = '123'
|
115
|
+
assert_equal true, client.delete_order(1)
|
116
|
+
end
|
117
|
+
|
118
|
+
def test_delete_order_failure
|
119
|
+
stub_request(:delete, 'https://bitfex.trade/api/v1/orders/1')
|
120
|
+
.with(headers: { 'Authorization' => 'Bearer 123' })
|
121
|
+
.to_return(status: 400, body: '{"success":false,"errors":["TEST"]}')
|
122
|
+
|
123
|
+
assert_raises Bitfex::ApiError do
|
124
|
+
client = Bitfex::Api.new
|
125
|
+
client.token = '123'
|
126
|
+
client.delete_order(1)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
def test_create_order_success
|
131
|
+
stub_request(:post, 'https://bitfex.trade/api/v1/orders')
|
132
|
+
.with(body: "{\"order\":{\"pair\":\"BTC_RUR\",\"operation\":\"buy\",\"amount\":1.0,\"price\":60000.0}}",
|
133
|
+
headers: { 'Authorization' => 'Bearer 123' })
|
134
|
+
.to_return(status: 200, body: '{"success":true}')
|
135
|
+
|
136
|
+
client = Bitfex::Api.new
|
137
|
+
client.token = '123'
|
138
|
+
assert_equal true, client.create_order(:buy, 'BTC_RUR', 1.0, 600_00.0)
|
139
|
+
end
|
140
|
+
|
141
|
+
def test_create_order_failure
|
142
|
+
stub_request(:post, 'https://bitfex.trade/api/v1/orders')
|
143
|
+
.with(body: "{\"order\":{\"pair\":\"BTC_RUR\",\"operation\":\"buy\",\"amount\":1.0,\"price\":60000.0}}",
|
144
|
+
headers: { 'Authorization' => 'Bearer 123' })
|
145
|
+
.to_return(status: 403, body: '{"success":false,"errors":["TEST"]}')
|
146
|
+
|
147
|
+
assert_raises Bitfex::ApiError do
|
148
|
+
client = Bitfex::Api.new
|
149
|
+
client.token = '123'
|
150
|
+
client.create_order(:buy, 'BTC_RUR', 1.0, 600_00.0)
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bitfex
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- BitFex.Trade
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-02-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: webmock
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: minitest
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '5.11'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '5.11'
|
41
|
+
description: API wrapper for BitFex.Trade cryptocurrency stock exchange
|
42
|
+
email: support@bitfex.trade
|
43
|
+
executables: []
|
44
|
+
extensions: []
|
45
|
+
extra_rdoc_files:
|
46
|
+
- README.md
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- ".travis.yml"
|
50
|
+
- Gemfile
|
51
|
+
- Gemfile.lock
|
52
|
+
- LICENSE
|
53
|
+
- README.md
|
54
|
+
- Rakefile
|
55
|
+
- bitfex.gemspec
|
56
|
+
- lib.rb
|
57
|
+
- lib/bitfex.rb
|
58
|
+
- lib/bitfex/api.rb
|
59
|
+
- lib/bitfex/errors.rb
|
60
|
+
- lib/bitfex/version.rb
|
61
|
+
- test/test_bitfex.rb
|
62
|
+
- test/test_helper.rb
|
63
|
+
homepage: https://bitfex.trade
|
64
|
+
licenses:
|
65
|
+
- MIT
|
66
|
+
metadata: {}
|
67
|
+
post_install_message:
|
68
|
+
rdoc_options: []
|
69
|
+
require_paths:
|
70
|
+
- lib
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 2.0.0
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
requirements: []
|
82
|
+
rubyforge_project:
|
83
|
+
rubygems_version: 2.5.2.1
|
84
|
+
signing_key:
|
85
|
+
specification_version: 4
|
86
|
+
summary: API wrapper for BitFex.Trade
|
87
|
+
test_files:
|
88
|
+
- test/test_bitfex.rb
|
89
|
+
- test/test_helper.rb
|