gate-io-api 0.0.65__py3-none-any.whl → 0.0.100__py3-none-any.whl

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.

Potentially problematic release.


This version of gate-io-api might be problematic. Click here for more details.

@@ -34,17 +34,21 @@ PAD_WITH_ZERO = 6
34
34
 
35
35
 
36
36
  def decimal_to_precision(n, rounding_mode=ROUND, precision=None, counting_mode=DECIMAL_PLACES, padding_mode=NO_PADDING):
37
- assert precision is not None
37
+ assert precision is not None, 'precision should not be None'
38
+
39
+ if isinstance(precision, str):
40
+ precision = float(precision)
41
+ assert isinstance(precision, float) or isinstance(precision, decimal.Decimal) or isinstance(precision, numbers.Integral), 'precision has an invalid number'
42
+
38
43
  if counting_mode == TICK_SIZE:
39
- assert(isinstance(precision, float) or isinstance(precision, decimal.Decimal) or isinstance(precision, numbers.Integral) or isinstance(precision, str))
44
+ assert precision > 0, 'negative or zero precision can not be used with TICK_SIZE precisionMode'
40
45
  else:
41
- assert(isinstance(precision, numbers.Integral))
46
+ assert isinstance(precision, numbers.Integral)
47
+
42
48
  assert rounding_mode in [TRUNCATE, ROUND]
43
49
  assert counting_mode in [DECIMAL_PLACES, SIGNIFICANT_DIGITS, TICK_SIZE]
44
50
  assert padding_mode in [NO_PADDING, PAD_WITH_ZERO]
45
-
46
- if isinstance(precision, str):
47
- precision = float(precision)
51
+ # end of checks
48
52
 
49
53
  context = decimal.getcontext()
50
54
 
@@ -78,12 +82,12 @@ def decimal_to_precision(n, rounding_mode=ROUND, precision=None, counting_mode=D
78
82
  if missing != 0:
79
83
  if rounding_mode == ROUND:
80
84
  if dec > 0:
81
- if missing >= precision / 2:
85
+ if missing >= precision_dec / 2:
82
86
  dec = dec - missing + precision_dec
83
87
  else:
84
88
  dec = dec - missing
85
89
  else:
86
- if missing >= precision / 2:
90
+ if missing >= precision_dec / 2:
87
91
  dec = dec + missing - precision_dec
88
92
  else:
89
93
  dec = dec + missing
@@ -117,7 +121,7 @@ def decimal_to_precision(n, rounding_mode=ROUND, precision=None, counting_mode=D
117
121
  precise = '{:f}'.format(min((below, above), key=lambda x: abs(x - dec)))
118
122
  else:
119
123
  precise = '{:f}'.format(dec.quantize(sigfig))
120
- if precise == ('-0.' + len(precise) * '0')[:2] or precise == '-0':
124
+ if precise.startswith('-0') and all(c in '0.' for c in precise[1:]):
121
125
  precise = precise[1:]
122
126
 
123
127
  elif rounding_mode == TRUNCATE:
@@ -138,7 +142,7 @@ def decimal_to_precision(n, rounding_mode=ROUND, precision=None, counting_mode=D
138
142
  precise = string
139
143
  else:
140
144
  precise = string[:end].ljust(dot, '0')
141
- if precise == ('-0.' + len(precise) * '0')[:3] or precise == '-0':
145
+ if precise.startswith('-0') and all(c in '0.' for c in precise[1:]):
142
146
  precise = precise[1:]
143
147
  precise = precise.rstrip('.')
144
148
 
gate/ccxt/base/errors.py CHANGED
@@ -23,6 +23,7 @@ error_hierarchy = {
23
23
  },
24
24
  'MarketClosed': {},
25
25
  'ManualInteractionNeeded': {},
26
+ 'RestrictedLocation': {},
26
27
  },
27
28
  'InsufficientFunds': {},
28
29
  'InvalidAddress': {
@@ -118,6 +119,10 @@ class ManualInteractionNeeded(OperationRejected):
118
119
  pass
119
120
 
120
121
 
122
+ class RestrictedLocation(OperationRejected):
123
+ pass
124
+
125
+
121
126
  class InsufficientFunds(ExchangeError):
122
127
  pass
123
128
 
@@ -238,6 +243,7 @@ __all__ = [
238
243
  'MarginModeAlreadySet',
239
244
  'MarketClosed',
240
245
  'ManualInteractionNeeded',
246
+ 'RestrictedLocation',
241
247
  'InsufficientFunds',
242
248
  'InvalidAddress',
243
249
  'AddressPending',