mexbt 0.0.4 → 0.0.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b5d3d42c18c0d316d920d381e853d2e2767cb141
4
- data.tar.gz: a0508b7182b66874add7b2af78c764014cdcb5d5
3
+ metadata.gz: 2fd935693905edbab1bda0eec07c1dc337446288
4
+ data.tar.gz: 8e19ba7bccb2585c3805a7df905ad845590d28ae
5
5
  SHA512:
6
- metadata.gz: 1da58e0313428224f94604448d3af8d4a7488c2048ee101c141ecd92c17998afa2a1304275213675772e4fcef2ff5d7a5a136b0a7afc52b86eb75e50486c6b28
7
- data.tar.gz: c9a6c57a86e57f64b2037482350a72688f5dc60fcb40387acf2ec1070c4e2b266c30741a7b5aeaa34db797178157fea289247f2b921b29d5f946efd47cbb47cd
6
+ metadata.gz: a689255dbe126cba0dac1228e8eac535ea3a3f68dea148a1ec35638e701bf82467abdba516bb6e7f3492d695c6a54a6415117a0b2c262e0a78faabff8f67dff2
7
+ data.tar.gz: 74cc762b1724b3da51f8e8669522de45495644d1d2f65e1a4f629044b2f7e671661da7e1a1d313def0932c47eab2c59ab1608a7777b8ac6aab9932878c8e8f7a
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mexbt (0.0.3)
4
+ mexbt (0.0.4)
5
5
  activesupport (>= 4.1.8)
6
6
  rest_client (= 1.8.2)
7
7
 
@@ -17,7 +17,7 @@ GEM
17
17
  diff-lcs (1.2.5)
18
18
  i18n (0.6.11)
19
19
  json (1.8.1)
20
- minitest (5.4.3)
20
+ minitest (5.5.0)
21
21
  netrc (0.7.9)
22
22
  rake (10.3.2)
23
23
  rest_client (1.8.2)
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2014 williamcoates
1
+ Copyright (c) 2014 Exchange of the Americas SAPI de CV
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  This is a lightweight ruby client for the [meXBT](https://mexbt.com) exchange API. It doesn't try and do anything clever with the JSON response from the API, it simply
4
4
  returns it as-is.
5
5
 
6
- # Install
6
+ ## Install
7
7
 
8
8
  If using bundler simply this to your Gemfile:
9
9
 
@@ -11,11 +11,11 @@ If using bundler simply this to your Gemfile:
11
11
 
12
12
  And run `bundle install` of course.
13
13
 
14
- # Ruby version
14
+ ## Ruby version
15
15
 
16
16
  You need to be using Ruby 2.1 or higher.
17
17
 
18
- # Public API
18
+ ## Public API
19
19
 
20
20
  You can access all the Public API functions with zero configuration. By default they will use the 'BTCMXN' currency pair.
21
21
 
@@ -34,10 +34,10 @@ Or alternatively you can set it per call:
34
34
 
35
35
  Mexbt.ticker(currency_pair: 'BTCUSD')
36
36
 
37
- # Private API
37
+ ## Private API
38
38
 
39
39
 
40
- ## Configuration
40
+ ### Configuration
41
41
 
42
42
  You need to generate an API key pair at https://mexbt.com/api/keys. However if you want to get started quickly we recommend having a play in the sandbox first, see the 'Sandbox' section below.
43
43
 
@@ -56,7 +56,7 @@ You need to generate an API key pair at https://mexbt.com/api/keys. However if y
56
56
  Mexbt::Orders.cancel(id: 123, currency_pair: 'btcmxn')
57
57
  Mexbt::Orders.cancel_all() # Cancel all orders for the default currency pair
58
58
 
59
- ## Account functions
59
+ ### Account functions
60
60
 
61
61
  Mexbt::Account.balance
62
62
  Mexbt::Account.trades
@@ -64,7 +64,7 @@ You need to generate an API key pair at https://mexbt.com/api/keys. However if y
64
64
  Mexbt::Account.deposit_addresses
65
65
  Mexbt::Account.withdraw(amount: 1, currency: :btc, address: 'xxx') Mexbt::Account.info # Fetches your user info
66
66
 
67
- ## Sandbox
67
+ ### Sandbox
68
68
 
69
69
  It's a good idea to first play with the API in the sandbox, that way you don't need any real money to start trading with the API. Just make sure you configure `sandbox = true`.
70
70
 
@@ -72,7 +72,7 @@ You can register a sandbox account at https://sandbox.mexbt.com/en/register. It
72
72
 
73
73
  Your sandbox account will automatically have a bunch of cash to play with.
74
74
 
75
- # API documentation
75
+ ## API documentation
76
76
 
77
77
  You can find API docs for the Public API at http://docs.mexbtpublicapi.apiary.io
78
78
 
@@ -81,7 +81,7 @@ API docs for the Private API are at http://docs.mexbtprivateapi.apiary.io
81
81
  There are also docs for the Private API sandbox at http://docs.mexbtprivateapisandbox.apiary.io
82
82
 
83
83
 
84
- # TODO
84
+ ## TODO
85
85
 
86
86
  Mock out web calls with WebMock so that specs don't break everytime sandbox db is cleaned.
87
87
 
data/lib/mexbt/client.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require 'rest_client'
2
- require 'active_support'
2
+ require 'active_support/core_ext/hash/indifferent_access'
3
3
 
4
4
  module Mexbt
5
5
  module Client
@@ -39,5 +39,10 @@ module Mexbt
39
39
  raise json_response[:rejectReason]
40
40
  end
41
41
  end
42
+
43
+ def call_data(path)
44
+ res = Request.execute(method: :get, url: "https://data.mexbt.com/#{path}", ssl_version: SSL_VERSION)
45
+ ActiveSupport::HashWithIndifferentAccess.new(JSON.parse(res))
46
+ end
42
47
  end
43
48
  end
data/lib/mexbt/orders.rb CHANGED
@@ -5,6 +5,10 @@ module Mexbt
5
5
  include Mexbt::Private
6
6
 
7
7
  def create(amount:, price: nil, currency_pair: Mexbt.currency_pair, side: :buy, type: :market)
8
+ # Horribly hack because sandbox only accepts 6 decimal places thanks to AP
9
+ if Mexbt.sandbox
10
+ amount = BigDecimal.new(amount, 15).round(6).to_f
11
+ end
8
12
  type =
9
13
  case type
10
14
  when :market, 1
data/lib/mexbt/public.rb CHANGED
@@ -16,7 +16,21 @@ module Mexbt
16
16
  end
17
17
 
18
18
  def order_book(currency_pair: Mexbt.currency_pair)
19
- call("order-book", { productPair: currency_pair })
19
+ begin
20
+ call("order-book", { productPair: currency_pair })
21
+ rescue RestClient::RequestFailed => e
22
+ if currency_pair.to_s.downcase === "btcmxn"
23
+ data_order_book = call_data("order-book/btcmxn")
24
+ mapper = Proc.new do |o|
25
+ {px: o.first, qty: o.last}
26
+ end
27
+ data_order_book[:asks] = data_order_book[:asks].map(&mapper)
28
+ data_order_book[:bids] = data_order_book[:bids].map(&mapper)
29
+ data_order_book
30
+ else
31
+ raise e
32
+ end
33
+ end
20
34
  end
21
35
 
22
36
  alias :orders :order_book
data/lib/mexbt/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Mexbt
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -29,8 +29,8 @@ describe Mexbt::Private do
29
29
 
30
30
  before do
31
31
  Mexbt.configure do |c|
32
- c.public_key = "8a742b8ecaff21784d8d788119bded0e"
33
- c.private_key = "e989fb9c1905a4fbd0a4bfe84230c9bc"
32
+ c.public_key = "56dd4872e23f9e326c0184552791f6f7"
33
+ c.private_key = "23a9814d6cf3cbb641bc41eb0b2115de"
34
34
  c.user_id = "test@mexbt.com"
35
35
  c.sandbox = true
36
36
  end
@@ -62,6 +62,12 @@ describe Mexbt::Private do
62
62
  expect(res["serverOrderId"]).to be_a(Fixnum)
63
63
  end
64
64
 
65
+ it "allows creating orders with 8 decimal places" do
66
+ res = Mexbt::Orders.create(amount: 0.12345678, currency_pair: "BTCUSD")
67
+ expect(res["isAccepted"]).to be true
68
+ expect(res["serverOrderId"]).to be_a(Fixnum)
69
+ end
70
+
65
71
  it "allows creating limit orders" do
66
72
  res = Mexbt::Orders.create(type: :limit, price: 100, amount: 0.1234, currency_pair: "BTCUSD")
67
73
  expect(res["isAccepted"]).to be true
@@ -22,6 +22,20 @@ describe Mexbt do
22
22
  expect(res["trades"]).to eql([])
23
23
  end
24
24
 
25
+ it "fetches btcmxn order book data from data API if AP API down" do
26
+ expect(Mexbt).to receive(:call).with("order-book", { productPair: :btcmxn }).and_raise("Boom")
27
+ order_book = Mexbt.order_book
28
+ expect(order_book["asks"].first["px"]).to be_a_kind_of(Numeric)
29
+ expect(order_book["asks"].first["qty"]).to be_a_kind_of(Numeric)
30
+ expect(order_book["bids"].first["px"]).to be_a_kind_of(Numeric)
31
+ expect(order_book["bids"].first["qty"]).to be_a_kind_of(Numeric)
32
+ end
33
+
34
+ it "simulates market order using data api data if AP API down" do
35
+ expect(Mexbt).to receive(:call).with("order-book", { productPair: :btcmxn }).and_raise("Boom")
36
+ expect(Mexbt.simulate_market_order(second_currency: 100)["first_amount"]).to be_a_kind_of(Numeric)
37
+ end
38
+
25
39
  context "simulating market orders" do
26
40
 
27
41
  before do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mexbt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - williamcoates
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-18 00:00:00.000000000 Z
11
+ date: 2015-01-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport