Skip to content

Commit 98227aa

Browse files
author
Shlomi Kushchi
authored
Merge branch 'master' into verbose_stacktrace
2 parents cc2bb4f + 949956f commit 98227aa

File tree

4 files changed

+35
-29
lines changed

4 files changed

+35
-29
lines changed

NOTICE

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Apache [PRODUCT_NAME]
2+
Copyright [XXXX-XXXX] The Apache Software Foundation
3+
4+
This product includes software developed at
5+
The Apache Software Foundation (http://www.apache.org/).

README.md

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# alpaca-trade-api-python
77

88
`alpaca-trade-api-python` is a python library for the [Alpaca Commission Free Trading API](https://alpaca.markets).
9-
It allows rapid trading algo development easily, with support for the
9+
It allows rapid trading algo development easily, with support for
1010
both REST and streaming data interfaces. For details of each API behavior,
1111
please see the online [API document](https://docs.alpaca.markets).
1212

@@ -21,7 +21,7 @@ $ pip3 install alpaca-trade-api
2121

2222
## Example
2323

24-
In order to call Alpaca's trade API, you need to sign up for a account and obtain API key pairs. Replace <key_id> and <secret_key> with what you get from the web console.
24+
In order to call Alpaca's trade API, you need to sign up for an account and obtain API key pairs. Replace <key_id> and <secret_key> with what you get from the web console.
2525

2626
### REST example
2727
```python
@@ -42,7 +42,7 @@ The HTTP API document is located at https://docs.alpaca.markets/
4242

4343
## API Version
4444

45-
API Version now defaults to 'v2', however if you still have a 'v1' account, you may need to specify api_version='v1' to properly use the API until you migrate.
45+
API Version now defaults to 'v2', however, if you still have a 'v1' account, you may need to specify api_version='v1' to properly use the API until you migrate.
4646

4747
## Authentication
4848

@@ -53,7 +53,7 @@ outlined below.
5353

5454
## Alpaca Environment Variables
5555

56-
The Alpaca SDK will check the environment for a number of variables which can be used rather than hard-coding these into your scripts.
56+
The Alpaca SDK will check the environment for a number of variables that can be used rather than hard-coding these into your scripts.
5757

5858
| Environment | default | Description |
5959
| -------------------------------- | -------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------- |
@@ -74,7 +74,7 @@ The `REST` class is the entry point for the API request. The instance of this
7474
class provides all REST API calls such as account, orders, positions,
7575
and bars.
7676

77-
Each returned object is wrapped by a subclass of `Entity` class (or a list of it).
77+
Each returned object is wrapped by a subclass of the `Entity` class (or a list of it).
7878
This helper class provides property access (the "dot notation") to the
7979
json object, backed by the original object stored in the `_raw` field.
8080
It also converts certain types to the appropriate python object.
@@ -88,7 +88,7 @@ account.status
8888
=> 'ACTIVE'
8989
```
9090

91-
The `Entity` class also converts timestamp string field to a pandas.Timestamp
91+
The `Entity` class also converts the timestamp string field to a pandas.Timestamp
9292
object. Its `_raw` property returns the original raw primitive data unmarshaled
9393
from the response JSON text.
9494

@@ -221,9 +221,9 @@ exception is raised, and each event handler is called asynchronously
221221
upon the message arrivals.
222222

223223
The `run` method tries to reconnect to the server in the event of
224-
connection failure. In this case you may want to reset your state
224+
connection failure. In this case, you may want to reset your state
225225
which is best in the `connect` event. The method still raises
226-
exception in the case any other unknown error happens inside the
226+
an exception in the case any other unknown error happens inside the
227227
event loop.
228228

229229
The `msg` object passed to each handler is wrapped by the entity
@@ -299,7 +299,15 @@ StreamConn object called `debug`. It is set to False by default, but you can tur
299299
verbose logs when this exception happens.
300300
Turn it on like so `StreamConn(debug=True)`
301301

302-
---
302+
## Logging
303+
You should define a logger in your app in order to make sure you get all the messages from the different components.<br>
304+
It will help you debug, and make sure you don't miss issues when they occur.<br>
305+
The simplest way to define a logger, if you have no experience with the python logger - will be something like this:
306+
```py
307+
import logging
308+
logging.basicConfig(format='%(asctime)s %(message)s', level=logging.INFO)
309+
```
310+
303311
# Polygon API Service
304312

305313
Alpaca's API key ID can be used to access Polygon API, the documentation for
@@ -334,7 +342,7 @@ df = api.polygon.historic_agg_v2('AAPL', 1, 'minute', _from=start, to=end).df
334342
```
335343

336344
## polygon/REST
337-
It is initialized through alpaca `REST` object.
345+
It is initialized through the alpaca `REST` object.
338346

339347
### polygon/REST.exchanges()
340348
Returns a list of `Exchange` entity.
@@ -345,7 +353,7 @@ Returns a `SymbolTypeMap` object.
345353
### polygon/REST.historic_trades_v2(symbol, date,timestamp=None, timestamp_limit=None, reverse=None, limit=None)
346354
Returns a `TradesV2` which is a list of `Trade` entities.
347355

348-
- `date` is a date string such as '2018-2-2'. The returned quotes are from this day onyl.
356+
- `date` is a date string such as '2018-2-2'. The returned quotes are from this day only.
349357
- `timestamp` is an integer in Unix Epoch nanoseconds as the lower bound filter, exclusive.
350358
- `timestamp_limit` is an integer in Unix Epoch nanoseconds as the maximum timestamp allowed in the results.
351359
- `limit` is an integer for the number of ticks to return. Default and max is 50000.
@@ -356,7 +364,7 @@ Returns a pandas DataFrame object with the ticks returned by `historic_trades_v2
356364
### polygon/REST.historic_quotes_v2(symbol, date,timestamp=None, timestamp_limit=None, reverse=None, limit=None)
357365
Returns a `QuotesV2` which is a list of `Quote` entities.
358366

359-
- `date` is a date string such as '2018-2-2'. The returned quotes are from this day onyl.
367+
- `date` is a date string such as '2018-2-2'. The returned quotes are from this day only.
360368
- `timestamp` is an integer in Unix Epoch nanoseconds as the lower bound filter, exclusive.
361369
- `timestamp_limit` is an integer in Unix Epoch nanoseconds as the maximum timestamp allowed in the results.
362370
- `limit` is an integer for the number of ticks to return. Default and max is 50000.
@@ -371,8 +379,7 @@ object.
371379
- `multiplier` is an integer affecting the amount of data contained in each Agg object.
372380
- `timespan` is a string affecting the length of time represented by each Agg object. It is one of the following values:
373381
- `minute`, `hour`, `day`, `week`, `month`, `quarter`, `year`
374-
- `_from` is an Eastern Time timestamp string/object that filters the result
375-
for the lower bound, inclusive. we accept the date in these formats:
382+
- `_from` is an Eastern Time timestamp string/object that filters the result for the lower bound, inclusive. we accept the date in these formats:
376383
datetime.datetime, datetime.date, pd.Timestamp, datetime.timestamp,
377384
isoformat string (YYYY-MM-DD)
378385
- `to` is an Eastern Time timestamp string that filters the result for the upper bound, inclusive. we support the same formats as the _from field
@@ -437,10 +444,10 @@ aapl = api.alpha_vantage.historic_quotes('AAPL', adjusted=True, output_format='p
437444
```
438445

439446
## alpha_vantage/REST
440-
It is initialized through alpaca `REST` object.
447+
It is initialized through the alpaca `REST` object.
441448

442449
### alpha_vantage/REST.get(params=None)
443-
Customizable endpoint, where you can pass all keywords/paramters from the documentation:https://www.alphavantage.co/documentation/#
450+
Customizable endpoint, where you can pass all keywords/parameters from the documentation:https://www.alphavantage.co/documentation/#
444451

445452
Returns the specific customized data.
446453

@@ -478,13 +485,13 @@ Returns a `csv`, `json`, or `pandas` object of historical OHLCV data for the cry
478485
Returns a `csv`, `json`, or `pandas` object with the data from the techindicator of choice.
479486

480487
### alpha_vantage/REST.sector()
481-
Returns a `json` of the currrency sector performances.
488+
Returns a `json` of the currency sector performances.
482489

483490
## Support and Contribution
484491

485492
For technical issues particular to this module, please report the
486493
issue on this GitHub repository. Any API issues can be reported through
487494
Alpaca's customer support.
488495

489-
New features, as well as bug fixes, by sending pull request is always
496+
New features, as well as bug fixes, by sending a pull request is always
490497
welcomed.

alpaca_trade_api/common.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,11 @@ class FLOAT(str):
4848
invalid strings all the way to the servers.
4949
"""
5050
def __new__(cls, value):
51-
if not value:
52-
raise ValueError('Unexpected empty string')
5351
if isinstance(value, float) or isinstance(value, int):
54-
pass # we're good
55-
elif isinstance(value, str):
56-
value = value.strip() # make sure no spaces
57-
if isinstance(float(value), float):
58-
pass # we're good
59-
else:
60-
raise ValueError(f'Unexpected float format "{value}"')
61-
return value
52+
return value
53+
if isinstance(value, str):
54+
return float(value.strip())
55+
raise ValueError(f'Unexpected float format "{value}"')
6256

6357

6458
def get_base_url() -> URL:

requirements/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
pandas>1,<2
1+
pandas # pyup: ignore
22
requests>2,<3
33
urllib3>1.24,<1.26
44
websocket-client>=0.56.0,<1

0 commit comments

Comments
 (0)