Skip to content

Commit ba81a91

Browse files
committed
black + isort
1 parent f1b8ca0 commit ba81a91

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+2715
-3554
lines changed

.github/workflows/black.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: Lint Source Code
2+
on: [pull_request]
3+
jobs:
4+
lint:
5+
runs-on: ubuntu-latest
6+
steps:
7+
- name: Checkout Source Code
8+
uses: actions/checkout@v2
9+
- name: Set up Python
10+
uses: actions/setup-python@v2
11+
- name: Lint
12+
uses: psf/black@stable
13+
with:
14+
black_args: "./ally --check"
15+

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ pyally.egg-info/
1717
pyally.egg-info/*
1818
venv/
1919
sphinx/_build/
20+
.mypy_cache

ally/Account/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
# SOFTWARE.
2222

23-
from .holdings import holdings
24-
from .balances import balances
25-
from .history import history
26-
from .accounts import accounts
23+
from .accounts import accounts
24+
from .balances import balances
25+
from .history import history
26+
from .holdings import holdings

ally/Account/accounts.py

Lines changed: 37 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -20,78 +20,59 @@
2020
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
# SOFTWARE.
2222

23-
from ..Api import AccountEndpoint, RequestType
24-
from .utils import _dot_flatten
23+
from .utils import _dot_flatten
24+
from ..Api import AccountEndpoint, RequestType
2525

2626

27+
class Accounts(AccountEndpoint):
28+
_type = RequestType.Info
29+
_resource = "accounts.json"
2730

28-
class Accounts ( AccountEndpoint ):
29-
_type = RequestType.Info
30-
_resource = 'accounts.json'
31+
def extract(self, response):
32+
"""Extract certain fields from response"""
33+
response = response.json()["response"]
34+
accounts = response["accounts"]
3135

36+
d = {k: v for k, v in _dot_flatten(accounts).items()}
37+
return d
3238

39+
@staticmethod
40+
def DataFrame(raw):
41+
import pandas as pd
3342

43+
# Wrap these in lists so that they can be read by pandas
44+
raw = {k: [v] for k, v in raw.items()}
3445

35-
def extract ( self, response ):
36-
"""Extract certain fields from response
37-
"""
38-
response = response.json()['response']
39-
accounts = response['accounts']
46+
return pd.DataFrame.from_dict(raw)
4047

41-
d = {
42-
k: v
43-
for k,v in _dot_flatten( accounts ).items()
44-
}
45-
return d
4648

49+
def accounts(self, dataframe: bool = True, block: bool = True):
50+
"""Gets list of available accounts, and some basic metrics for each one.
4751
48-
@staticmethod
49-
def DataFrame ( raw ):
50-
import pandas as pd
52+
Calls the 'accounts.json' endpoint to get the current list of accounts.
53+
This includes account number, cash account balances, and P/L.
5154
52-
# Wrap these in lists so that they can be read by pandas
53-
raw = { k: [v] for k,v in raw.items() }
55+
Args:
5456
55-
return pd.DataFrame.from_dict ( raw )
57+
dataframe: Specify an output format
58+
block: Specify whether to block thread if request exceeds rate limit
5659
5760
61+
Returns:
5862
63+
A pandas dataframe by default,
64+
otherwise a flat dictionary.
5965
66+
Raises:
6067
68+
RateLimitException: If block=False, rate limit problems will be raised
69+
"""
70+
result = Accounts(auth=self.auth, block=block).request()
6171

72+
if dataframe:
73+
try:
74+
result = Accounts.DataFrame(result)
75+
except:
76+
pass
6277

63-
def accounts ( self, dataframe: bool = True, block: bool = True ):
64-
"""Gets list of available accounts, and some basic metrics for each one.
65-
66-
Calls the 'accounts.json' endpoint to get the current list of accounts.
67-
This includes account number, cash account balances, and P/L.
68-
69-
Args:
70-
71-
dataframe: Specify an output format
72-
block: Specify whether to block thread if request exceeds rate limit
73-
74-
75-
Returns:
76-
77-
A pandas dataframe by default,
78-
otherwise a flat dictionary.
79-
80-
Raises:
81-
82-
RateLimitException: If block=False, rate limit problems will be raised
83-
"""
84-
result = Accounts(
85-
auth = self.auth,
86-
block = block
87-
).request()
88-
89-
90-
if dataframe:
91-
try:
92-
result = Accounts.DataFrame ( result )
93-
except:
94-
pass
95-
96-
return result
97-
78+
return result

ally/Account/balances.py

Lines changed: 39 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -20,79 +20,61 @@
2020
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
# SOFTWARE.
2222

23-
from ..Api import AccountEndpoint, RequestType
24-
from .utils import _dot_flatten
23+
from .utils import _dot_flatten
24+
from ..Api import AccountEndpoint, RequestType
2525

2626

27+
class Balances(AccountEndpoint):
28+
_type = RequestType.Info
29+
_resource = "accounts/{0}/balances.json"
2730

28-
class Balances ( AccountEndpoint ):
29-
_type = RequestType.Info
30-
_resource = 'accounts/{0}/balances.json'
31+
def extract(self, response):
32+
"""Extract certain fields from response"""
33+
response = response.json()["response"]
34+
balances = response["accountbalance"]
3135

36+
d = {k: v for k, v in _dot_flatten(balances).items()}
37+
return d
3238

39+
@staticmethod
40+
def DataFrame(raw):
41+
import pandas as pd
3342

43+
# Wrap these in lists so that they can be read by pandas
44+
raw = {k: [v] for k, v in raw.items()}
3445

35-
def extract ( self, response ):
36-
"""Extract certain fields from response
37-
"""
38-
response = response.json()['response']
39-
balances = response['accountbalance']
46+
return pd.DataFrame.from_dict(raw)
4047

41-
d = {
42-
k: v
43-
for k,v in _dot_flatten( balances ).items()
44-
}
45-
return d
4648

49+
def balances(self, dataframe: bool = True, block: bool = True):
50+
"""Gets current cash and various account metrics.
4751
48-
@staticmethod
49-
def DataFrame ( raw ):
50-
import pandas as pd
52+
Calls the 'accounts/./balances.json' endpoint to get the current list of balances.
53+
This includes margin amounts, cash, etc.
5154
52-
# Wrap these in lists so that they can be read by pandas
53-
raw = { k: [v] for k,v in raw.items() }
55+
Args:
5456
55-
return pd.DataFrame.from_dict ( raw )
57+
dataframe: Specify an output format
58+
block: Specify whether to block thread if request exceeds rate limit
5659
5760
61+
Returns:
5862
63+
A pandas dataframe with 1 row by default,
64+
otherwise a flat dictionary.
5965
66+
Raises:
6067
68+
RateLimitException: If block=False, rate limit problems will be raised
69+
"""
70+
result = Balances(
71+
auth=self.auth, account_nbr=self.account_nbr, block=block
72+
).request()
6173

74+
if dataframe:
75+
try:
76+
result = Balances.DataFrame(result)
77+
except:
78+
pass
6279

63-
def balances ( self, dataframe: bool = True, block: bool = True ):
64-
"""Gets current cash and various account metrics.
65-
66-
Calls the 'accounts/./balances.json' endpoint to get the current list of balances.
67-
This includes margin amounts, cash, etc.
68-
69-
Args:
70-
71-
dataframe: Specify an output format
72-
block: Specify whether to block thread if request exceeds rate limit
73-
74-
75-
Returns:
76-
77-
A pandas dataframe with 1 row by default,
78-
otherwise a flat dictionary.
79-
80-
Raises:
81-
82-
RateLimitException: If block=False, rate limit problems will be raised
83-
"""
84-
result = Balances(
85-
auth = self.auth,
86-
account_nbr = self.account_nbr,
87-
block = block
88-
).request()
89-
90-
91-
if dataframe:
92-
try:
93-
result = Balances.DataFrame ( result )
94-
except:
95-
pass
96-
97-
return result
98-
80+
return result

0 commit comments

Comments
 (0)