aboutsummaryrefslogtreecommitdiff
path: root/ccxt_wrapper.py
diff options
context:
space:
mode:
authorIsmaël Bouya <ismael.bouya@normalesup.org>2018-03-25 22:04:02 +0200
committerIsmaël Bouya <ismael.bouya@normalesup.org>2018-03-25 22:04:02 +0200
commitbfe841c557094afad2db0d2c63deadeea4ba63c6 (patch)
treedfade60890ffe5529dc80fec0b23702b97ea0383 /ccxt_wrapper.py
parentbd7ba362442f27fe3f53729a0040f2473b85a068 (diff)
parentd004a2a5e15a78991870dcb90cd6db63ab40a4e6 (diff)
downloadTrader-bfe841c557094afad2db0d2c63deadeea4ba63c6.tar.gz
Trader-bfe841c557094afad2db0d2c63deadeea4ba63c6.tar.zst
Trader-bfe841c557094afad2db0d2c63deadeea4ba63c6.zip
Merge branch 'dev'v1.0
Diffstat (limited to 'ccxt_wrapper.py')
-rw-r--r--ccxt_wrapper.py45
1 files changed, 45 insertions, 0 deletions
diff --git a/ccxt_wrapper.py b/ccxt_wrapper.py
index d37c306..4ed37d9 100644
--- a/ccxt_wrapper.py
+++ b/ccxt_wrapper.py
@@ -1,12 +1,57 @@
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
40 def __init__(self, *args, **kwargs):
41 super(poloniexE, self).__init__(*args, **kwargs)
42
43 # For requests logging
44 self.session.origin_request = self.session.request
45 self.session._parent = self
46
47 def request_wrap(self, *args, **kwargs):
48 r = self.origin_request(*args, **kwargs)
49 self._parent._market.report.log_http_request(args[0],
50 args[1], kwargs["data"], kwargs["headers"], r)
51 return r
52 self.session.request = request_wrap.__get__(self.session,
53 self.session.__class__)
54
10 @staticmethod 55 @staticmethod
11 def nanoseconds(): 56 def nanoseconds():
12 return int(time.time() * 1000000000) 57 return int(time.time() * 1000000000)