Implement more validation and conversion
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
import functools
|
||||
|
||||
from alpaca.common.exceptions import APIError
|
||||
from alpaca.trading.client import TradingClient
|
||||
from alpaca.trading.enums import OrderSide, TimeInForce
|
||||
@@ -12,19 +10,6 @@ from alpaca.trading.requests import (
|
||||
from core.exchanges import BaseExchange, ExchangeError, GenericAPIError
|
||||
|
||||
|
||||
def handle_errors(func):
|
||||
@functools.wraps(func)
|
||||
def wrapper(self, *args, **kwargs):
|
||||
return_value = func(self, *args, **kwargs)
|
||||
if isinstance(return_value, tuple):
|
||||
if return_value[0] is False:
|
||||
print("Error: ", return_value[1])
|
||||
return return_value
|
||||
return return_value[1]
|
||||
|
||||
return wrapper
|
||||
|
||||
|
||||
class AlpacaExchange(BaseExchange):
|
||||
def connect(self):
|
||||
self.client = TradingClient(
|
||||
@@ -34,18 +19,14 @@ class AlpacaExchange(BaseExchange):
|
||||
raw_data=True,
|
||||
)
|
||||
|
||||
@handle_errors
|
||||
def get_account(self):
|
||||
# return self.call("get_account")
|
||||
market = self.get_market_value("NONEXISTENT")
|
||||
print("MARTKET", market)
|
||||
return self.call("get_account")
|
||||
|
||||
def get_supported_assets(self):
|
||||
request = GetAssetsRequest(status="active", asset_class="crypto")
|
||||
assets = self.call("get_all_assets", filter=request)
|
||||
assets = assets["itemlist"]
|
||||
asset_list = [x["symbol"] for x in assets if "symbol" in x]
|
||||
print("Supported symbols", asset_list)
|
||||
|
||||
return asset_list
|
||||
|
||||
|
||||
Reference in New Issue
Block a user