aboutsummaryrefslogtreecommitdiff
path: root/ccxt_wrapper.py
diff options
context:
space:
mode:
Diffstat (limited to 'ccxt_wrapper.py')
-rw-r--r--ccxt_wrapper.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/ccxt_wrapper.py b/ccxt_wrapper.py
index d37c306..c500659 100644
--- a/ccxt_wrapper.py
+++ b/ccxt_wrapper.py
@@ -1,12 +1,42 @@
1from ccxt import * 1from ccxt import *
2import decimal 2import decimal
3import time 3import time
4from retry.api import retry_call
5import re
4 6
5def _cw_exchange_sum(self, *args): 7def _cw_exchange_sum(self, *args):
6 return sum([arg for arg in args if isinstance(arg, (float, int, decimal.Decimal))]) 8 return sum([arg for arg in args if isinstance(arg, (float, int, decimal.Decimal))])
7Exchange.sum = _cw_exchange_sum 9Exchange.sum = _cw_exchange_sum
8 10
9class poloniexE(poloniex): 11class poloniexE(poloniex):
12 RETRIABLE_CALLS = [
13 re.compile(r"^return"),
14 re.compile(r"^cancel"),
15 re.compile(r"^closeMarginPosition$"),
16 re.compile(r"^getMarginPosition$"),
17 ]
18
19 def request(self, path, api='public', method='GET', params={}, headers=None, body=None):
20 """
21 Wrapped to allow retry of non-posting requests"
22 """
23
24 origin_request = super(poloniexE, self).request
25 kwargs = {
26 "api": api,
27 "method": method,
28 "params": params,
29 "headers": headers,
30 "body": body
31 }
32
33 retriable = any(re.match(call, path) for call in self.RETRIABLE_CALLS)
34 if api == "public" or method == "GET" or retriable:
35 return retry_call(origin_request, fargs=[path], fkwargs=kwargs,
36 tries=10, delay=1, exceptions=(RequestTimeout,))
37 else:
38 return origin_request(path, **kwargs)
39
10 @staticmethod 40 @staticmethod
11 def nanoseconds(): 41 def nanoseconds():
12 return int(time.time() * 1000000000) 42 return int(time.time() * 1000000000)