alpacahq / alpaca-py Goto Github PK
View Code? Open in Web Editor NEWThe Official Python SDK for Alpaca API
Home Page: https://docs.alpaca.markets/docs/getting-started-1
License: Apache License 2.0
The Official Python SDK for Alpaca API
Home Page: https://docs.alpaca.markets/docs/getting-started-1
License: Apache License 2.0
Implement the watchlists routes as seen here in the docs
Should add the following to BrokerClient:
def get_watchlists_for_account(
self,
account_id: Union[UUID, str],
) -> List[Watchlist]:
pass
def get_watchlist_for_account_by_id(
self,
account_id: Union[UUID, str],
watchlist_id: Union[UUID, str],
) -> Watchlist:
pass
def create_watchlist_for_account(
self,
account_id: Union[UUID, str],
watchlist_data: CreateWatchlistRequest
) -> Watchlist:
pass
def update_watchlist_for_account_by_id(
self,
# Might be worth taking a union of this an Watchlist itself; but then we should make a change like that SDK wide. Probably a good 0.2.x change
watchlist_data: CreateWatchlistRequest
) -> Watchlist:
pass
def add_asset_to_watchlist_for_account_by_id(
self,
account_id: Union[UUID, str],
watchlist_id: Union[UUID, str],
symbol_or_asset_id: Union[UUID, str]
) -> Watchlist:
pass
def delete_watchlist_from_account_by_id(
self,
account_id: Union[UUID, str],
watchlist_id: Union[UUID, str],
) -> None:
pass
def remove_asset_from_watchlist_for_account_by_id(
self,
account_id: Union[UUID, str],
watchlist_id: Union[UUID, str],
symbol_or_asset_id: Union[UUID, str]
) -> Watchlist:
pass
This is to implement the routes found in the docs here
Need to add:
def create_journal(
self,
journal_data: CreateJournalRequest,
) -> Journal:
pass
# The response format for the api for this one is a list of Journals with extra error message fields. BatchJournalResponse should just
# handle this by encapsulating an Optional Journal in it. But I'd also be okay with a polymorphic approach of success and error results.
def create_batch_journal(
self,
batch_data: CreateBatchJournalRequest,
) -> List[BatchJournalResponse]:
pass
def create_reverse_batch_journal(
self,
reverse_batch_data: CreateReverseBatchJournalRequest,
) -> List[BatchJournalResponse]:
pass
def get_journals(
self,
journal_filter: Optional[GetJournalsRequest] = None
) -> List[Journal]:
pass
def get_journal_by_id(
self,
journal_id: Union[UUID, str] = None
) -> Journal:
pass
def cancel_journal_by_id(
self,
journal_id: Union[UUID, str],
) -> None:
pass
I have searched in Google and documentation page:
https://alpaca.markets/docs/python-sdk/market_data.html
I couldn't find an example on how to get the stock bars with alpaca-py 0.5.4
Only example for crypto bars is provided.
With alpaca-trade-api 2.3.0
is as simple as this: api.get_bars("AAPL", '1Min')
Thanks in advance for your response.
Regards,
Implement routes defined the Trading API assets docs.
def get_assets(self, request: GetAssetsRequest) -> List[Asset]:
pass
def get_asset_by_symbol(self, symbol: str) -> Asset:
pass
Implement routes defined in Trading API account activities docs.
def get_account_activities_by_type(self, type: ActivityType, request: GetAccountActivitiesByTypeRequest) -> List[AccountActivity]:
pass
def get_account_activities(self, request: GetAccountActivitiesRequest) -> List[AccountActivity]:
pass
Being able to convert to dataframes greatly improve ability to view and manipulate data.
No response
No response
No response
When I use the default non raw_data in CryptoDataStream.subscribe_bars, it is missing the field exchange. If I change it to raw_data, I can see the exchange. I believe it is missing from the data/mappings.py and the data/models/bars.py.
When I use the subscribe_bars, I expect one of the returned values for the record should indicate what exchange it is from.
alpaca-py v0.5.0
Running on macOS Monterey 12.4, Python 3.9.10.
No response
Implement routes defined by Trading API portfolio history docs.
def get_portfolio_history(self, request: GetPortfolioHistoryRequest) -> PortfolioHistory:
pass
Implement routes found in docs here
def get_orders(self, request: GetOrdersRequest) -> List[Order]:
pass
def get_order_by_id(self, order_id: UUID, request: GetOrderByIdRequest) -> Order:
pass
def get_order_by_client_id(self, client_id: UUID, request: GetOrderByClientIdRequest) -> Order:
pass
def submit_order(self, request: OrderSubmissionRequest) -> Order:
pass
def cancel_order_by_id(self, order_id: UUID) -> None:
pass
def replace_order_by_id(self, order_id: UUID, request: ReplaceOrderRequest) -> None:
pass
def cancel_orders(self) -> None:
pass
When we add to docs/api_reference/broker/models
Order
-----
.. autoclass:: alpaca.broker.models.trading.Order
We will get
/Users/alpaca/Development/alpaca-py/alpaca/trading/models.py:docstring of alpaca.trading.models.Order:: WARNING: more than one target found for cross-reference 'Order': alpaca.broker.models.trading.Order, alpaca.trading.models.Order
Should be no error
v0.3.0
When we add to docs/api_reference/broker/models
Order
-----
.. autoclass:: alpaca.broker.models.trading.Order
We will get
/Users/alpaca/Development/alpaca-py/alpaca/trading/models.py:docstring of alpaca.trading.models.Order:: WARNING: more than one target found for cross-reference 'Order': alpaca.broker.models.trading.Order, alpaca.trading.models.Order
### Filled out the Steps to Reproduce section?
- [X] I have entered valid steps to reproduce my issue or have attached a minimally reproducible case in code that shows my issue happening; and understand that without this my issue will be flagged as invalid and closed after 30 days.
### Anything else?
Might be Sphinx bug
Implement the Positions related routes as seen here in the docs
Should add the following to BrokerClient:
Note the symbol_or_asset_id will need different UUID validation than what we currently use since it might be a symbol name. I think we'd be good enough to just check if UUID already and if not use it verbatim
def get_all_positions_for_account(
self,
account_id: Union[UUID, str],
) -> List[Position]:
pass
def get_open_position_for_account(
self,
account_id: Union[UUID, str],
symbol_or_asset_id: Union[UUID, str]
) -> Position:
pass
def close_all_positions_for_account(
self,
account_id: Union[UUID, str],
cancel_orders: bool
) -> List[ClosePositionReponse]:
pass
def close_position_for_account_by_id(
self,
account_id: Union[UUID, str],
symbol_or_asset_id: Union[UUID, str],
close_options: Optional[ClosePositionRequest] = None
) -> Order:
pass
Broker API does not support returning raw responses. It currently always wraps the responses in object models.
Ability to return response as given by API.
No response
No response
Implement routes found in the Trading API positions docs.
def get_positions(self) -> List[Position]:
pass
def get_position_by_symbol(self, symbol: str) -> Position:
pass
def close_all_positions(self, request: CloseAllPositionsRequest) -> None:
pass
def close_position_by_symbol(self, symbol: str, request: ClosePositionRequest) -> None:
pass
Yes.
Support Request Ticket Number: 60289
Right now, there is no way to cancel all orders for specific symbol.
You can only cancel all orders api.cancel_all_orders()
We need something like this:
api.cancel_orders('AAPL')
or something like this:
api.cancel_all_orders('AAPL')
or something like this:
api.cancel_all_orders(symbol='AAPL')
Keep it simple.
Keep it simple.
Implement routes found in Trading API account docs.
Routes to be implemented
def get_account(self) -> TradingAccount:
pass
_one_request
in common/rest.py returns response.json()
when response.text
is not empty. However, this can lead to issues when implementing routes that require the raw response. Furthermore, for empty responses (response.text = ""
), a NoneType is returned which does not contain status code information.
The methods affected are
download_trade_document_for_account_by_id
in broker/client
cancel_order_by_id
in trading/client
cancel_journal
in broker/client
No response
No response
No response
In alpaca.trading.client there are multiple locations where a an object of type "list" is compared to "List".
For example in get_orders:
if "symbols" in params and type(params["symbols"]) is List:
will produce False
even if symbols is a list.
Instead try using one of:
No response
0.5.2
Use function get_orders in alpaca.trading.client and pass a request with a list of symbols
No response
Currently API parameters are passed directly into the client methods, instead we should introduce request models similar to the other API clients.
No response
No response
No response
TradingStream cannot be import due to a missing import in alpaca.trading.init
No response
alpaca-py version: 0.5.2
Try importing trading stream:
from alpaca.trading.stream import TradingStream
No response
Currently during the alpha phase we are testing out different naming schemes to see what sticks. This ticket is to finalize on a naming scheme and rename all the methods to match.
Also need to once finalized update the CONTRIBUTING file with the new naming scheme
This is to implement the routes found here
Need to add to BrokerClient:
def create_transfer_for_account(
self,
account_id: Union[UUID, str],
transfer_data: CreateTransferRequest,
) -> Transfer:
pass
def get_transfers_for_account(
self,
account_id: Union[UUID, str],
) -> List[Transfer]:
pass
def cancel_transfer_for_account(
self,
account_id: Union[UUID, str],
transfer_id: Union[UUID, str],
) -> None:
pass
Is there a reason (a good reason) why this SDK requires pandas version 1.3.5?
I installed it yesterday to slowly ease into the new SDK. During installation, pandas was downgraded from 1.4.X to 1.3.5
This change broke my code. Turns out there are major improvements made to pandas since 1.3.5
All the trading models are inside of the common module. This makes sense in practice since these trading models are shared by the broker module and trading module. But this leaves the trading module empty. Instead, it may make sense to keep all trading related models within the trading module for better organization.
No response
No response
No response
Implement routes defined in Trading API calendar docs.
def get_calendar(self, request: GetMarketCalendarRequest) -> MarketCalendar:
pass
Currently, the API will throw an error if we try to close a position that is does not exist. The SDK does not handle this error, meaning if the user calls close_position
on a non-existing position, their code will throw an APIError.
Instead, the SDK should handle this error and return a FailedClosePositionDetails
object,
No response
No response
Crypto exchanges not supported in AssetExchange
No response
0.2.0
data = GetAssetsRequest(asset_class=AssetClass.CRYPTO)
print(broker_client.get_all_assets(data))
throws
value is not a valid enumeration member; permitted: 'AMEX', 'ARCA', 'BATS', 'NYSE', 'NASDAQ', 'NYSEARCA'
### Filled out the Steps to Reproduce section?
- [X] I have entered valid steps to reproduce my issue or have attached a minimally reproducible case in code that shows my issue happening; and understand that without this my issue will be flagged as invalid and closed after 30 days.
### Anything else?
_No response_
This is to implement the routes found here in the docs
Need to add in the following methods to BrokerClient:
def create_ach_relationship_for_account(
self,
account_id: Union[UUID, str],
ach_data: Union[CreateACHRelationshipRequest, CreatePlaidRelationshipRequest],
) -> ACHRelationship:
pass
# needs to handle both flows of creating with raw ACH data as well as with a Plaid Token.
def get_ach_relationships_for_account(
self,
account_id: Union[UUID, str],
statuses: Optional[List[ACHRelationshipStatus]] = None,
) -> List[ACHRelationship]:
pass
def delete_ach_relationship_for_account(
self,
account_id: Union[UUID, str],
ach_relationship_id: Union[UUID, str],
) -> None:
pass
Implement the Portfolio History routes as seen here in the docs
Should add the following to BrokerClient:
def get_portfolio_history_for_account(
self,
account_id: Union[UUID, str],
) -> PortfolioHistory:
pass
Implement the routes from the docs here
Also missing from the docs is a GET route for /v1/trading/accounts/{account_id}/account/configurations
that we should implement here
Should add the following interface to BrokerClient:
def get_trade_configuration_for_account(
self,
account_id: Union[UUID, str]
): -> TradeAccountConfiguration:
pass
def update_trade_configuration_for_account(
self,
account_id: Union[UUID, str],
config: UpdateTradeConfigurationRequest
)-> TradeAccountConfiguration:
pass
TimeFrame
only exists within the context of market data but it is currently in the common module. Instead, it should belong in market data.
No response
No response
No response
This is to implement the routes found here in the docs
Need to add to BrokerClient:
def create_bank_for_account(
self,
account_id: Union[UUID, str],
bank_data: CreateBankRequest,
) -> Bank:
pass
def get_banks_for_account(
self,
account_id: Union[UUID, str],
) -> List[Bank]:
pass
def delete_bank_for_account(
self,
account_id: Union[UUID, str],
bank_id: Union[UUID, str],
) -> None:
pass
Trading API currently always wraps API responses in object models. It does not allow the ability to return raw responses.
The ability to return responses as given by API before wrapping in object models.
No response
No response
Currently releases to PyPi must be done manually through poetry build & poetry publish
.
Use GitHub actions to publish to PyPi
No response
No response
I have searched in Google and documentation page:
https://alpaca.markets/docs/python-sdk/market_data.html
I couldn't find an example on how to get the latest trade with alpaca-py 0.5.3
With alpaca-trade-api 2.3.0
is as simple as this: api.get_latest_trade("AAPL")
Thanks in advance for your response.
Regards,
Implement the Order related routes as seen here in the docs
Should add the following to BrokerClient:
def create_order_for_account(
self,
account_id: Union[UUID, str],
order: CreateOrderRequest
) -> Order:
pass
def get_orders_for_account(
self,
account_id: Union[UUID, str],
order_filter: GetOrdersRequest
) -> List[Order]:
pass
def get_order_for_account_by_id(
self,
account_id: Union[UUID, str],
order_id: Union[UUID, str],
nested: Optional[bool] = None,
) -> Order:
pass
def get_order_for_account_by_client_order_id(
self,
account_id: Union[UUID, str],
client_order_id: Union[UUID, str],
nested: Optional[bool] = None,
) -> Order:
pass
def replace_order_for_account_by_id(
self,
account_id: Union[UUID, str],
order_id: Union[UUID, str],
replace_data: ReplaceOrderRequest,
) -> Order:
pass
def close_all_open_orders_for_account(
self,
account_id: Union[UUID, str],
) -> List[OrderCancelationResponse]:
pass
def close_order_for_account_by_id(
self,
account_id: Union[UUID, str],
order_id: Union[UUID, str],
) -> None:
pass
The API currently defaults the time in force to day if not provided since it is the most common time in force. The OrderRequest
model should reflect this by setting the default value for time_in_force
to TimeInForce.DAY
.
No response
No response
No response
ClosePositionResponse is needed because the response can vary on whether there is an open position or not. Furthermore, for non-existing positions, there can be varying responses depending on whether there is an open order for that symbol.
No response
No response
No response
Implement routes defined in Trading API account configurations docs.
Note Update endpoint doesn't take params??
def get_account_configurations(self) -> TradingAccountConfigurations:
pass
def update_account_configuration(self) -> TradingAccountConfigurations:
pass
Implement routes defined in Trading API Corporate Announcement docs.
def get_corporate_annoucements(self, request: GetCorporateAnnouncementsRequest) -> List[CorporateAnnouncement]:
pass
def get_corporate_announcment_by_id(self, corporate_announcment_id: UUID) -> Announcement:
pass
AccountCreationRequest
, AccountUpdateRequest
should follow similar naming to other request models.
rename AccountCreationRequest
to CreateAccountRequest
rename AccountUpdateRequest
to UpdateAccountRequest
rename OrderRequest
to GetOrderRequest
No response
No response
Implement routes found in Trading API Clock docs.
def get_clock(self) -> MarketClock:
pass
Add code coverage tests to CI. We can add a minimum code coverage to ensure higher levels of code quality.
No response
No response
No response
I have searched in Google and documentation page:
https://alpaca.markets/docs/python-sdk/trading.html
I couldn't find an example on how to cancel a single order with alpaca-py 0.5.4
You only provide an example to cancel all orders
With alpaca-trade-api 2.3.0
is as simple as this: api.cancel_order('3e4aab784-5965-491b-aedd-ba31b4dd0d59')
Thanks in advance for your response.
Regards,
Implement routes defined in the Trading API watchlists docs.
def get_watchlists(self) -> List[Watchlist]:
pass
def create_watchlist(self, request: CreateWatchlistRequest) -> Watchlist:
pass
def get_watchlist_by_id(self, watchlist_id: UUID) -> Watchlist:
pass
def update_watchlist_by_id(self, watchlist_id: UUID) -> Watchlist:
pass
def add_asset_to_watchlist_by_id(self, watchlist_id: UUID, request: AddAssetToWatchlistRequest) -> Watchlist:
pass
def delete_watchlist_by_id(self, watchlist_id: UUID) -> None:
pass
def remove_symbol_from_watchlist_by_id(self, watchlist_id: UUID, symbol: str) -> Watchlist:
pass
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.