alpaca-py-nopandas 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. alpaca/__init__.py +2 -0
  2. alpaca/broker/__init__.py +8 -0
  3. alpaca/broker/client.py +2360 -0
  4. alpaca/broker/enums.py +528 -0
  5. alpaca/broker/models/__init__.py +7 -0
  6. alpaca/broker/models/accounts.py +347 -0
  7. alpaca/broker/models/cip.py +265 -0
  8. alpaca/broker/models/documents.py +159 -0
  9. alpaca/broker/models/funding.py +114 -0
  10. alpaca/broker/models/journals.py +71 -0
  11. alpaca/broker/models/rebalancing.py +80 -0
  12. alpaca/broker/models/trading.py +13 -0
  13. alpaca/broker/requests.py +1135 -0
  14. alpaca/common/__init__.py +6 -0
  15. alpaca/common/constants.py +13 -0
  16. alpaca/common/enums.py +64 -0
  17. alpaca/common/exceptions.py +47 -0
  18. alpaca/common/models.py +21 -0
  19. alpaca/common/requests.py +82 -0
  20. alpaca/common/rest.py +438 -0
  21. alpaca/common/types.py +7 -0
  22. alpaca/common/utils.py +89 -0
  23. alpaca/data/__init__.py +5 -0
  24. alpaca/data/enums.py +184 -0
  25. alpaca/data/historical/__init__.py +13 -0
  26. alpaca/data/historical/corporate_actions.py +76 -0
  27. alpaca/data/historical/crypto.py +299 -0
  28. alpaca/data/historical/news.py +63 -0
  29. alpaca/data/historical/option.py +230 -0
  30. alpaca/data/historical/screener.py +72 -0
  31. alpaca/data/historical/stock.py +226 -0
  32. alpaca/data/historical/utils.py +30 -0
  33. alpaca/data/live/__init__.py +11 -0
  34. alpaca/data/live/crypto.py +168 -0
  35. alpaca/data/live/news.py +62 -0
  36. alpaca/data/live/option.py +88 -0
  37. alpaca/data/live/stock.py +199 -0
  38. alpaca/data/live/websocket.py +390 -0
  39. alpaca/data/mappings.py +84 -0
  40. alpaca/data/models/__init__.py +7 -0
  41. alpaca/data/models/bars.py +83 -0
  42. alpaca/data/models/base.py +45 -0
  43. alpaca/data/models/corporate_actions.py +309 -0
  44. alpaca/data/models/news.py +90 -0
  45. alpaca/data/models/orderbooks.py +59 -0
  46. alpaca/data/models/quotes.py +78 -0
  47. alpaca/data/models/screener.py +68 -0
  48. alpaca/data/models/snapshots.py +132 -0
  49. alpaca/data/models/trades.py +204 -0
  50. alpaca/data/requests.py +580 -0
  51. alpaca/data/timeframe.py +148 -0
  52. alpaca/py.typed +0 -0
  53. alpaca/trading/__init__.py +5 -0
  54. alpaca/trading/client.py +784 -0
  55. alpaca/trading/enums.py +412 -0
  56. alpaca/trading/models.py +697 -0
  57. alpaca/trading/requests.py +604 -0
  58. alpaca/trading/stream.py +225 -0
  59. alpaca_py_nopandas-0.1.0.dist-info/LICENSE +201 -0
  60. alpaca_py_nopandas-0.1.0.dist-info/METADATA +299 -0
  61. alpaca_py_nopandas-0.1.0.dist-info/RECORD +62 -0
  62. alpaca_py_nopandas-0.1.0.dist-info/WHEEL +4 -0
@@ -0,0 +1,159 @@
1
+ from datetime import date as datetime_date
2
+ from datetime import datetime
3
+ from ipaddress import IPv4Address, IPv6Address
4
+ from typing import Any, Optional, Union
5
+ from uuid import UUID
6
+
7
+ from pydantic import model_validator
8
+
9
+ from alpaca.broker.enums import DocumentType, TradeDocumentSubType, TradeDocumentType
10
+ from alpaca.common.models import ModelWithID
11
+ from alpaca.common.models import ValidateBaseModel as BaseModel
12
+
13
+ IPAddress = Union[IPv4Address, IPv6Address]
14
+
15
+
16
+ class AccountDocument(BaseModel):
17
+ """
18
+ User documents provided within Account Model.
19
+
20
+ This model is different from the TradeDocument model in that this model represents documents having to do with a
21
+ brokerage Account.
22
+
23
+ see https://alpaca.markets/docs/broker/api-references/accounts/accounts/#the-account-model
24
+
25
+ Attributes:
26
+ id (UUID): ID of the Document
27
+ document_type (DocumentType): The type of document uploaded
28
+ document_sub_type (Optional[str]): The specific type of document, e.g. passport
29
+ name (Optional(str)): Name of the document if present
30
+ content (str): Base64 string representing the document
31
+ mime_type (str): The format of content encoded by the string
32
+ """
33
+
34
+ id: Optional[UUID]
35
+ document_type: Optional[DocumentType]
36
+ document_sub_type: Optional[str] = None
37
+ content: Optional[str] = None
38
+ mime_type: Optional[str] = None
39
+
40
+ def __init__(self, **data: Any) -> None:
41
+ # validate the incoming id field for uuid
42
+ _id = data.get("id", None)
43
+ if isinstance(_id, str):
44
+ data["id"] = UUID(_id)
45
+
46
+ super().__init__(**data)
47
+
48
+
49
+ class TradeDocument(ModelWithID):
50
+ """
51
+ Similar to the AccountDocument model but this represents documents having to do with a TradeAccount not a regular
52
+ Account.
53
+
54
+ IE: Account Monthly Statements or Trade Confirmations.
55
+
56
+ Attributes:
57
+ id (UUID): Unique id of the TradeDocument
58
+ name (str): Name of the document
59
+ type (TradeDocumentType): The kind of TradeDocument this is
60
+ sub_type (Optional[TradeDocumentSubType]): The subtype of the document. The API returns "" in the case of this
61
+ not being specified, however we transform this case into None for convenience.
62
+ date (date): Date on when this TradeDocument was generated
63
+ """
64
+
65
+ name: str
66
+ type: TradeDocumentType
67
+ sub_type: Optional[TradeDocumentSubType] = None
68
+ date: datetime_date
69
+
70
+ def __init__(self, **data: Any) -> None:
71
+ if "id" in data and isinstance(data["id"], str):
72
+ data["id"] = UUID(data["id"])
73
+
74
+ if "sub_type" in data and data["sub_type"] == "":
75
+ data["sub_type"] = None
76
+
77
+ super().__init__(**data)
78
+
79
+
80
+ class W8BenDocument(BaseModel):
81
+ """
82
+ Represents the information normally contained in a W8BEN document as fields for convenience if you don't
83
+ want to upload a file.
84
+
85
+ Please see https://docs.alpaca.markets/docs/international-accounts
86
+ for more information.
87
+
88
+ TODO: None of the docs or code explain what any of these fields mean. Guessing based on name alone for
89
+ all of them; but we really need the docs updated.
90
+
91
+ Attributes:
92
+ additional_conditions (Optional[str]): Any additional conditions to specify
93
+ country_citizen (str): The Country that the applicant is a citizen of
94
+ date (date): date signed
95
+ date_of_birth (date): DOB of applicant
96
+ foreign_tax_id (Optional[str]): Applicant's tax id in their home country
97
+ ftin_not_required (Optional[bool]): Required if foreign_tax_id and tax_id_ssn are empty.
98
+ full_name (str): Full name of applicant
99
+ income_type (Optional[str]): income type of applicant
100
+ ip_address (IPAddress): ip address of applicant when signed
101
+ mailing_address_city_state (Optional[str]): mailing city/state of applicant
102
+ mailing_address_country (Optional[str]): mailing country for applicant
103
+ mailing_address_street (Optional[str]): mailing street address for applicant
104
+ paragraph_number (Optional[str]): TODO: get documentation for this field
105
+ percent_rate_withholding (Optional[str]): TODO: get documentation for this field
106
+ permanent_address_city_state (str): permanent city/state of applicant
107
+ permanent_address_country (str): permanent country of residence of applicant
108
+ permanent_address_street (str): permanent street address of applicant
109
+ reference_number (Optional[str]): TODO: Get documentation for this field
110
+ residency (Optional[str]): Country of residency of applicant
111
+ TODO: get real documentation for this field. current is just guess based on example
112
+ revision (str): Revision of the W8BEN form
113
+ signer_full_name (str): Full name of signing user
114
+ tax_id_ssn (Optional[str]): TaxID/SSN of applicant
115
+ timestamp (datetime): timestamp when form data was gathered
116
+ """
117
+
118
+ country_citizen: str
119
+ date: datetime_date
120
+ date_of_birth: datetime_date
121
+ full_name: str
122
+ ip_address: IPAddress
123
+ permanent_address_city_state: str
124
+ permanent_address_country: str
125
+ permanent_address_street: str
126
+ revision: str
127
+ signer_full_name: str
128
+ timestamp: datetime
129
+
130
+ # optional fields
131
+ additional_conditions: Optional[str] = None
132
+ foreign_tax_id: Optional[str] = None
133
+ ftin_not_required: Optional[bool] = None
134
+ income_type: Optional[str] = None
135
+ mailing_address_city_state: Optional[str] = None
136
+ mailing_address_country: Optional[str] = None
137
+ mailing_address_street: Optional[str] = None
138
+ paragraph_number: Optional[str] = None
139
+ percent_rate_withholding: Optional[str] = None
140
+ reference_number: Optional[str] = None
141
+ residency: Optional[str] = None
142
+ tax_id_ssn: Optional[str] = None
143
+
144
+ @model_validator(mode="before")
145
+ def root_validator(cls, values: dict) -> dict:
146
+ foreign_tax_set = (
147
+ "foreign_tax_id" in values and values["foreign_tax_id"] is not None
148
+ )
149
+ tax_id_set = "tax_id_ssn" in values and values["tax_id_ssn"] is not None
150
+ ftin_set = (
151
+ "ftin_not_required" in values and values["ftin_not_required"] is not None
152
+ )
153
+
154
+ if not foreign_tax_set and not tax_id_set and not ftin_set:
155
+ raise ValueError(
156
+ "ftin_not_required must be set if foreign_tax_id and tax_id_ssn are not"
157
+ )
158
+
159
+ return values
@@ -0,0 +1,114 @@
1
+ from datetime import datetime
2
+ from typing import Optional
3
+ from uuid import UUID
4
+
5
+ from alpaca.broker.enums import (
6
+ ACHRelationshipStatus,
7
+ BankAccountType,
8
+ BankStatus,
9
+ IdentifierType,
10
+ TransferType,
11
+ TransferStatus,
12
+ TransferDirection,
13
+ FeePaymentMethod,
14
+ )
15
+ from alpaca.common.models import ModelWithID
16
+
17
+
18
+ class ACHRelationship(ModelWithID):
19
+ """
20
+ Attributes:
21
+ id (UUID): ID of Relationship
22
+ account_id (UUID): ID of the Account this ACHRelationship is tied to
23
+ created_at (datetime): Date and time this relationship was created
24
+ updated_at (datetime): Date and time of when this relationship was last updated
25
+ status (ACHRelationshipStatus): Current status of the relationship
26
+ account_owner_name (str): Full name of the account owner
27
+ bank_account_type (BankAccountType): The kind of bank account this relationship points to
28
+ bank_account_number (str): The number of bank account that the relationship points to
29
+ bank_routing_number (str): Routing number for the bank account
30
+ nickname (str): User provided name for account
31
+ processor_token (Optional[str]): If you are using Plaid, then this is a Plaid processor token.
32
+ """
33
+
34
+ account_id: UUID
35
+ created_at: datetime
36
+ updated_at: datetime
37
+ status: ACHRelationshipStatus
38
+ account_owner_name: str
39
+ bank_account_type: BankAccountType
40
+ bank_account_number: str
41
+ bank_routing_number: str
42
+ nickname: Optional[str] = None
43
+ processor_token: Optional[str] = None
44
+
45
+
46
+ class Bank(ModelWithID):
47
+ """
48
+ Attributes:
49
+ id (UUID): ID of Bank.
50
+ account_id (UUID): ID of the Account this Bank is tied to.
51
+ created_at (datetime): Date and time this Bank was created.
52
+ updated_at (datetime): Date and time of when this Bank was last updated.
53
+ name (str): Name of the bank.
54
+ status (BankStatus): The status of the bank connection.
55
+ country (str): Country where bank account is located.
56
+ state_province (str): State/Province where bank is located.
57
+ postal_code (str): Postal code where bank is located.
58
+ city (str): City where bank is located.
59
+ street_address (str): Street address where bank is located.
60
+ account_number (str): The bank account number.
61
+ bank_code (str): The bank account code.
62
+ bank_code_type (IdentifierType): The bank identifier.
63
+ """
64
+
65
+ account_id: UUID
66
+ created_at: datetime
67
+ updated_at: datetime
68
+ name: str
69
+ status: BankStatus
70
+ country: str
71
+ state_province: str
72
+ postal_code: str
73
+ city: str
74
+ street_address: str
75
+ account_number: str
76
+ bank_code: str
77
+ bank_code_type: IdentifierType
78
+
79
+
80
+ class Transfer(ModelWithID):
81
+ """
82
+ Attributes:
83
+ id (UUID): ID of Transfer.
84
+ account_id (UUID): ID of the Account this Transfer is tied to.
85
+ created_at (datetime): Date and time when this Transfer was created.
86
+ updated_at (datetime): Date and time of when this Transfer was last updated.
87
+ expires_at (datetime): Date and time of when this Transfer will expire.
88
+ relationship_id (UUID): ID of the funding relationship used to make the transfer.
89
+ amount (str): The amount the recipient will receive after any applicable fees are deducted.
90
+ type (TransferType): The type of transfer.
91
+ status (TransferStatus): The status of the transfer.
92
+ direction (TransferDirection): The direction of the transfer.
93
+ reason (Optional[str]): Reasoning associated with the current status.
94
+ requested_amount (Optional[str]): Amount entered upon creation of a transfer entity.
95
+ fee (Optional[str]): Dollar amount of any applicable fees.
96
+ fee_payment_method (Optional[FeePaymentMethod]): Denotes how any applicable fees will be paid.
97
+ additional_information (Optional[str]): Additional information provided with wire transfers.
98
+ """
99
+
100
+ account_id: UUID
101
+ created_at: datetime
102
+ updated_at: Optional[datetime] = None
103
+ expires_at: Optional[datetime] = None
104
+ relationship_id: Optional[UUID] = None
105
+ bank_id: Optional[UUID] = None
106
+ amount: str
107
+ type: TransferType
108
+ status: TransferStatus
109
+ direction: TransferDirection
110
+ reason: Optional[str] = None
111
+ requested_amount: Optional[str] = None
112
+ fee: Optional[str] = None
113
+ fee_payment_method: Optional[FeePaymentMethod] = None
114
+ additional_information: Optional[str] = None
@@ -0,0 +1,71 @@
1
+ from datetime import date
2
+ from typing import Optional
3
+ from uuid import UUID
4
+
5
+ from alpaca.broker.enums import JournalEntryType, JournalStatus
6
+ from alpaca.common.models import ModelWithID
7
+ from alpaca.common.enums import SupportedCurrencies
8
+
9
+
10
+ class Journal(ModelWithID):
11
+ """
12
+ Represents a transfer of cash or securities from one account to another.
13
+
14
+ There are two types of journals Cash Journals and Security Journals.
15
+
16
+ **Travel Rule**
17
+ In an effort to fight the criminal financial transactions, FinCEN enacted the
18
+ Travel Rule that applies to fund transfers of more than $3,000.
19
+ When you use Journal API to bundle a bulk of transfers for the end-users, you will need to tell about
20
+ the breakdown and each transmitter information using the optional fields of the POST request.
21
+
22
+ Learn more about journals here: https://alpaca.markets/docs/api-references/broker-api/journals/
23
+
24
+ Attributes:
25
+ id (UUID): The journal ID
26
+ to_account (UUID): The account ID that received the journal.
27
+ from_account (UUID): The account ID that initiates the journal.
28
+ entry_type (JournalEntryType): Whether the journal is a cash or security journal.
29
+ status (JournalStatus): The lifecycle status of the journal.
30
+ symbol (Optional[str]): For security journals, the symbol identifier of the security being journaled.
31
+ qty (Optional[float]): For security journals, the quantity of the security being journaled.
32
+ price (Optional[float]): For security journals, the price at which the security is being journaled at.
33
+ net_amount (Optional[float]): For cash journals, the total cash amount journaled
34
+ description (Optional[str]): Journal description. It can include fixtures for sandbox API.
35
+ settle_date (Optional[date]):
36
+ system_date (Optional[date]):
37
+ transmitter_name (Optional[str]): For cash journals, travel rule related name info.
38
+ transmitter_account_number (Optional[str]): For cash journals, travel rule account number info.
39
+ transmitter_address (Optional[str]): For cash journals, travel rule related address info.
40
+ transmitter_financial_institution (Optional[str]): For cash journals, travel rule related institution info.
41
+ transmitter_timestamp (Optional[str]): For cash journals, travel rule related timestamp info.
42
+ """
43
+
44
+ to_account: UUID
45
+ from_account: UUID
46
+ entry_type: JournalEntryType
47
+ status: JournalStatus
48
+ net_amount: Optional[float] = None
49
+ symbol: Optional[str] = None
50
+ qty: Optional[float] = None
51
+ price: Optional[float] = None
52
+ description: Optional[str] = None
53
+ settle_date: Optional[date] = None
54
+ system_date: Optional[date] = None
55
+ transmitter_name: Optional[str] = None
56
+ transmitter_account_number: Optional[str] = None
57
+ transmitter_address: Optional[str] = None
58
+ transmitter_financial_institution: Optional[str] = None
59
+ transmitter_timestamp: Optional[str] = None
60
+ currency: Optional[SupportedCurrencies] = None
61
+
62
+
63
+ class BatchJournalResponse(Journal):
64
+ """
65
+ Represents a journal response from a batch journal request.
66
+
67
+ Attributes:
68
+ error_message (Optional[str]): An message that contains error details for failed journals.
69
+ """
70
+
71
+ error_message: Optional[str] = None
@@ -0,0 +1,80 @@
1
+ from datetime import datetime
2
+ from typing import List, Optional
3
+ from uuid import UUID
4
+
5
+ from alpaca.broker.enums import PortfolioStatus, RunInitiatedFrom, RunStatus, RunType
6
+ from alpaca.broker.models import Order
7
+ from alpaca.broker.requests import RebalancingConditions, Weight
8
+ from alpaca.common.models import ValidateBaseModel as BaseModel
9
+
10
+
11
+ class Portfolio(BaseModel):
12
+ """
13
+ Portfolio response model.
14
+
15
+ https://docs.alpaca.markets/reference/get-v1-rebalancing-portfolios
16
+ """
17
+
18
+ id: UUID
19
+ name: str
20
+ description: str
21
+ status: PortfolioStatus
22
+ cooldown_days: int
23
+ created_at: datetime
24
+ updated_at: datetime
25
+ weights: List[Weight]
26
+ rebalance_conditions: Optional[List[RebalancingConditions]] = None
27
+
28
+
29
+ class Subscription(BaseModel):
30
+ """
31
+ Subscription response model.
32
+
33
+ https://docs.alpaca.markets/reference/get-v1-rebalancing-subscriptions-1
34
+ """
35
+
36
+ id: UUID
37
+ account_id: UUID
38
+ portfolio_id: UUID
39
+ created_at: datetime
40
+ last_rebalanced_at: Optional[datetime] = None
41
+
42
+
43
+ class SkippedOrder(BaseModel):
44
+ """
45
+ Skipped order response model.
46
+
47
+ https://docs.alpaca.markets/reference/get-v1-rebalancing-runs-run_id-1
48
+ """
49
+
50
+ symbol: str
51
+ side: Optional[str] = None
52
+ notional: Optional[str] = None
53
+ currency: Optional[str] = None
54
+ reason: str
55
+ reason_details: str
56
+
57
+
58
+ class RebalancingRun(BaseModel):
59
+ """
60
+ Rebalancing run response model.
61
+
62
+ https://docs.alpaca.markets/reference/get-v1-rebalancing-runs
63
+ """
64
+
65
+ id: UUID
66
+ account_id: UUID
67
+ type: RunType
68
+ amount: Optional[str] = None
69
+ portfolio_id: UUID
70
+ weights: List[Weight]
71
+ initiated_from: Optional[RunInitiatedFrom] = None
72
+ created_at: datetime
73
+ updated_at: datetime
74
+ completed_at: Optional[datetime] = None
75
+ canceled_at: Optional[datetime] = None
76
+ status: RunStatus
77
+ reason: Optional[str] = None
78
+ orders: Optional[List[Order]] = None
79
+ failed_orders: Optional[List[Order]] = None
80
+ skipped_orders: Optional[List[SkippedOrder]] = None
@@ -0,0 +1,13 @@
1
+ from typing import Optional
2
+ from alpaca.trading.models import Order as BaseOrder
3
+
4
+
5
+ class Order(BaseOrder):
6
+ """
7
+ See base alpaca.trading.models.Order model for full list of base attributes.
8
+
9
+ Attributes:
10
+ commission (float): The dollar value commission you want to charge the end user.
11
+ """
12
+
13
+ commission: Optional[float] = None