Trading Bot Club alpaca api
Project description
tbc-ken-lib
This lib is made for to be used by members of the TBC club made in 2022.
Install
$ pip install tbc-ken-lib
Supported Features
tbc-ken-lib has and will only have functions that will be used for the project. Other functions that other Alpaca API clients may include that will not be used by the club will not be included in this lib.
This lib is made for to be used by members of the TBC club made in 2022.
Install
Make sure python3 and pip is installed globally in your system. Write or paste the script into your bash terminal.
$ pip install tbc-ken-lib
Latest Supported Features
tbc-ken-lib has and will only have functions that will be used for the project. Other functions that other Alpaca API clients may include that will not be used by the club will not be included in this lib.
- Get a list of symbols
- Get any asset's market history
- Get general information of any assets
- Access owned assets and positions
- View account informations
- Sell assets
- Buy assets
Unticked features will be coming in the next versions.
Examples
Index
Setup
Install the module from https://pypi.org Follow this link and generate an API key: https://app.alpaca.markets/paper/dashboard/overview Don't worry if you lose the key or forgot where you saved it. You can always regenerate them.
#example.py
import ken_api
api = ken_api.api(
'XXXXXXXXXXXXXXXXXXXX', # alpaca api key (20 characters in length)
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" # alpaca api secret (40 characters in length)
)
# The alpaca api key and secret almost feels like user and password sometimes.
# If you don't have your own keys, you can use mine up there, though it is limitted to 200 api requests per minute.
# It's recommended to use your own keys.
Get Assets
get_assets: (*symbols: str, **simple: bool) -> (dict | int)
Get basic info of any stocks by putting in symbols.
Put in simple=True to make the result come in a simple format.
"""
You can put in one symbol or many symbols.
Without having the simple=True, it will return you much more data.
"""
print(api.get_assets('SXNTF', "SWSSF", "MANR", simple=True))
print(api.get_assets('PCSGF', simple=True))
print(api.get_assets('PCSGF'))
Get Bars
get_bars: (symbol: Any, **kwargs: Any) -> (list | int)
This function simply returns a List of dicts representing each candle in a 1 day time frame.
# Get candles of a symbol.
#You can specify the start, end, and limit. (optional)
print(api.get_bars("TSLA", start="2022-10-05", end="2022-10-15"))
Expected return format
t: string/timestamp Timestamp in RFC-3339 format with nanosecond precision
o: number Open price
h: number High price
c: number Close price
v: int Volume
n: int Number of trades
vw: number Volume-weighted average price
Download Assets
download_symbols: (path) -> (dict | int)
The function downloads a list of all stocks and assets Alpaca has, both active and inactive. It also takes no parameters
api.download_symbols()
# This function doesn't return anything. The result will be downloaded as symbols_list in your current working directory without a file extension.
Expected file content
asset_id: Asset ID
symbol: Symbol name of the asset
exchange: Exchange name of the asset (ErisX for crypto)
asset_class: Asset class name
avg_entry_price: Average entry price of the position
qty: The number of shares
qty_available: Total number of shares available minus open orders
side: “long”
market_value: Total dollar amount of the position
cost_basis: Total cost basis in dollar
unrealized_pl: Unrealized profit/loss in dollars
unrealized_plpc: Unrealized profit/loss percent (by a factor of 1)
unrealized_intraday_pl: Unrealized profit/loss in dollars for the day
unrealized_intraday_plpc: Unrealized profit/loss percent (by a factor of 1)
current_price: Current asset price per share
lastday_price: Last day’s asset price per share based on the closing value of the last trading day
change_today: Percent change from last day price (by a factor of 1)
Get Positions
get_positions: (symbol: str = "") -> (list | int)
Returns owned assets' info or a specific asset's info.
params str symbol: specific symbol of an asset you want to get the position.
api.get_positions("TSLA")
# This will return your TSLA assets.
Expected file content
asset_id: asset's id
symbol: asset's symbol
exchange: just expect "us-equity"
id: asset's id
status: either "active" or "inactive"
Get Account Information
get_account: () -> (dict | int)
Return account information
print(api.get_account())
# This will return your TSLA assets.
Expected return format
id: account id
account_number: account number
status: your account status:
"ONBOARDING"The account is onboarding."SUBMISSION_FAILED"The account application submission failed for some reason."SUBMITTED"The account application has been submitted for review."ACCOUNT_UPDATED"The account information is being updated."APPROVAL_PENDING"The final account approval is pending."ACTIVE"The account is active for trading."REJECTED"The account application has been rejected.
account_blocked: either "True" or "False"
equity: int
trading_blocked: either "True" or "False"
daytrade_count: int
ballance_asof: a date in YYYY-MM-DD format
position_market_value: int
created_at: timestamp in the format of yyyy-MM-dd'T'HH:mm:ss.SSS'Z'
currency: a currency, probably USD
buying_power: int
and much more useful information
Patches
v0.3.2
Added 2 functions. Made python 3.10 or above a requirement.
v0.3
To use this lib, it is recommended to put your own api **key** and **secret** in your api object parameters. If not, you will automatically use mine, which has it's limits.
v0.2 and bellow
To use the lib, touch alpaca_credentials.json and place in it your credentials.
//alpaca_credentials.json
{
"APCA-API-KEY-ID": "PKNOZUSMT0A6E89QURCG",
"APCA-API-SECRET-KEY": "SXFTc5gC4cAWmUpuGEiEurBGfN4bAqhA6Mxu28Ez"
}
oad_symbols: (path:str) -> (dict | int)](#download-assets)
Examples
Setup
Follow this link and generate an API key: https://app.alpaca.markets/paper/dashboard/overview Don't worry if you lose the key or forgot where you saved it. You can always regenerate them.
#example.py
import ken_api
api = ken_api.api(
'XXXXXXXXXXXXXXXXXXXX', # alpaca api key (20 characters in length)
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" # alpaca api secret (40 characters in length)
)
# The alpaca api key and secret almost feels like user and password sometimes.
# If you don't have your own keys, you can use mine up there, though it is limitted to 200 api requests per minute.
# It's recommended to use your own keys.
Get Assets
"""
This one returns you candle bars of the graph.
You can specify the start, end, and even limit.
Get info of any stocks by putting in symbols.
Put in simple=True to make the result come in a simple format.
You can put in one symbol or many symbols.
Without having the simple=True, it will return you much more data.
"""
print(api.get_assets('SXNTF', "SWSSF", "MANR", simple=True))
print(api.get_assets('PCSGF', simple=True))
print(api.get_assets('PCSGF'))
print(api.get_bars("TSLA", start="2022-10-05", end="2022-10-15",limit=10))
Download Assets
"""
The function downloads a list of all stocks and assets Alpaca has,
both active and inactive. It also takes no parameters
"""
api.download_symbols()
# This function doesn't return anything. The result will be downloaded as symbols_list in your current working directory without a file extension.
Patches
v0.3.2
Added 2 functions. Made Python 3.10 or above a requirement.
v0.3
To use this lib, it is recommended to put your own api **key** and **secret** in your api object parameters. If not, you will automatically use mine, which has it's limits.
v0.2 and bellow
To use the lib, touch alpaca_credentials.json and place in it your credentials.
//alpaca_credentials.json
{
"APCA-API-KEY-ID": "PKNOZUSMT0A6E89QURCG",
"APCA-API-SECRET-KEY": "SXFTc5gC4cAWmUpuGEiEurBGfN4bAqhA6Mxu28Ez"
}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file tbc_ken_api-0.3.3.tar.gz.
File metadata
- Download URL: tbc_ken_api-0.3.3.tar.gz
- Upload date:
- Size: 5.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
28f31e5aa932b07c21a303809996f111757ba49dc8ea250e696218213a2c0474
|
|
| MD5 |
40f70c1ec8d88828ab97d5e0c55c9e9d
|
|
| BLAKE2b-256 |
5eb7bf9c14cd16d743869290bf6cf4b0e55f553f48bcd7984c7a136cdce93594
|