Add more hooks to active management
This commit is contained in:
@@ -33,11 +33,12 @@ def get_pair(account, base, quote, invert=False):
|
||||
:param invert: Invert the pair
|
||||
:return: currency symbol, e.g. BTC_USD, BTC/USD, etc.
|
||||
"""
|
||||
# Currently we only have two exchanges with different pair separators
|
||||
if account.exchange == "alpaca":
|
||||
separator = "/"
|
||||
elif account.exchange == "oanda":
|
||||
separator = "_"
|
||||
else:
|
||||
separator = "_"
|
||||
|
||||
# Flip the pair if needed
|
||||
if invert:
|
||||
@@ -50,6 +51,16 @@ def get_pair(account, base, quote, invert=False):
|
||||
return symbol
|
||||
|
||||
|
||||
def get_symbol_price(account, price_index, symbol):
|
||||
try:
|
||||
prices = account.client.get_currencies([symbol])
|
||||
except GenericAPIError as e:
|
||||
log.error(f"Error getting currencies and inverted currencies: {e}")
|
||||
return None
|
||||
price = D(prices["prices"][0][price_index][0]["price"])
|
||||
return price
|
||||
|
||||
|
||||
def to_currency(direction, account, amount, from_currency, to_currency):
|
||||
"""
|
||||
Convert an amount from one currency to another.
|
||||
@@ -79,12 +90,7 @@ def to_currency(direction, account, amount, from_currency, to_currency):
|
||||
if not symbol:
|
||||
log.error(f"Could not find symbol for {from_currency} -> {to_currency}")
|
||||
raise Exception("Could not find symbol")
|
||||
try:
|
||||
prices = account.client.get_currencies([symbol])
|
||||
except GenericAPIError as e:
|
||||
log.error(f"Error getting currencies and inverted currencies: {e}")
|
||||
return None
|
||||
price = D(prices["prices"][0][price_index][0]["price"])
|
||||
price = get_symbol_price(account, price_index, symbol)
|
||||
|
||||
# If we had to flip base and quote, we need to use the reciprocal of the price
|
||||
if inverted:
|
||||
|
||||
Reference in New Issue
Block a user