try:
r = http.request("GET", cls.URL)
except Exception:
- return
+ return None
try:
cls.data = json.loads(r.data,
parse_int=D,
def clean_weights(i):
def clean_weights_(h):
- if type(h[1][i]) == str:
+ if isinstance(h[1][i], str):
return [h[0], h[1][i]]
else:
return [h[0], int(h[1][i] * 10000)]
return Amount(self.currency, self.value - other.value)
def __mul__(self, value):
- if type(value) != int and type(value) != float and type(value) != D:
+ if not isinstance(value, (int, float, D)):
raise TypeError("Amount may only be multiplied by numbers")
return Amount(self.currency, self.value * value)
return self.__mul__(value)
def __floordiv__(self, value):
- if type(value) != int and type(value) != float and type(value) != D:
+ if not isinstance(value, (int, float, D)):
raise TypeError("Amount may only be multiplied by integers")
return Amount(self.currency, self.value / value)
@classmethod
def compute_value(cls, ticker, action, compute_value="default"):
- if type(compute_value) == str:
+ if isinstance(compute_value, str):
compute_value = Computation.computations[compute_value]
return compute_value(ticker, action)
print("\t", order, sep="")
class Order:
- def __init__(self, action, amount, rate, base_currency, market):
+ def __init__(self, action, amount, rate, base_currency, market, account="exchange"):
self.action = action
self.amount = amount
self.rate = rate
self.base_currency = base_currency
self.market = market
+ self.account = account
self.result = None
self.status = "pending"
amount = self.amount.value
if debug:
- print("market.create_order('{}', 'limit', '{}', {}, price={})".format(
- symbol, self.action, amount, self.rate))
+ print("market.create_order('{}', 'limit', '{}', {}, price={}, account={})".format(
+ symbol, self.action, amount, self.rate, self.account))
else:
try:
- self.result = self.market.create_order(symbol, 'limit', self.action, amount, price=self.rate)
+ self.result = self.market.create_order(symbol, 'limit', self.action, amount, price=self.rate, account=self.account)
self.status = "open"
except Exception as e:
self.status = "error"
- print("error when running market.create_order('{}', 'limit', '{}', {}, price={})".format(
- symbol, self.action, amount, self.rate))
+ print("error when running market.create_order('{}', 'limit', '{}', {}, price={}, account={})".format(
+ symbol, self.action, amount, self.rate, self.account))
self.error_message = str("{}: {}".format(e.__class__.__name__, e))
print(self.error_message)