From d209d79bd2e225c82826b10e764469172fa114fa Mon Sep 17 00:00:00 2001 From: Dmitriy Tatarkin Date: Tue, 20 Aug 2024 05:05:54 +0300 Subject: [PATCH] Fix `Transfer` pydantic model to properly handle optional `relationship_id`, `expires_at` and `updated_at` fields from Retrieve List of Transfers API for an Account endpoint (#496) --- LICENSE | 2 +- alpaca/broker/models/funding.py | 7 +++--- alpaca/data/historical/utils.py | 4 +-- docs/_templates/base.html | 4 +-- docs/_templates/page.html | 2 +- docs/_templates/sidebar/navigation.html | 2 +- .../broker/account_activities.rst | 3 --- docs/api_reference/broker/accounts.rst | 2 -- docs/api_reference/broker/assets.rst | 2 +- docs/api_reference/broker/broker-client.rst | 1 - docs/api_reference/broker/calendar.rst | 1 - docs/api_reference/broker/clock.rst | 1 - docs/api_reference/broker/funding.rst | 10 -------- docs/api_reference/broker/journals.rst | 1 - docs/api_reference/broker/requests.rst | 1 - docs/api_reference/broker/trading.rst | 2 -- docs/api_reference/broker/trading/orders.rst | 1 - .../broker/trading/portfolio-history.rst | 2 -- .../broker/trading/positions.rst | 2 +- docs/api_reference/broker_api.rst | 1 - docs/api_reference/data/crypto/historical.rst | 1 - docs/api_reference/data/crypto/requests.rst | 2 +- docs/api_reference/data/enums.rst | 2 +- docs/api_reference/data/models.rst | 1 - docs/api_reference/data/stock/historical.rst | 1 - docs/api_reference/data/stock/live.rst | 2 +- docs/api_reference/data/stock/requests.rst | 2 +- docs/api_reference/data/stock/screener.rst | 2 +- docs/api_reference/data_api.rst | 2 -- docs/api_reference/trading/account.rst | 1 - docs/api_reference/trading/assets.rst | 2 -- docs/api_reference/trading/calendar.rst | 4 --- docs/api_reference/trading/clock.rst | 2 +- docs/api_reference/trading/contracts.rst | 2 -- docs/api_reference/trading/orders.rst | 2 +- docs/api_reference/trading/requests.rst | 8 ------ docs/api_reference/trading/trading-client.rst | 2 +- docs/api_reference/trading/watchlists.rst | 1 - docs/api_reference/trading_api.rst | 1 - docs/broker.rst | 5 ---- docs/getting_started.rst | 3 --- docs/index.rst | 8 +++--- docs/market_data.rst | 8 ++---- docs/trading.rst | 3 --- examples/README.md | 2 +- .../broker_client/test_funding_routes.py | 25 ++++++++++--------- 46 files changed, 40 insertions(+), 105 deletions(-) diff --git a/LICENSE b/LICENSE index 94cfc030..424a4eb4 100644 --- a/LICENSE +++ b/LICENSE @@ -198,4 +198,4 @@ Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and -limitations under the License. \ No newline at end of file +limitations under the License. diff --git a/alpaca/broker/models/funding.py b/alpaca/broker/models/funding.py index fcdc0bde..d2acd4b4 100644 --- a/alpaca/broker/models/funding.py +++ b/alpaca/broker/models/funding.py @@ -99,9 +99,10 @@ class Transfer(ModelWithID): account_id: UUID created_at: datetime - updated_at: datetime - expires_at: datetime - relationship_id: UUID + updated_at: Optional[datetime] = None + expires_at: Optional[datetime] = None + relationship_id: Optional[UUID] = None + bank_id: Optional[UUID] = None amount: str type: TransferType status: TransferStatus diff --git a/alpaca/data/historical/utils.py b/alpaca/data/historical/utils.py index 6b238e0c..27709a78 100644 --- a/alpaca/data/historical/utils.py +++ b/alpaca/data/historical/utils.py @@ -5,9 +5,9 @@ """ These functions were created and put in this file to handle all of the edge cases -for parsing data that exist in the market data API. +for parsing data that exist in the market data API. -v2/stocks and v1beta2/crypto +v2/stocks and v1beta2/crypto """ diff --git a/docs/_templates/base.html b/docs/_templates/base.html index 97f737c7..24209505 100644 --- a/docs/_templates/base.html +++ b/docs/_templates/base.html @@ -98,7 +98,7 @@ if (!cta) return; cta.addEventListener("click", function() { const eventName = window.location.pathname.includes("broker") - ? "docs_python_sdk_broker_cta_clicked" + ? "docs_python_sdk_broker_cta_clicked" : "docs_python_sdk_lpca_cta_clicked"; amplitude.getInstance().logEvent(eventName,{ url, @@ -119,4 +119,4 @@ }).join("").trim(); } -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/docs/_templates/page.html b/docs/_templates/page.html index 27def55d..0f51b91c 100644 --- a/docs/_templates/page.html +++ b/docs/_templates/page.html @@ -245,4 +245,4 @@ -{%- endblock %} \ No newline at end of file +{%- endblock %} diff --git a/docs/_templates/sidebar/navigation.html b/docs/_templates/sidebar/navigation.html index 3ac6e48a..fcdc4a60 100644 --- a/docs/_templates/sidebar/navigation.html +++ b/docs/_templates/sidebar/navigation.html @@ -18,4 +18,4 @@ Community - \ No newline at end of file + diff --git a/docs/api_reference/broker/account_activities.rst b/docs/api_reference/broker/account_activities.rst index 4a73d2f3..3d725741 100644 --- a/docs/api_reference/broker/account_activities.rst +++ b/docs/api_reference/broker/account_activities.rst @@ -7,6 +7,3 @@ Get Account Activities ---------------------- .. automethod:: alpaca.broker.client.BrokerClient.get_account_activities - - - diff --git a/docs/api_reference/broker/accounts.rst b/docs/api_reference/broker/accounts.rst index b1cd6bf2..1937688c 100644 --- a/docs/api_reference/broker/accounts.rst +++ b/docs/api_reference/broker/accounts.rst @@ -56,5 +56,3 @@ Update Trade Configuration For Account -------------------------------------- .. automethod:: alpaca.broker.client.BrokerClient.update_trade_configuration_for_account - - diff --git a/docs/api_reference/broker/assets.rst b/docs/api_reference/broker/assets.rst index 57b862c0..a82547d6 100644 --- a/docs/api_reference/broker/assets.rst +++ b/docs/api_reference/broker/assets.rst @@ -15,4 +15,4 @@ Get All Assets Get a Single Asset ------------------ -.. automethod:: alpaca.broker.client.BrokerClient.get_asset \ No newline at end of file +.. automethod:: alpaca.broker.client.BrokerClient.get_asset diff --git a/docs/api_reference/broker/broker-client.rst b/docs/api_reference/broker/broker-client.rst index 1b1c9c0a..52408733 100644 --- a/docs/api_reference/broker/broker-client.rst +++ b/docs/api_reference/broker/broker-client.rst @@ -4,4 +4,3 @@ BrokerClient .. autoclass:: alpaca.broker.client.BrokerClient :members: __init__ - diff --git a/docs/api_reference/broker/calendar.rst b/docs/api_reference/broker/calendar.rst index 1fd53078..f8f3f798 100644 --- a/docs/api_reference/broker/calendar.rst +++ b/docs/api_reference/broker/calendar.rst @@ -5,4 +5,3 @@ Get Market Calendar ------------------- .. automethod:: alpaca.broker.client.BrokerClient.get_calendar - diff --git a/docs/api_reference/broker/clock.rst b/docs/api_reference/broker/clock.rst index c1ff1299..ecfe8443 100644 --- a/docs/api_reference/broker/clock.rst +++ b/docs/api_reference/broker/clock.rst @@ -7,4 +7,3 @@ Get Market Clock ---------------- .. automethod:: alpaca.broker.client.BrokerClient.get_clock - diff --git a/docs/api_reference/broker/funding.rst b/docs/api_reference/broker/funding.rst index 60f3c5e3..9ee04fb4 100644 --- a/docs/api_reference/broker/funding.rst +++ b/docs/api_reference/broker/funding.rst @@ -55,13 +55,3 @@ Cancel Transfer For Account --------------------------- .. automethod:: alpaca.broker.client.BrokerClient.cancel_transfer_for_account - - - - - - - - - - diff --git a/docs/api_reference/broker/journals.rst b/docs/api_reference/broker/journals.rst index f9b90e95..59aeaa9f 100644 --- a/docs/api_reference/broker/journals.rst +++ b/docs/api_reference/broker/journals.rst @@ -37,4 +37,3 @@ Cancel Journal by ID -------------------- .. automethod:: alpaca.broker.client.BrokerClient.cancel_journal_by_id - diff --git a/docs/api_reference/broker/requests.rst b/docs/api_reference/broker/requests.rst index 5ad379ea..a9e57894 100644 --- a/docs/api_reference/broker/requests.rst +++ b/docs/api_reference/broker/requests.rst @@ -163,4 +163,3 @@ GetJournalsRequest ------------------ .. autoclass:: alpaca.broker.requests.GetJournalsRequest - diff --git a/docs/api_reference/broker/trading.rst b/docs/api_reference/broker/trading.rst index 922f4549..78e1e260 100644 --- a/docs/api_reference/broker/trading.rst +++ b/docs/api_reference/broker/trading.rst @@ -10,5 +10,3 @@ Trading trading/positions trading/portfolio-history trading/watchlists - - diff --git a/docs/api_reference/broker/trading/orders.rst b/docs/api_reference/broker/trading/orders.rst index e93888ac..666fa5b9 100644 --- a/docs/api_reference/broker/trading/orders.rst +++ b/docs/api_reference/broker/trading/orders.rst @@ -43,4 +43,3 @@ Cancel an Order For Account By Id --------------------------------- .. automethod:: alpaca.broker.client.BrokerClient.cancel_order_for_account_by_id - diff --git a/docs/api_reference/broker/trading/portfolio-history.rst b/docs/api_reference/broker/trading/portfolio-history.rst index 1b50a29d..37321e4f 100644 --- a/docs/api_reference/broker/trading/portfolio-history.rst +++ b/docs/api_reference/broker/trading/portfolio-history.rst @@ -7,5 +7,3 @@ Get Portfolio History For Account --------------------------------- .. automethod:: alpaca.broker.client.BrokerClient.get_portfolio_history_for_account - - diff --git a/docs/api_reference/broker/trading/positions.rst b/docs/api_reference/broker/trading/positions.rst index b75f3396..563404b8 100644 --- a/docs/api_reference/broker/trading/positions.rst +++ b/docs/api_reference/broker/trading/positions.rst @@ -24,4 +24,4 @@ Close All Positions For Account Close A Position For Account ---------------------------- -.. automethod:: alpaca.broker.client.BrokerClient.close_position_for_account \ No newline at end of file +.. automethod:: alpaca.broker.client.BrokerClient.close_position_for_account diff --git a/docs/api_reference/broker_api.rst b/docs/api_reference/broker_api.rst index 9b40aa8a..2b2fe849 100644 --- a/docs/api_reference/broker_api.rst +++ b/docs/api_reference/broker_api.rst @@ -24,4 +24,3 @@ Contents broker/models broker/requests broker/enums - diff --git a/docs/api_reference/data/crypto/historical.rst b/docs/api_reference/data/crypto/historical.rst index 2ecbd906..56d7b5a2 100644 --- a/docs/api_reference/data/crypto/historical.rst +++ b/docs/api_reference/data/crypto/historical.rst @@ -50,4 +50,3 @@ Get Crypto Latest Orderbook --------------------------- .. automethod:: alpaca.data.historical.crypto.CryptoHistoricalDataClient.get_crypto_latest_orderbook - diff --git a/docs/api_reference/data/crypto/requests.rst b/docs/api_reference/data/crypto/requests.rst index 2b289680..0357c204 100644 --- a/docs/api_reference/data/crypto/requests.rst +++ b/docs/api_reference/data/crypto/requests.rst @@ -36,4 +36,4 @@ CryptoLatestTradeRequest CryptoSnapshotRequest --------------------- -.. autoclass:: alpaca.data.requests.CryptoSnapshotRequest \ No newline at end of file +.. autoclass:: alpaca.data.requests.CryptoSnapshotRequest diff --git a/docs/api_reference/data/enums.rst b/docs/api_reference/data/enums.rst index e0b588dc..1d16786e 100644 --- a/docs/api_reference/data/enums.rst +++ b/docs/api_reference/data/enums.rst @@ -36,4 +36,4 @@ MostActivesBy MarketType ---------- -.. autoclass:: alpaca.data.enums.MarketType \ No newline at end of file +.. autoclass:: alpaca.data.enums.MarketType diff --git a/docs/api_reference/data/models.rst b/docs/api_reference/data/models.rst index 56143bc5..6bc36296 100644 --- a/docs/api_reference/data/models.rst +++ b/docs/api_reference/data/models.rst @@ -99,4 +99,3 @@ Movers ------ .. autoclass:: alpaca.data.models.screener.Movers - diff --git a/docs/api_reference/data/stock/historical.rst b/docs/api_reference/data/stock/historical.rst index 4c650445..ce572b85 100644 --- a/docs/api_reference/data/stock/historical.rst +++ b/docs/api_reference/data/stock/historical.rst @@ -48,4 +48,3 @@ Get Stock Snapshot ------------------ .. automethod:: alpaca.data.historical.stock.StockHistoricalDataClient.get_stock_snapshot - diff --git a/docs/api_reference/data/stock/live.rst b/docs/api_reference/data/stock/live.rst index 2d14e607..796b5cc5 100644 --- a/docs/api_reference/data/stock/live.rst +++ b/docs/api_reference/data/stock/live.rst @@ -8,4 +8,4 @@ StockDataStream .. autoclass:: alpaca.data.live.stock.StockDataStream :members: - :inherited-members: \ No newline at end of file + :inherited-members: diff --git a/docs/api_reference/data/stock/requests.rst b/docs/api_reference/data/stock/requests.rst index b3ffa419..f3f08d08 100644 --- a/docs/api_reference/data/stock/requests.rst +++ b/docs/api_reference/data/stock/requests.rst @@ -54,4 +54,4 @@ MostActivesRequest MarketMoversRequest ------------------- -.. autoclass:: alpaca.data.requests.MarketMoversRequest \ No newline at end of file +.. autoclass:: alpaca.data.requests.MarketMoversRequest diff --git a/docs/api_reference/data/stock/screener.rst b/docs/api_reference/data/stock/screener.rst index 894c84f6..0df3f8ef 100644 --- a/docs/api_reference/data/stock/screener.rst +++ b/docs/api_reference/data/stock/screener.rst @@ -18,4 +18,4 @@ Get Most Actives Get Market Movers ----------------- -.. automethod:: alpaca.data.historical.screener.ScreenerClient.get_market_movers \ No newline at end of file +.. automethod:: alpaca.data.historical.screener.ScreenerClient.get_market_movers diff --git a/docs/api_reference/data_api.rst b/docs/api_reference/data_api.rst index 0023d223..b9c7c493 100644 --- a/docs/api_reference/data_api.rst +++ b/docs/api_reference/data_api.rst @@ -12,5 +12,3 @@ Market Data Reference data/timeframe data/models data/enums - - diff --git a/docs/api_reference/trading/account.rst b/docs/api_reference/trading/account.rst index d87ed464..7770bbed 100644 --- a/docs/api_reference/trading/account.rst +++ b/docs/api_reference/trading/account.rst @@ -10,4 +10,3 @@ Get Account Details ------------------- .. automethod:: alpaca.trading.client.TradingClient.get_account - diff --git a/docs/api_reference/trading/assets.rst b/docs/api_reference/trading/assets.rst index 533753a7..647221a6 100644 --- a/docs/api_reference/trading/assets.rst +++ b/docs/api_reference/trading/assets.rst @@ -15,5 +15,3 @@ Get Asset --------- .. automethod:: alpaca.trading.client.TradingClient.get_asset - - diff --git a/docs/api_reference/trading/calendar.rst b/docs/api_reference/trading/calendar.rst index 54f07cb4..75a44049 100644 --- a/docs/api_reference/trading/calendar.rst +++ b/docs/api_reference/trading/calendar.rst @@ -11,7 +11,3 @@ Get Calendar ------------ .. automethod:: alpaca.trading.client.TradingClient.get_calendar - - - - diff --git a/docs/api_reference/trading/clock.rst b/docs/api_reference/trading/clock.rst index f4ed6233..6d8ca053 100644 --- a/docs/api_reference/trading/clock.rst +++ b/docs/api_reference/trading/clock.rst @@ -10,4 +10,4 @@ of the trading hours for a given day. Get Clock --------- -.. automethod:: alpaca.trading.client.TradingClient.get_clock \ No newline at end of file +.. automethod:: alpaca.trading.client.TradingClient.get_clock diff --git a/docs/api_reference/trading/contracts.rst b/docs/api_reference/trading/contracts.rst index bcc29b44..65cf7c6a 100644 --- a/docs/api_reference/trading/contracts.rst +++ b/docs/api_reference/trading/contracts.rst @@ -14,5 +14,3 @@ Get Option Contract ------------------- .. automethod:: alpaca.trading.client.TradingClient.get_option_contract - - diff --git a/docs/api_reference/trading/orders.rst b/docs/api_reference/trading/orders.rst index f43897eb..ea9c1421 100644 --- a/docs/api_reference/trading/orders.rst +++ b/docs/api_reference/trading/orders.rst @@ -35,4 +35,4 @@ Cancel All Orders Cancel Order By Id ------------------ -.. automethod:: alpaca.trading.client.TradingClient.cancel_order_by_id \ No newline at end of file +.. automethod:: alpaca.trading.client.TradingClient.cancel_order_by_id diff --git a/docs/api_reference/trading/requests.rst b/docs/api_reference/trading/requests.rst index 40fc60d0..f9b4b6c2 100644 --- a/docs/api_reference/trading/requests.rst +++ b/docs/api_reference/trading/requests.rst @@ -114,11 +114,3 @@ GetCorporateAnnouncementsRequest -------------------------------- .. autoclass:: alpaca.trading.requests.GetCorporateAnnouncementsRequest - - - - - - - - diff --git a/docs/api_reference/trading/trading-client.rst b/docs/api_reference/trading/trading-client.rst index 3356315b..bca00090 100644 --- a/docs/api_reference/trading/trading-client.rst +++ b/docs/api_reference/trading/trading-client.rst @@ -3,4 +3,4 @@ TradingClient ============= .. autoclass:: alpaca.trading.client.TradingClient - :members: __init__ \ No newline at end of file + :members: __init__ diff --git a/docs/api_reference/trading/watchlists.rst b/docs/api_reference/trading/watchlists.rst index b044d085..eae9c320 100644 --- a/docs/api_reference/trading/watchlists.rst +++ b/docs/api_reference/trading/watchlists.rst @@ -46,4 +46,3 @@ Delete Watchlist By Id ---------------------- .. automethod:: alpaca.trading.client.TradingClient.delete_watchlist_by_id - diff --git a/docs/api_reference/trading_api.rst b/docs/api_reference/trading_api.rst index 8ad28bcb..76288e74 100644 --- a/docs/api_reference/trading_api.rst +++ b/docs/api_reference/trading_api.rst @@ -22,4 +22,3 @@ Contents trading/models trading/requests trading/enums - diff --git a/docs/broker.rst b/docs/broker.rst index 2dfcbbef..e611dd06 100644 --- a/docs/broker.rst +++ b/docs/broker.rst @@ -401,8 +401,3 @@ This will return a list of ``Position`` objects. account_id = "c8f1ef5d-edc0-4f23-9ee4-378f19cb92a4" positions = broker_client.get_all_positions_for_account(account_id=account_id) - - - - - diff --git a/docs/getting_started.rst b/docs/getting_started.rst index 5d5abe1e..4bdc8b4a 100644 --- a/docs/getting_started.rst +++ b/docs/getting_started.rst @@ -158,6 +158,3 @@ Broker API To use the Broker API, you will need to sign up for a `broker account `_ and retrieve your Broker API keys. The API keys can be found on the dashboard once you've logged in. Alpaca also provides a sandbox environment to test out Broker API. To use the sandbox mode, provide your sandbox keys. Once you have your keys, you can pass them into ``BrokerClient`` to get started. - - - diff --git a/docs/index.rst b/docs/index.rst index 5b6a1f28..b2063f36 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -10,19 +10,19 @@ .. meta:: :image: https://alpaca.markets/static/images/meta-image-alpaca-py.png :description: The Official Python SDK for Alpaca's Suite of APIs - + Alpaca-py Documentation ======================= .. container:: homepage-banner - + .. image:: images/alpaca-py-banner.png :alt: The official Python SDK for Alpaca's APIs. -.. container:: badges-row +.. container:: badges-row |GitHub stars| @@ -100,5 +100,3 @@ Here are some libraries that work well with Alpaca-py. * `Plaid `_ - Connect user banking information. * `Onfido `_ - Identity verification / KYC. - - diff --git a/docs/market_data.rst b/docs/market_data.rst index 0847ef83..854b2db1 100644 --- a/docs/market_data.rst +++ b/docs/market_data.rst @@ -4,8 +4,8 @@ Market Data =========== -The market data API allows you to access both live and historical data for equities, cryptocurrencies, and options. -Over 5 years of historical data is available for thousands of equity and cryptocurrency symbols. +The market data API allows you to access both live and historical data for equities, cryptocurrencies, and options. +Over 5 years of historical data is available for thousands of equity and cryptocurrency symbols. Various data types are available such as bars/candles (OHLCV), trade data (price and sales), and quote data. For crypto, there is also orderbook data. For more information on the data types available, please look at the `API reference `_. @@ -192,7 +192,3 @@ Finally, you will need to call the ``run`` method to start receiving data. wss_client.subscribe_quotes(quote_data_handler, "SPY") wss_client.run() - - - - diff --git a/docs/trading.rst b/docs/trading.rst index d80be4cc..96ebbf4a 100644 --- a/docs/trading.rst +++ b/docs/trading.rst @@ -250,6 +250,3 @@ Here is an example # start our websocket streaming trading_stream.run() - - - diff --git a/examples/README.md b/examples/README.md index a3c9bcc1..b34b6910 100644 --- a/examples/README.md +++ b/examples/README.md @@ -1,6 +1,6 @@ ## Google Colab Notebooks -Explore the examples for Stocks, Options, and Crypto utilizing alpaca-py in the notebooks provided below. Open them in Google Colab to jumpstart your development journey! +Explore the examples for Stocks, Options, and Crypto utilizing alpaca-py in the notebooks provided below. Open them in Google Colab to jumpstart your development journey! | Notebooks | Open in Google Colab | | :--------------------------------------------------------------------------------------- | :-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | diff --git a/tests/broker/broker_client/test_funding_routes.py b/tests/broker/broker_client/test_funding_routes.py index 453dd693..c27ed3cc 100644 --- a/tests/broker/broker_client/test_funding_routes.py +++ b/tests/broker/broker_client/test_funding_routes.py @@ -266,19 +266,20 @@ def setup_reqmock_for_paginated_transfers_response(account_id, reqmock): resp_one = """ [ { - "id": "be3c368a-4c7c-4384-808e-f02c9f5a8afe", - "relationship_id": "0f08c6bc-8e9f-463d-a73f-fd047fdb5e94", - "account_id": "2a87c088-ffb6-472b-a4a3-cd9305c8605c", - "type": "ach", - "status": "COMPLETE", - "reason": null, - "amount": "498", + "id": "bf438b6d-4ea3-4241-9e1c-a0e55b47f4e0", + "account_id": "2d6cab28-c5d1-4ff8-91c6-b6404a9ee114", + "type": "wire", + "status": "CANCELED", + "currency": "USD", + "amount": "100", + "instant_amount": "0", "direction": "INCOMING", - "created_at": "2021-05-05T07:55:31.190788Z", - "updated_at": "2021-05-05T08:13:33.029539Z", - "expires_at": "2021-05-12T07:55:31.190719Z", - "requested_amount": "500", - "fee": "2", + "created_at": "2024-07-15T13:40:01.963459Z", + "updated_at": "2024-07-22T08:22:29.990176Z", + "reason": null, + "hold_until": null, + "requested_amount": "100", + "fee": "0", "fee_payment_method": "user" }, {