binance-ruby 0.7 → 0.8

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
  SHA256:
3
- metadata.gz: e38e2e3ef1f8051d6ddda7a07dfee0e35de604ba8985861ef6041d0841e127b6
4
- data.tar.gz: 9f147f98929be3d56108cc258c5533e9469ae153c0659faa0319358e63e0636d
3
+ metadata.gz: 668b3b6e78da3669db282611f925fb7644ba796f6a4483bc5d674203341398a4
4
+ data.tar.gz: 54240e645b552307a31478c00f46b356f60fb338573818ed761b61e5c1caea87
5
5
  SHA512:
6
- metadata.gz: 0c40157c4619143f0d83ab5fcfab5b63f1db7a561bbb2b5fa50dd6f2c572c7762be9bc5b81bad9824bdfb345e9ad52e9c0bad8edcb7e27474c52ff4cde473604
7
- data.tar.gz: ef136e619f4042998197c29dc99a6072036b6169ec27843a97aeade71b7db2006ac287e9fe19d08b135bde867bd045aa788c2127683aaee8e36c039e60021067
6
+ metadata.gz: 0f1ae28bacebc0b4b8b77428bad2edebbd9c9a21c61f9b55a99f6379343e6a3d9cc9d133b8b675304d97121e907aa28145296c4c7ccb5caad8982cce8d1f38d7
7
+ data.tar.gz: ea649cc3fbdf599b0754f68e77ef27efc776a766e657fc3d25764691c767142db3780001d0c803963673c56200e556e12c086869758668ce5ac6a74f38d6f6dd
@@ -9,9 +9,8 @@ module Binance
9
9
  :trading_api_key, :withdrawals_api_key
10
10
 
11
11
  def api_key(type: nil)
12
- raise Error.new(message: "invalid security_type type: #{type}.") unless type.nil? || api_key_types.include?(type)
13
- instance_api_key(type: type) || ENV["BINANCE_#{type.to_s.humanize.upcase}_API_KEY"] ||
14
- instance_api_key || ENV["BINANCE_API_KEY"]
12
+ raise Error.new(message: "invalid api_key type: #{type}.") unless type.nil? || api_key_types.include?(type)
13
+ instance_api_key(type: type) || ENV["BINANCE_#{type.to_s.humanize.upcase}_API_KEY"] || ENV["BINANCE_API_KEY"]
15
14
  end
16
15
 
17
16
  def tld
@@ -8,6 +8,53 @@ module Binance
8
8
  def is_error_response?(response:)
9
9
  response.code >= 400
10
10
  end
11
+
12
+ # https://github.com/binance/binance-spot-api-docs/blob/master/errors.md
13
+ def localized(message)
14
+ code = message.match(/\d+/).to_s.to_i
15
+ case code
16
+ when 1000 then Unknown
17
+ when 1001 then Disconnected
18
+ when 1002 then Unauthorized
19
+ when 1003 then TooManyRequests
20
+ when 1006 then UnexpectedResponse
21
+ when 1007 then Timeout
22
+ when 1014 then UnknownOrderComposition
23
+ when 1015 then TooManyOrders
24
+ when 1016 then ServiceShuttingDown
25
+ when 1020 then UnsupportedOperation
26
+ when 1021 then InvalidTimestamp
27
+ when 1022 then InvalidSignature
28
+ when 1100 then IllegalChars
29
+ when 1101 then TooManyParameters
30
+ when 1102 then MandatoryParamEmptyOrMalformed
31
+ when 1103 then UnknownParam
32
+ when 1104 then UnreadParameters
33
+ when 1105 then ParamEmpty
34
+ when 1106 then ParamNotRequired
35
+ when 1111 then BadPrecision
36
+ when 1112 then NoDepth
37
+ when 1114 then TIFNotRequired
38
+ when 1115 then InvalidTIF
39
+ when 1116 then InvalidOrderType
40
+ when 1117 then InvalidSide
41
+ when 1118 then EmptyNewCLOrderId
42
+ when 1119 then EmptyOrgCLOrderId
43
+ when 1120 then BadInterval
44
+ when 1121 then BadSymbol
45
+ when 1125 then InvalidListenKey
46
+ when 1127 then IntervalTooLarge
47
+ when 1128 then OptionalParamsBadCombo
48
+ when 1130 then InvalidParameter
49
+ when 2010 then NewOrderRejected
50
+ when 2011 then CancelOrderRejected
51
+ when 2013 then NoSuchOrder
52
+ when 2014 then BadAPIKeyFormat
53
+ when 2015 then RejectedAPIKey
54
+ when 2016 then NoTradingWindow
55
+ else Binance::Api::Error
56
+ end
57
+ end
11
58
  end
12
59
 
13
60
  def initialize(code: nil, json: {}, message: nil, symbol: nil)
@@ -19,6 +66,7 @@ module Binance
19
66
  def inspect
20
67
  message = ""
21
68
  message += "(#{code}) " unless code.nil?
69
+ message += "@#{symbol} " unless symbol.nil?
22
70
  message += "#{msg}" unless msg.nil?
23
71
  end
24
72
 
@@ -29,6 +77,46 @@ module Binance
29
77
  def to_s
30
78
  inspect
31
79
  end
80
+
81
+ class Unknown < Error; end
82
+ class Disconnected < Error; end
83
+ class Unauthorized < Error; end
84
+ class TooManyRequests < Error; end
85
+ class UnexpectedResponse < Error; end
86
+ class Timeout < Error; end
87
+ class UnknownOrderComposition < Error; end
88
+ class TooManyOrders < Error; end
89
+ class ServiceShuttingDown < Error; end
90
+ class UnsupportedOperation < Error; end
91
+ class InvalidTimestamp < Error; end
92
+ class InvalidSignature < Error; end
93
+ class IllegalChars < Error; end
94
+ class TooManyParameters < Error; end
95
+ class MandatoryParamEmptyOrMalformed < Error; end
96
+ class UnknownParam < Error; end
97
+ class UnreadParameters < Error; end
98
+ class ParamEmpty < Error; end
99
+ class ParamNotRequired < Error; end
100
+ class BadPrecision < Error; end
101
+ class NoDepth < Error; end
102
+ class TIFNotRequired < Error; end
103
+ class InvalidTIF < Error; end
104
+ class InvalidOrderType < Error; end
105
+ class InvalidSide < Error; end
106
+ class EmptyNewCLOrderId < Error; end
107
+ class EmptyOrgCLOrderId < Error; end
108
+ class BadInterval < Error; end
109
+ class BadSymbol < Error; end
110
+ class InvalidListenKey < Error; end
111
+ class IntervalTooLarge < Error; end
112
+ class OptionalParamsBadCombo < Error; end
113
+ class InvalidParameter < Error; end
114
+ class NewOrderRejected < Error; end
115
+ class CancelOrderRejected < Error; end
116
+ class NoSuchOrder < Error; end
117
+ class BadAPIKeyFormat < Error; end
118
+ class RejectedAPIKey < Error; end
119
+ class NoTradingWindow < Error; end
32
120
  end
33
121
  end
34
122
  end
@@ -44,7 +44,7 @@ module Binance
44
44
  # binance 500 errors are html format
45
45
  raise Error.new(message: error)
46
46
  end
47
- raise Error.new(json: json) if Error.is_error_response?(response: response)
47
+ raise Error.localized(json[:code]).new(json: json) if Error.is_error_response?(response: response)
48
48
  json
49
49
  end
50
50
 
@@ -1,5 +1,5 @@
1
1
  module Binance
2
2
  module Api
3
- VERSION = "0.7"
3
+ VERSION = "0.8"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: binance-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.7'
4
+ version: '0.8'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jake Peterson
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-02-08 00:00:00.000000000 Z
11
+ date: 2021-04-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: codecov
@@ -203,8 +203,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
203
203
  - !ruby/object:Gem::Version
204
204
  version: '0'
205
205
  requirements: []
206
- rubygems_version: 3.0.8
206
+ rubygems_version: 3.1.6
207
207
  signing_key:
208
208
  specification_version: 4
209
- summary: binance-ruby-0.7
209
+ summary: binance-ruby-0.8
210
210
  test_files: []