Exception: Binance::Api::Error

Inherits:
StandardError
  • Object
show all
Defined in:
lib/binance/api/error.rb

Defined Under Namespace

Classes: BadAPIKeyFormat, BadInterval, BadPrecision, BadSymbol, CancelOrderRejected, Disconnected, EmptyNewCLOrderId, EmptyOrgCLOrderId, IllegalChars, IntervalTooLarge, InvalidListenKey, InvalidOrderType, InvalidParameter, InvalidQuantity, InvalidSide, InvalidSignature, InvalidTIF, InvalidTimestamp, MandatoryParamEmptyOrMalformed, NewOrderRejected, NoDepth, NoSuchOrder, NoTradingWindow, OptionalParamsBadCombo, ParamEmpty, ParamNotRequired, RejectedAPIKey, ServiceShuttingDown, TIFNotRequired, Timeout, TooManyOrders, TooManyParameters, TooManyRequests, Unauthorized, UnexpectedResponse, Unknown, UnknownOrderComposition, UnknownParam, UnreadParameters, UnsupportedOperation

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code: nil, json: {}, message: nil, symbol: nil) ⇒ Error

Returns a new instance of Error.



61
62
63
64
65
# File 'lib/binance/api/error.rb', line 61

def initialize(code: nil, json: {}, message: nil, symbol: nil)
  @code = code || json[:code]
  @msg = message || json[:msg]
  @symbol = message || json[:symbol]
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



4
5
6
# File 'lib/binance/api/error.rb', line 4

def code
  @code
end

#msgObject (readonly)

Returns the value of attribute msg.



4
5
6
# File 'lib/binance/api/error.rb', line 4

def msg
  @msg
end

#symbolObject (readonly)

Returns the value of attribute symbol.



4
5
6
# File 'lib/binance/api/error.rb', line 4

def symbol
  @symbol
end

Class Method Details

.is_error_response?(response:) ⇒ Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/binance/api/error.rb', line 8

def is_error_response?(response:)
  response.code >= 400
end

.localized(message) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/binance/api/error.rb', line 13

def localized(message)
  code = message.to_s.match(/\d+/).to_s.to_i
  case code
  when 1000 then Unknown
  when 1001 then Disconnected
  when 1002 then Unauthorized
  when 1003 then TooManyRequests
  when 1006 then UnexpectedResponse
  when 1007 then Timeout
  when 1013 then InvalidQuantity
  when 1014 then UnknownOrderComposition
  when 1015 then TooManyOrders
  when 1016 then ServiceShuttingDown
  when 1020 then UnsupportedOperation
  when 1021 then InvalidTimestamp
  when 1022 then InvalidSignature
  when 1100 then IllegalChars
  when 1101 then TooManyParameters
  when 1102 then MandatoryParamEmptyOrMalformed
  when 1103 then UnknownParam
  when 1104 then UnreadParameters
  when 1105 then ParamEmpty
  when 1106 then ParamNotRequired
  when 1111 then BadPrecision
  when 1112 then NoDepth
  when 1114 then TIFNotRequired
  when 1115 then InvalidTIF
  when 1116 then InvalidOrderType
  when 1117 then InvalidSide
  when 1118 then EmptyNewCLOrderId
  when 1119 then EmptyOrgCLOrderId
  when 1120 then BadInterval
  when 1121 then BadSymbol
  when 1125 then InvalidListenKey
  when 1127 then IntervalTooLarge
  when 1128 then OptionalParamsBadCombo
  when 1130 then InvalidParameter
  when 2010 then NewOrderRejected
  when 2011 then CancelOrderRejected
  when 2013 then NoSuchOrder
  when 2014 then BadAPIKeyFormat
  when 2015 then RejectedAPIKey
  when 2016 then NoTradingWindow
  else Binance::Api::Error
  end
end

Instance Method Details

#inspectObject



67
68
69
70
71
72
# File 'lib/binance/api/error.rb', line 67

def inspect
  message = ""
  message += "(#{code}) " unless code.nil?
  message += "@#{symbol} " unless symbol.nil?
  message += "#{msg}" unless msg.nil?
end

#messageObject



74
75
76
# File 'lib/binance/api/error.rb', line 74

def message
  inspect
end

#to_sObject



78
79
80
# File 'lib/binance/api/error.rb', line 78

def to_s
  inspect
end