-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from jiak94/account_api
Implement Account API
- Loading branch information
Showing
10 changed files
with
1,881 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,210 @@ | ||
from asynctradier.common import AccountType | ||
|
||
|
||
class CashAccountBalanceDetails: | ||
""" | ||
Represents the details of a cash account balance. | ||
Attributes: | ||
cash_available (float): The amount of cash available in the account. | ||
sweep (float): The amount of cash swept from the account. | ||
unsettled_funds (float): The amount of funds that are currently unsettled. | ||
""" | ||
|
||
def __init__(self, **kwargs): | ||
self.cash_available = kwargs.get("cash_available", 0.0) | ||
self.sweep = kwargs.get("sweep", 0.0) | ||
self.unsettled_funds = kwargs.get("unsettled_funds", 0.0) | ||
|
||
def to_dict(self): | ||
""" | ||
Converts the AccountBalance object to a dictionary. | ||
Returns: | ||
dict: A dictionary representation of the AccountBalance object. | ||
""" | ||
return { | ||
"cash_available": self.cash_available, | ||
"sweep": self.sweep, | ||
"unsettled_funds": self.unsettled_funds, | ||
} | ||
|
||
def __str__(self): | ||
return f"CashAccountBalanceDetails(capacity={self.cash_available}, sweep={self.sweep}, unsettled_funds={self.unsettled_funds})" | ||
|
||
|
||
class MarginAccountBalanceDetails: | ||
""" | ||
Represents the details of a margin account balance. | ||
Attributes: | ||
fed_call (float): The federal call amount. | ||
maintenance_call (float): The maintenance call amount. | ||
option_buying_power (float): The buying power for options. | ||
stock_buying_power (float): The buying power for stocks. | ||
stock_short_value (float): The value of shorted stocks. | ||
sweep (float): The sweep amount. | ||
""" | ||
|
||
def __init__(self, **kwargs): | ||
self.fed_call = kwargs.get("fed_call", 0.0) | ||
self.maintenance_call = kwargs.get("maintenance_call", 0.0) | ||
self.option_buying_power = kwargs.get("option_buying_power", 0.0) | ||
self.stock_buying_power = kwargs.get("stock_buying_power", 0.0) | ||
self.stock_short_value = kwargs.get("stock_short_value", 0.0) | ||
self.sweep = kwargs.get("sweep", 0.0) | ||
|
||
def to_dict(self): | ||
""" | ||
Converts the AccountBalance object to a dictionary. | ||
Returns: | ||
dict: A dictionary representation of the AccountBalance object. | ||
""" | ||
return { | ||
"fed_call": self.fed_call, | ||
"maintenance_call": self.maintenance_call, | ||
"option_buying_power": self.option_buying_power, | ||
"stock_buying_power": self.stock_buying_power, | ||
"stock_short_value": self.stock_short_value, | ||
"sweep": self.sweep, | ||
} | ||
|
||
def __str__(self): | ||
return f"MarginAccountBalanceDetails(fed_call={self.fed_call}, maintenance_call={self.maintenance_call}, option_buying_power={self.option_buying_power}, stock_buying_power={self.stock_buying_power}, stock_short_value={self.stock_short_value}, sweep={self.sweep})" | ||
|
||
|
||
class PDTAccountBalanceDetails: | ||
""" | ||
Represents the account balance details for a Pattern Day Trader (PDT). | ||
Attributes: | ||
fed_call (float): The amount of the Federal Call. | ||
maintenance_call (float): The amount of the Maintenance Call. | ||
option_buying_power (float): The buying power for options trading. | ||
stock_buying_power (float): The buying power for stock trading. | ||
stock_short_value (float): The value of shorted stocks. | ||
""" | ||
|
||
def __init__(self, **kwargs): | ||
self.fed_call = kwargs.get("fed_call", 0.0) | ||
self.maintenance_call = kwargs.get("maintenance_call", 0.0) | ||
self.option_buying_power = kwargs.get("option_buying_power", 0.0) | ||
self.stock_buying_power = kwargs.get("stock_buying_power", 0.0) | ||
self.stock_short_value = kwargs.get("stock_short_value", 0.0) | ||
|
||
def to_dict(self): | ||
""" | ||
Converts the AccountBalance object to a dictionary. | ||
Returns: | ||
dict: A dictionary representation of the AccountBalance object. | ||
""" | ||
return { | ||
"fed_call": self.fed_call, | ||
"maintenance_call": self.maintenance_call, | ||
"option_buying_power": self.option_buying_power, | ||
"stock_buying_power": self.stock_buying_power, | ||
"stock_short_value": self.stock_short_value, | ||
} | ||
|
||
def __str__(self): | ||
return f"PDTAccountBalanceDetails(fed_call={self.fed_call}, maintenance_call={self.maintenance_call}, option_buying_power={self.option_buying_power}, stock_buying_power={self.stock_buying_power}, stock_short_value={self.stock_short_value})" | ||
|
||
|
||
class AccountBalance: | ||
""" | ||
Represents the balance of an account. | ||
Attributes: | ||
option_short_value (float): The short value of options in the account. | ||
total_equity (float): The total equity of the account. | ||
account_number (str): The account number. | ||
account_type (AccountType): The type of the account. | ||
close_pl (float): The close profit/loss of the account. | ||
current_requirement (float): The current requirement of the account. | ||
equity (float): The equity of the account. | ||
long_market_value (float): The long market value of the account. | ||
market_value (float): The market value of the account. | ||
open_pl (float): The open profit/loss of the account. | ||
option_long_value (float): The long value of options in the account. | ||
option_requirement (float): The option requirement of the account. | ||
pending_orders_count (int): The count of pending orders in the account. | ||
short_market_value (float): The short market value of the account. | ||
stock_long_value (float): The long value of stocks in the account. | ||
total_cash (float): The total cash in the account. | ||
uncleared_funds (float): The uncleared funds in the account. | ||
pending_cash (float): The pending cash in the account. | ||
cash (CashAccountBalanceDetails): The details of the cash account balance (if account type is cash). | ||
margin (MarginAccountBalanceDetails): The details of the margin account balance (if account type is margin). | ||
pdt (PDTAccountBalanceDetails): The details of the PDT account balance (if account type is pdt). | ||
""" | ||
|
||
def __init__(self, **kwargs): | ||
self.option_short_value = kwargs.get("option_short_value") | ||
self.total_equity = kwargs.get("total_equity") | ||
self.account_number = kwargs.get("account_number") | ||
self.account_type = ( | ||
AccountType(kwargs.get("account_type")) | ||
if kwargs.get("account_type") | ||
else None | ||
) | ||
self.close_pl = kwargs.get("close_pl") | ||
self.current_requirement = kwargs.get("current_requirement") | ||
self.equity = kwargs.get("equity") | ||
self.long_market_value = kwargs.get("long_market_value") | ||
self.market_value = kwargs.get("market_value") | ||
self.open_pl = kwargs.get("open_pl") | ||
self.option_long_value = kwargs.get("option_long_value") | ||
self.option_requirement = kwargs.get("option_requirement") | ||
self.pending_orders_count = kwargs.get("pending_orders_count") | ||
self.short_market_value = kwargs.get("short_market_value") | ||
self.stock_long_value = kwargs.get("stock_long_value") | ||
self.total_cash = kwargs.get("total_cash") | ||
self.uncleared_funds = kwargs.get("uncleared_funds") | ||
self.pending_cash = kwargs.get("pending_cash") | ||
|
||
self.cash = ( | ||
CashAccountBalanceDetails(**kwargs.get("cash")) | ||
if kwargs.get("cash") | ||
else None | ||
) | ||
self.margin = ( | ||
MarginAccountBalanceDetails(**kwargs.get("margin")) | ||
if kwargs.get("margin") | ||
else None | ||
) | ||
self.pdt = ( | ||
PDTAccountBalanceDetails(**kwargs.get("pdt")) if kwargs.get("pdt") else None | ||
) | ||
|
||
def to_dict(self): | ||
""" | ||
Converts the AccountBalance object to a dictionary. | ||
Returns: | ||
dict: A dictionary representation of the AccountBalance object. | ||
""" | ||
return { | ||
"option_short_value": self.option_short_value, | ||
"total_equity": self.total_equity, | ||
"account_number": self.account_number, | ||
"account_type": self.account_type, | ||
"close_pl": self.close_pl, | ||
"current_requirement": self.current_requirement, | ||
"equity": self.equity, | ||
"long_market_value": self.long_market_value, | ||
"market_value": self.market_value, | ||
"open_pl": self.open_pl, | ||
"option_long_value": self.option_long_value, | ||
"option_requirement": self.option_requirement, | ||
"pending_orders_count": self.pending_orders_count, | ||
"short_market_value": self.short_market_value, | ||
"stock_long_value": self.stock_long_value, | ||
"total_cash": self.total_cash, | ||
"uncleared_funds": self.uncleared_funds, | ||
"pending_cash": self.pending_cash, | ||
"cash": self.cash.to_dict() if self.cash else None, | ||
"margin": self.margin.to_dict() if self.margin else None, | ||
"pdt": self.pdt.to_dict() if self.pdt else None, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
from asynctradier.common import EventType, TradeType | ||
|
||
|
||
class Event: | ||
""" | ||
Represents an event. | ||
Attributes: | ||
amount (float): The amount of the event. | ||
date (str): The date of the event. | ||
type (EventType): The type of the event. | ||
description (str): The description of the event. | ||
commision (float): The commission of the event. | ||
price (float): The price of the event. | ||
quantity (float): The quantity of the event. | ||
symbol (str): The symbol of the event. | ||
trade_type (TradeType): The type of trade. | ||
""" | ||
|
||
def __init__(self, **kwargs): | ||
self.amount = float(kwargs.get("amount")) if kwargs.get("amount") else 0.0 | ||
self.date = kwargs.get("date") | ||
self.type = EventType(kwargs.get("type")) if kwargs.get("type") else None | ||
|
||
detail = kwargs.get(self.type.value, {}) | ||
|
||
self.description = detail.get("description") | ||
self.commision = ( | ||
float(detail.get("commision")) if detail.get("commision") else 0.0 | ||
) | ||
self.price = float(detail.get("price")) if detail.get("price") else 0.0 | ||
self.quantity = float(detail.get("quantity")) if detail.get("quantity") else 0.0 | ||
self.symbol = detail.get("symbol") | ||
self.trade_type = ( | ||
TradeType(detail.get("trade_type").lower()) | ||
if detail.get("trade_type") | ||
else None | ||
) | ||
|
||
def to_dict(self): | ||
""" | ||
Converts the Event object to a dictionary. | ||
Returns: | ||
dict: A dictionary representation of the Event object. | ||
""" | ||
return { | ||
"amount": self.amount, | ||
"date": self.date, | ||
"type": self.type.value, | ||
"description": self.description, | ||
"commision": self.commision, | ||
"price": self.price, | ||
"symbol": self.symbol, | ||
"trade_type": self.trade_type.value, | ||
"quantity": self.quantity, | ||
} | ||
|
||
def __str__(self): | ||
return f"Event(amount={self.amount}, date={self.date}, type={self.type}, description={self.description}, commision={self.commision}, price={self.price}, symbol={self.symbol}, trade_type={self.trade_type})" |
Oops, something went wrong.