Exception: Binance::SDK::Error

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

Defined Under Namespace

Classes: BadAPIKeyFormat, BadInterval, BadPrecision, BadSymbol, CancelOrderRejected, CounterPartyBestPrice, Disconnected, EmptyNewCLOrderId, EmptyOrgCLOrderId, IllegalChars, IncorrectOrderPositionSide, IntervalTooLarge, InvalidCallbackRate, InvalidInterval, InvalidListenKey, InvalidOrderType, InvalidParameter, InvalidQuantity, InvalidSide, InvalidSignature, InvalidTIF, InvalidTimestamp, MandatoryParamEmptyOrMalformed, NewOrderRejected, NoDepth, NoNeedToChangeMarginType, NoSuchOrder, NoTradingWindow, OptionalParamsBadCombo, ParamEmpty, ParamNotRequired, QuantityGreaterThanMaxQuantity, RejectedAPIKey, ServiceShuttingDown, TIFNotRequired, Timeout, TimestampOutsideRecvWindow, 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.



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

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

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



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

def code
  @code
end

#msgObject (readonly)

Returns the value of attribute msg.



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

def msg
  @msg
end

#symbolObject (readonly)

Returns the value of attribute symbol.



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

def symbol
  @symbol
end

Class Method Details

.is_error_response?(response:) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/binance/sdk/error.rb', line 7

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

.localized(message) ⇒ Object



11
12
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
59
60
61
62
63
64
# File 'lib/binance/sdk/error.rb', line 11

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 2007 then InvalidCallbackRate
  when 2010 then NewOrderRejected
  when 2011 then CancelOrderRejected
  when 2013 then NoSuchOrder
  when 2014 then BadAPIKeyFormat
  when 2015 then RejectedAPIKey
  when 2016 then NoTradingWindow
  when -1021 then TimestampOutsideRecvWindow
  when -4131 then CounterPartyBestPrice
  when -4005 then QuantityGreaterThanMaxQuantity
  when -1117 then InvalidSide
  when -4046 then NoNeedToChangeMarginType
  when -4061 then IncorrectOrderPositionSide
  when -1120 then InvalidInterval
  else Binance::SDK::Error
  end
end

Instance Method Details

#inspectObject



73
74
75
76
77
78
79
# File 'lib/binance/sdk/error.rb', line 73

def inspect
  message = ""

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

#messageObject



81
82
83
# File 'lib/binance/sdk/error.rb', line 81

def message
  inspect
end

#to_sObject



85
86
87
# File 'lib/binance/sdk/error.rb', line 85

def to_s
  inspect
end