Fixed hash method to create sid numbers

This commit is contained in:
fredfortier
2017-10-23 20:29:48 -04:00
parent c7b422d465
commit c2a02e7074
+7 -1
View File
@@ -17,6 +17,8 @@
"""
Cythonized Asset object.
"""
import hashlib
cimport cython
from cpython.number cimport PyNumber_Index
from cpython.object cimport (
@@ -501,7 +503,11 @@ cdef class TradingPair(Asset):
if sid == 0 or sid is None:
try:
sid = abs(hash(symbol)) % (10 ** 4)
# sid = abs(hash(symbol)) % (10 ** 4)
# TODO: try to encode the symbol in the main scope
sid = int(
hashlib.sha256(symbol.encode('utf-8')).hexdigest(), 16
) % 10 ** 6
except Exception as e:
raise SidHashError(symbol=symbol)