alpaca-sdk 0.0.0

Unofficial Rust SDK for the Alpaca trading, market data, and broker APIs
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
//! Enums for the trading API, from `alpaca/trading/enums.py`.
//!
//! Generated by `scripts/gen_enums.py` from `alpaca/trading/enums.py`
//! at alpaca-py revision `cc4cb3b`. Do not edit by hand — hand-written
//! `impl` blocks belong in the sibling `enums_ext.rs`.

use crate::types::wire::wire_enum;
wire_enum! {
    /// Represents what kind of Activity an instance of `TradeActivity` or `NonTradeActivity` is.
    ///
    /// Please see <https://alpaca.markets/docs/api-references/broker-api/accounts/account-activities/#enumactivitytype>
    /// for descriptions of each of the types
    pub enum ActivityType {
        /// `FILL`
        Fill => "FILL",
        /// `ACATC`
        Acatc => "ACATC",
        /// `ACATS`
        Acats => "ACATS",
        /// `CFEE`
        Cfee => "CFEE",
        /// `CIL`
        Cil => "CIL",
        /// `CSD`
        Csd => "CSD",
        /// `CSW`
        Csw => "CSW",
        /// `DIV`
        Div => "DIV",
        /// `DIVCGL`
        Divcgl => "DIVCGL",
        /// `DIVCGS`
        Divcgs => "DIVCGS",
        /// `DIVNRA`
        Divnra => "DIVNRA",
        /// `DIVROC`
        Divroc => "DIVROC",
        /// `DIVTXEX`
        Divtxex => "DIVTXEX",
        /// `DIVWH`
        Divwh => "DIVWH",
        /// `EXTRD`
        Extrd => "EXTRD",
        /// `FEE`
        Fee => "FEE",
        /// `FXTRD`
        Fxtrd => "FXTRD",
        /// `INT`
        Int => "INT",
        /// `INTPNL`
        Intpnl => "INTPNL",
        /// `JNLC`
        Jnlc => "JNLC",
        /// `JNLS`
        Jnls => "JNLS",
        /// `MA`
        Ma => "MA",
        /// `MEM`
        Mem => "MEM",
        /// `NC`
        Nc => "NC",
        /// `OCT`
        Oct => "OCT",
        /// `OPASN`
        Opasn => "OPASN",
        /// `OPCSH`
        Opcsh => "OPCSH",
        /// `OPEXC`
        Opexc => "OPEXC",
        /// `OPEXP`
        Opexp => "OPEXP",
        /// `OPTRD`
        Optrd => "OPTRD",
        /// `PTC`
        Ptc => "PTC",
        /// `REORG`
        Reorg => "REORG",
        /// `SPIN`
        Spin => "SPIN",
        /// `SPLIT`
        Split => "SPLIT",
        /// `SWP`
        Swp => "SWP",
        /// `VOF`
        Vof => "VOF",
        /// `WH`
        Wh => "WH",
    }
}

wire_enum! {
    /// Represents the type of `TradeActivity`.
    ///
    /// Please see <https://alpaca.markets/docs/api-references/broker-api/accounts/account-activities/#attributes>
    pub enum TradeActivityType {
        /// `partial_fill`
        PartialFill => "partial_fill",
        /// `fill`
        Fill => "fill",
    }
}

wire_enum! {
    /// Represents the status of a `NonTradeActivity`.
    ///
    /// Please see <https://alpaca.markets/docs/api-references/broker-api/accounts/account-activities/#enumaccountactivity>
    /// for more info.
    pub enum NonTradeActivityStatus {
        /// `executed`
        Executed => "executed",
        /// `correct`
        Correct => "correct",
        /// `canceled`
        Canceled => "canceled",
    }
}

wire_enum! {
    /// Represents what class of order this is.
    ///
    /// The order classes supported by Alpaca vary based on the order's security type.
    /// The following provides a comprehensive breakdown of the supported order classes for each category:
    /// - Equity trading: simple (or ""), oco, oto, bracket.
    /// - Options trading: simple (or ""), mleg (required for multi-leg complex options strategies).
    /// - Crypto trading: simple (or "").
    pub enum OrderClass {
        /// `simple`
        Simple => "simple",
        /// `mleg`
        Mleg => "mleg",
        /// `bracket`
        Bracket => "bracket",
        /// `oco`
        Oco => "oco",
        /// `oto`
        Oto => "oto",
    }
}

wire_enum! {
    /// Represents what type of order this is.
    ///
    /// The order types supported by Alpaca vary based on the order's security type.
    /// The following provides a comprehensive breakdown of the supported order types for each category:
    /// - Equity trading: market, limit, stop, `stop_limit`, `trailing_stop`.
    /// - Options trading: market, limit, stop, `stop_limit`.
    /// - Crypto trading: market, limit, `stop_limit`.
    pub enum OrderType {
        /// `market`
        Market => "market",
        /// `limit`
        Limit => "limit",
        /// `stop`
        Stop => "stop",
        /// `stop_limit`
        StopLimit => "stop_limit",
        /// `trailing_stop`
        TrailingStop => "trailing_stop",
    }
}

wire_enum! {
    /// Represents what side this order was executed on.
    pub enum OrderSide {
        /// `buy`
        Buy => "buy",
        /// `sell`
        Sell => "sell",
    }
}

wire_enum! {
    /// Represents the various states an Order can be in.
    ///
    /// please see <https://alpaca.markets/docs/api-references/broker-api/trading/orders/#order-status> for more info
    pub enum OrderStatus {
        /// `new`
        New => "new",
        /// `partially_filled`
        PartiallyFilled => "partially_filled",
        /// `filled`
        Filled => "filled",
        /// `done_for_day`
        DoneForDay => "done_for_day",
        /// `canceled`
        Canceled => "canceled",
        /// `expired`
        Expired => "expired",
        /// `replaced`
        Replaced => "replaced",
        /// `pending_cancel`
        PendingCancel => "pending_cancel",
        /// `pending_replace`
        PendingReplace => "pending_replace",
        /// `pending_review`
        PendingReview => "pending_review",
        /// `accepted`
        Accepted => "accepted",
        /// `pending_new`
        PendingNew => "pending_new",
        /// `accepted_for_bidding`
        AcceptedForBidding => "accepted_for_bidding",
        /// `stopped`
        Stopped => "stopped",
        /// `rejected`
        Rejected => "rejected",
        /// `suspended`
        Suspended => "suspended",
        /// `calculated`
        Calculated => "calculated",
        /// `held`
        Held => "held",
    }
}

wire_enum! {
    /// This represents the category to which the asset belongs to.
    /// It serves to identify the nature of the financial instrument, with options
    /// including "`us_equity`" for U.S. equities, "`us_option`" for U.S. options,
    /// and "crypto" for cryptocurrencies.
    pub enum AssetClass {
        /// `us_equity`
        UsEquity => "us_equity",
        /// `us_option`
        UsOption => "us_option",
        /// `crypto`
        Crypto => "crypto",
        /// `crypto_perp`
        CryptoPerp => "crypto_perp",
    }
}

wire_enum! {
    /// Represents the various states for an Asset's lifecycle
    pub enum AssetStatus {
        /// `active`
        Active => "active",
        /// `inactive`
        Inactive => "inactive",
    }
}

wire_enum! {
    /// Represents the current exchanges Alpaca supports.
    pub enum AssetExchange {
        /// `AMEX`
        Amex => "AMEX",
        /// `ARCA`
        Arca => "ARCA",
        /// `ASCX`
        Ascx => "ASCX",
        /// `BATS`
        Bats => "BATS",
        /// `NYSE`
        Nyse => "NYSE",
        /// `NASDAQ`
        Nasdaq => "NASDAQ",
        /// `NYSEARCA`
        Nysearca => "NYSEARCA",
        /// `FTXU`
        Ftxu => "FTXU",
        /// `CBSE`
        Cbse => "CBSE",
        /// `GNSS`
        Gnss => "GNSS",
        /// `ERSX`
        Ersx => "ERSX",
        /// `OTC`
        Otc => "OTC",
        /// `CRYPTO`
        Crypto => "CRYPTO",
        /// The empty value.
        Empty => "",
    }
}

wire_enum! {
    /// Represents what side this position is.
    pub enum PositionSide {
        /// `short`
        Short => "short",
        /// `long`
        Long => "long",
    }
}

wire_enum! {
    /// Represents the various time in force options for an Order.
    ///
    /// The Time-In-Force values supported by Alpaca vary based on the order's security type. Here is a breakdown of the supported `TIFs` for each specific security type:
    /// - Equity trading: day, gtc, opg, cls, ioc, fok.
    /// - Options trading: day.
    /// - Crypto trading: gtc, ioc.
    /// Below are the descriptions of each TIF:
    /// - day: A day order is eligible for execution only on the day it is live. By default, the order is only valid during Regular Trading Hours (9:30am - 4:00pm ET). If unfilled after the closing auction, it is automatically canceled. If submitted after the close, it is queued and submitted the following trading day. However, if marked as eligible for extended hours, the order can also execute during supported extended hours.
    /// - gtc: The order is good until canceled. Non-marketable GTC limit orders are subject to price adjustments to offset corporate actions affecting the issue. We do not currently support Do Not Reduce(DNR) orders to opt out of such price adjustments.
    /// - opg: Use this TIF with a market/limit order type to submit “market on open” (MOO) and “limit on open” (LOO) orders. This order is eligible to execute only in the market opening auction. Any unfilled orders after the open will be cancelled. OPG orders submitted after 9:28am but before 7:00pm ET will be rejected. OPG orders submitted after 7:00pm will be queued and routed to the following day’s opening auction. On open/on close orders are routed to the primary exchange. Such orders do not necessarily execute exactly at 9:30am / 4:00pm ET but execute per the exchange’s auction rules.
    /// - cls: Use this TIF with a market/limit order type to submit “market on close” (MOC) and “limit on close” (LOC) orders. This order is eligible to execute only in the market closing auction. Any unfilled orders after the close will be cancelled. CLS orders submitted after 3:50pm but before 7:00pm ET will be rejected. CLS orders submitted after 7:00pm will be queued and routed to the following day’s closing auction. Only available with API v2.
    /// - ioc: An Immediate Or Cancel (IOC) order requires all or part of the order to be executed immediately. Any unfilled portion of the order is canceled. Only available with API v2. Most market makers who receive IOC orders will attempt to fill the order on a principal basis only, and cancel any unfilled balance. On occasion, this can result in the entire order being cancelled if the market maker does not have any existing inventory of the security in question.
    /// - fok: A Fill or Kill (FOK) order is only executed if the entire order quantity can be filled, otherwise the order is canceled. Only available with API v2.
    pub enum TimeInForce {
        /// `day`
        Day => "day",
        /// `gtc`
        Gtc => "gtc",
        /// `opg`
        Opg => "opg",
        /// `cls`
        Cls => "cls",
        /// `ioc`
        Ioc => "ioc",
        /// `fok`
        Fok => "fok",
    }
}

wire_enum! {
    /// The general types of corporate action events.
    ///
    /// Learn more here: <https://alpaca.markets/docs/api-references/trading-api/corporate-actions-announcements/>
    pub enum CorporateActionType {
        /// `dividend`
        Dividend => "dividend",
        /// `merger`
        Merger => "merger",
        /// `spinoff`
        Spinoff => "spinoff",
        /// `split`
        Split => "split",
    }
}

wire_enum! {
    /// The specific types of corporate actions. Each subtype is related to `CorporateActionType`.
    ///
    /// Learn more here: <https://alpaca.markets/docs/api-references/trading-api/corporate-actions-announcements/>
    pub enum CorporateActionSubType {
        /// `cash`
        Cash => "cash",
        /// `stock`
        Stock => "stock",
        /// `merger_update`
        MergerUpdate => "merger_update",
        /// `merger_completion`
        MergerCompletion => "merger_completion",
        /// `spinoff`
        Spinoff => "spinoff",
        /// `stock_split`
        StockSplit => "stock_split",
        /// `unit_split`
        UnitSplit => "unit_split",
        /// `reverse_split`
        ReverseSplit => "reverse_split",
        /// `recapitalization`
        Recapitalization => "recapitalization",
    }
}

wire_enum! {
    /// The various statuses each brokerage account can take during its lifetime
    ///
    /// see <https://alpaca.markets/docs/broker/api-references/accounts/accounts/#account-status>
    pub enum AccountStatus {
        /// `ACCOUNT_CLOSED`
        AccountClosed => "ACCOUNT_CLOSED",
        /// `ACCOUNT_UPDATED`
        AccountUpdated => "ACCOUNT_UPDATED",
        /// `ACTION_REQUIRED`
        ActionRequired => "ACTION_REQUIRED",
        /// `ACTIVE`
        Active => "ACTIVE",
        /// `AML_REVIEW`
        AmlReview => "AML_REVIEW",
        /// `APPROVAL_PENDING`
        ApprovalPending => "APPROVAL_PENDING",
        /// `APPROVED`
        Approved => "APPROVED",
        /// `DISABLED`
        Disabled => "DISABLED",
        /// `DISABLE_PENDING`
        DisablePending => "DISABLE_PENDING",
        /// `EDITED`
        Edited => "EDITED",
        /// `INACTIVE`
        Inactive => "INACTIVE",
        /// `KYC_SUBMITTED`
        KycSubmitted => "KYC_SUBMITTED",
        /// `LIMITED`
        Limited => "LIMITED",
        /// `ONBOARDING`
        Onboarding => "ONBOARDING",
        /// `PAPER_ONLY`
        PaperOnly => "PAPER_ONLY",
        /// `REAPPROVAL_PENDING`
        ReapprovalPending => "REAPPROVAL_PENDING",
        /// `REJECTED`
        Rejected => "REJECTED",
        /// `RESUBMITTED`
        Resubmitted => "RESUBMITTED",
        /// `SIGNED_UP`
        SignedUp => "SIGNED_UP",
        /// `SUBMISSION_FAILED`
        SubmissionFailed => "SUBMISSION_FAILED",
        /// `SUBMITTED`
        Submitted => "SUBMITTED",
    }
}

wire_enum! {
    /// The `CorporateActionDateType` values accepted by the API.
    pub enum CorporateActionDateType {
        /// `declaration_date`
        DeclarationDate => "declaration_date",
        /// `ex_date`
        ExDate => "ex_date",
        /// `record_date`
        RecordDate => "record_date",
        /// `payable_date`
        PayableDate => "payable_date",
    }
}

wire_enum! {
    /// The `TradeEvent` values accepted by the API.
    pub enum TradeEvent {
        /// `accepted`
        Accepted => "accepted",
        /// `canceled`
        Canceled => "canceled",
        /// `expired`
        Expired => "expired",
        /// `fill`
        Fill => "fill",
        /// `new`
        New => "new",
        /// `partial_fill`
        PartialFill => "partial_fill",
        /// `pending_cancel`
        PendingCancel => "pending_cancel",
        /// `pending_new`
        PendingNew => "pending_new",
        /// `pending_replace`
        PendingReplace => "pending_replace",
        /// `rejected`
        Rejected => "rejected",
        /// `replaced`
        Replaced => "replaced",
        /// `restated`
        Restated => "restated",
    }
}

wire_enum! {
    /// The `QueryOrderStatus` values accepted by the API.
    pub enum QueryOrderStatus {
        /// `open`
        Open => "open",
        /// `closed`
        Closed => "closed",
        /// `all`
        All => "all",
    }
}

wire_enum! {
    /// Specifies when to run a DTBP check for an account.
    ///
    /// NOTE: These values are currently the same as `PDTCheck` however they are not guaranteed to be in sync the future
    ///
    /// please see <https://alpaca.markets/docs/api-references/broker-api/trading/trading-configurations/#attributes>
    /// for more info.
    pub enum DTBPCheck {
        /// `both`
        Both => "both",
        /// `entry`
        Entry => "entry",
        /// `exit`
        Exit => "exit",
    }
}

wire_enum! {
    /// Specifies when to run a PDT check for an account.
    ///
    /// NOTE: These values are currently the same as `DTBPCheck` however they are not guaranteed to be in sync the future
    ///
    /// please see <https://alpaca.markets/docs/api-references/broker-api/trading/trading-configurations/#attributes>
    /// for more info.
    pub enum PDTCheck {
        /// `both`
        Both => "both",
        /// `entry`
        Entry => "entry",
        /// `exit`
        Exit => "exit",
    }
}

wire_enum! {
    /// Used for controlling when an Account will receive a trade confirmation email.
    ///
    /// please see <https://docs.alpaca.markets/reference/getaccountconfig>
    /// for more info.
    pub enum TradeConfirmationEmail {
        /// `all`
        All => "all",
        /// `none`
        None => "none",
    }
}

wire_enum! {
    /// Represents the exercise style of options
    pub enum ExerciseStyle {
        /// `american`
        American => "american",
        /// `european`
        European => "european",
    }
}

wire_enum! {
    /// Represents the category of an Activity
    pub enum ActivityCategory {
        /// `trade_activity`
        TradeActivity => "trade_activity",
        /// `non_trade_activity`
        NonTradeActivity => "non_trade_activity",
    }
}

wire_enum! {
    /// Represents what side this order was executed on.
    pub enum PositionIntent {
        /// `buy_to_open`
        BuyToOpen => "buy_to_open",
        /// `buy_to_close`
        BuyToClose => "buy_to_close",
        /// `sell_to_open`
        SellToOpen => "sell_to_open",
        /// `sell_to_close`
        SellToClose => "sell_to_close",
    }
}