Skip to content

Commit

Permalink
create leg collection
Browse files Browse the repository at this point in the history
  • Loading branch information
rcholic committed Jun 8, 2024
1 parent d17ef4b commit 1d7a5b8
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 6 deletions.
1 change: 1 addition & 0 deletions cschwabpy/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class OptionContractType(str, Enum):
CALL = "CALL"
PUT = "PUT"
ALL = "ALL"
UNKNOWN = "UNKNOWN"


class OptionContractStrategy(str, Enum):
Expand Down
86 changes: 80 additions & 6 deletions cschwabpy/models/trade_models.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
from cschwabpy.models import JSONSerializableBaseModel
from cschwabpy.models import JSONSerializableBaseModel, OptionContractType
from typing import Optional, List, Any
from pydantic import Field
from enum import Enum
from enum import Enum
from enum import Enum
from enum import Enum
from enum import Enum
from enum import Enum


class AccountType(str, Enum):
Expand Down Expand Up @@ -114,6 +110,44 @@ class Destination(Enum):
AUTO = "AUTO"


# class OrderLegType(str, Enum):
class AssetType(str, Enum): # same as OrderLegType
EQUITY = "EQUITY"
OPTION = "OPTION"
INDEX = "INDEX"
MUTUAL_FUND = "MUTUAL_FUND"
CASH_EQUIVALENT = "CASH_EQUIVALENT"
FIXED_INCOME = "FIXED_INCOME"
CURRENCY = "CURRENCY"
COLLECTIVE_INVESTMENT = "COLLECTIVE_INVESTMENT"


class OptionType(str, Enum):
VANILLA = "VANILLA"
BINARY = "BINARY"
BARRIER = "BARRIER"
UNKNOWN = "UNKNOWN"


class OrderLegInstruction(str, Enum):
BUY = "BUY"
SELL = "SELL"
BUY_TO_COVER = "BUY_TO_COVER"
SELL_SHORT = "SELL_SHORT"
BUY_TO_OPEN = "BUY_TO_OPEN"
BUY_TO_CLOSE = "BUY_TO_CLOSE"
SELL_TO_OPEN = "SELL_TO_OPEN"
SELL_TO_CLOSE = "SELL_TO_CLOSE"
EXCHANGE = "EXCHANGE"
SELL_SHORT_EXEMPT = "SELL_SHORT_EXEMPT"


class PositionEffect(str, Enum):
OPENING = "OPENING"
CLOSING = "CLOSING"
AUTOMATIC = "AUTOMATIC"


class AccountNumberModel(JSONSerializableBaseModel):
accountNumber: str
hashValue: str
Expand Down Expand Up @@ -164,6 +198,46 @@ class MarginInitialBalance(MarginBalance):
liquidationValue: Optional[float] = None


class AccountInstrument(JSONSerializableBaseModel):
assetType: Optional[AssetType] = None
cusip: Optional[str] = None
description: Optional[str] = None
instrumentId: Optional[int] = None
symbol: Optional[str] = None
netChange: Optional[float] = None


class AccountEquity(AccountInstrument):
assetType: AssetType = AssetType.EQUITY


class AccountFixedIncome(AccountInstrument):
assetType: AssetType = AssetType.FIXED_INCOME
maturityDate: Optional[str] = None
factor: Optional[float] = None
variableRate: Optional[float] = None


class AccountOption(AccountInstrument):
assetType: AssetType = AssetType.OPTION
optionDeliverables: Optional[Any] = None # TODO
putCall: Optional[OptionContractType] = None
optionMultiplier: Optional[int] = None
type_: Optional[OptionType] = Field(None, alias="type")
underlyingSymbol: Optional[str] = None


class OrderLegCollection(JSONSerializableBaseModel):
orderLegType: Optional[AssetType] = None
legId: Optional[int] = None
instrument: Optional[AccountInstrument] = None # e.g. AccountOption
instruction: Optional[OrderLegInstruction] = None
positionEffect: Optional[PositionEffect] = None
quantity: Optional[float] = None
# quantityType: Optional[str] = None #TODO
# toSymbol: Optional[str] = None #TODO


class Position(JSONSerializableBaseModel):
shortQuantity: Optional[float] = None
averagePrice: Optional[float] = None
Expand Down Expand Up @@ -244,7 +318,7 @@ class Order(JSONSerializableBaseModel):
priceLinkType: Optional[str] = None
price: Optional[float] = None
taxLotMethod: Optional[str] = None
orderLegCollection: List[Any] = [] # TODO: OrderLeg type
orderLegCollection: List[OrderLegCollection] = [] # TODO: OrderLeg type
activationPrice: Optional[float] = None
specialInstruction: Optional[str] = None # TODO: enum this
orderStrategyType: Optional[str] = None
Expand Down

0 comments on commit 1d7a5b8

Please sign in to comment.