コード例 #1
0
ファイル: pricing.py プロジェクト: hamx0r/v20-python
class QuoteHomeConversionFactors(BaseEntity):
    _summary_format = ""
    _name_format = ""

    _properties = [
        Property(
            "positiveUnits", "positiveUnits",
            "The factor used to convert a positive amount of the Price's Instrument's quote currency into a positive amount of the Account's home currency.  Conversion is performed by multiplying the quote units by the conversion factor.",
            "primitive", "primitives.DecimalNumber", False, None),
        Property(
            "negativeUnits", "negativeUnits",
            "The factor used to convert a negative amount of the Price's Instrument's quote currency into a negative amount of the Account's home currency.  Conversion is performed by multiplying the quote units by the conversion factor.",
            "primitive", "primitives.DecimalNumber", False, None),
    ]

    def __init__(self, **kwargs):
        super(QuoteHomeConversionFactors, self).__init__()
        for prop in self._properties:
            setattr(self, prop.name, kwargs.get(prop.name, prop.default))

    @staticmethod
    def from_dict(data):

        body = {}
        if data.get('positiveUnits') is not None:
            body['positiveUnits'] = \
                data.get('positiveUnits')

        if data.get('negativeUnits') is not None:
            body['negativeUnits'] = \
                data.get('negativeUnits')

        self = QuoteHomeConversionFactors(**body)

        return self
コード例 #2
0
ファイル: trade.py プロジェクト: hamx0r/v20-python
class CalculatedTradeState(BaseEntity):
    _summary_format = ""
    _name_format = ""

    _properties = [
        Property("id", "Trade ID", "The Trade's ID.", "primitive",
                 "trade.TradeID", False, None),
        Property("unrealizedPL", "Trade UPL",
                 "The Trade's unrealized profit/loss.", "primitive",
                 "primitives.AccountUnits", False, None),
    ]

    def __init__(self, **kwargs):
        super(CalculatedTradeState, self).__init__()
        for prop in self._properties:
            setattr(self, prop.name, kwargs.get(prop.name, prop.default))

    @staticmethod
    def from_dict(data):

        body = {}
        if data.get('id') is not None:
            body['id'] = \
                data.get('id')

        if data.get('unrealizedPL') is not None:
            body['unrealizedPL'] = \
                data.get('unrealizedPL')

        self = CalculatedTradeState(**body)

        return self
コード例 #3
0
ファイル: pricing.py プロジェクト: hamx0r/v20-python
class PriceBucket(BaseEntity):
    _summary_format = ""
    _name_format = ""

    _properties = [
        Property("price", "price", "The Price offered by the PriceBucket",
                 "primitive", "pricing.PriceValue", False, None),
        Property("liquidity", "liquidity",
                 "The amount of liquidity offered by the PriceBucket",
                 "primitive", "integer", False, None),
    ]

    def __init__(self, **kwargs):
        super(PriceBucket, self).__init__()
        for prop in self._properties:
            setattr(self, prop.name, kwargs.get(prop.name, prop.default))

    @staticmethod
    def from_dict(data):

        body = {}
        if data.get('price') is not None:
            body['price'] = \
                data.get('price')

        if data.get('liquidity') is not None:
            body['liquidity'] = \
                data.get('liquidity')

        self = PriceBucket(**body)

        return self
コード例 #4
0
class CandlestickData(BaseEntity):
    _summary_format = ""
    _name_format = ""

    _properties = [
        Property(
            "o", "o",
            "The first (open) price in the time-range represented by the candlestick.",
            "primitive", "pricing.PriceValue", False, None),
        Property(
            "h", "h",
            "The highest price in the time-range represented by the candlestick.",
            "primitive", "pricing.PriceValue", False, None),
        Property(
            "l", "l",
            "The lowest price in the time-range represented by the candlestick.",
            "primitive", "pricing.PriceValue", False, None),
        Property(
            "c", "c",
            "The last (closing) price in the time-range represented by the candlestick.",
            "primitive", "pricing.PriceValue", False, None),
    ]

    def __init__(self, **kwargs):
        super(CandlestickData, self).__init__()
        for prop in self._properties:
            setattr(self, prop.name, kwargs.get(prop.name, prop.default))

    @staticmethod
    def from_dict(data):

        body = {}
        if data.get('o') is not None:
            body['o'] = \
                data.get('o')

        if data.get('h') is not None:
            body['h'] = \
                data.get('h')

        if data.get('l') is not None:
            body['l'] = \
                data.get('l')

        if data.get('c') is not None:
            body['c'] = \
                data.get('c')

        self = CandlestickData(**body)

        return self
コード例 #5
0
ファイル: pricing.py プロジェクト: hamx0r/v20-python
class UnitsAvailableDetails(BaseEntity):
    _summary_format = ""
    _name_format = ""

    _properties = [
        Property(
            "default", "default",
            "The number of units that are available to be traded using an Order with a positionFill option of \"DEFAULT\". For an Account with hedging enabled, this value will be the same as the \"OPEN_ONLY\" value. For an Account without hedging enabled, this value will be the same as the \"REDUCE_FIRST\" value.",
            "primitive", "primitives.DecimalNumber", False, None),
        Property(
            "reduceFirst", "reduceFirst",
            "The number of units that may are available to be traded with an Order with a positionFill option of \"REDUCE_FIRST\".",
            "primitive", "primitives.DecimalNumber", False, None),
        Property(
            "reduceOnly", "reduceOnly",
            "The number of units that may are available to be traded with an Order with a positionFill option of \"REDUCE_ONLY\".",
            "primitive", "primitives.DecimalNumber", False, None),
        Property(
            "openOnly", "openOnly",
            "The number of units that may are available to be traded with an Order with a positionFill option of \"OPEN_ONLY\".",
            "primitive", "primitives.DecimalNumber", False, None),
    ]

    def __init__(self, **kwargs):
        super(UnitsAvailableDetails, self).__init__()
        for prop in self._properties:
            setattr(self, prop.name, kwargs.get(prop.name, prop.default))

    @staticmethod
    def from_dict(data):

        body = {}
        if data.get('default') is not None:
            body['default'] = \
                data.get('default')

        if data.get('reduceFirst') is not None:
            body['reduceFirst'] = \
                data.get('reduceFirst')

        if data.get('reduceOnly') is not None:
            body['reduceOnly'] = \
                data.get('reduceOnly')

        if data.get('openOnly') is not None:
            body['openOnly'] = \
                data.get('openOnly')

        self = UnitsAvailableDetails(**body)

        return self
コード例 #6
0
ファイル: pricing.py プロジェクト: englianhu/v20-python
class UnitsAvailable(BaseEntity):
    _summary_format = ""
    _name_format = ""

    _properties = [
        Property(
            "long",
            "long",
            "The units available breakdown for long Orders.",
            "object",
            "pricing.UnitsAvailableDetails",
            False,
            None
        ),
        Property(
            "short",
            "short",
            "The units available breakdown for short Orders.",
            "object",
            "pricing.UnitsAvailableDetails",
            False,
            None
        ),
    ]

    def __init__(self, **kwargs):
        super(UnitsAvailable, self).__init__()
        for prop in self._properties:
            setattr(self, prop.name, kwargs.get(prop.name, prop.default))

    @staticmethod
    def from_dict(data):

        body = {}
        if data.get('long') is not None:
            body['long'] = \
                UnitsAvailableDetails.from_dict(
                    data['long']
                )

        if data.get('short') is not None:
            body['short'] = \
                UnitsAvailableDetails.from_dict(
                    data['short']
                )

        self = UnitsAvailable(**body)

        return self
コード例 #7
0
ファイル: position.py プロジェクト: englianhu/v20-python
class CalculatedPositionState(BaseEntity):
    _summary_format = ""
    _name_format = ""

    _properties = [
        Property("instrument", "instrument", "The Position's Instrument.",
                 "primitive", "primitives.InstrumentName", False, None),
        Property("netUnrealizedPL", "netUnrealizedPL",
                 "The Position's net unrealized profit/loss", "primitive",
                 "primitives.AccountUnits", False, None),
        Property(
            "longUnrealizedPL", "longUnrealizedPL",
            "The unrealized profit/loss of the Position's long open Trades",
            "primitive", "primitives.AccountUnits", False, None),
        Property(
            "shortUnrealizedPL", "shortUnrealizedPL",
            "The unrealized profit/loss of the Position's short open Trades",
            "primitive", "primitives.AccountUnits", False, None),
    ]

    def __init__(self, **kwargs):
        super(CalculatedPositionState, self).__init__()
        for prop in self._properties:
            setattr(self, prop.name, kwargs.get(prop.name, prop.default))

    @staticmethod
    def from_dict(data):

        body = {}
        if data.get('instrument') is not None:
            body['instrument'] = \
                data.get('instrument')

        if data.get('netUnrealizedPL') is not None:
            body['netUnrealizedPL'] = \
                data.get('netUnrealizedPL')

        if data.get('longUnrealizedPL') is not None:
            body['longUnrealizedPL'] = \
                data.get('longUnrealizedPL')

        if data.get('shortUnrealizedPL') is not None:
            body['shortUnrealizedPL'] = \
                data.get('shortUnrealizedPL')

        self = CalculatedPositionState(**body)

        return self
コード例 #8
0
ファイル: pricing.py プロジェクト: englianhu/v20-python
class Heartbeat(BaseEntity):
    _summary_format = "Pricing Heartbeat {time}"
    _name_format = ""

    _properties = [
        Property(
            "type",
            "type",
            "The string \"HEARTBEAT\"",
            "primitive",
            "string",
            False,
            "HEARTBEAT"
        ),
        Property(
            "time",
            "time",
            "The date/time when the Heartbeat was created.",
            "primitive",
            "primitives.DateTime",
            False,
            None
        ),
    ]

    def __init__(self, **kwargs):
        super(Heartbeat, self).__init__()
        for prop in self._properties:
            setattr(self, prop.name, kwargs.get(prop.name, prop.default))

    @staticmethod
    def from_dict(data):

        body = {}
        if data.get('type') is not None:
            body['type'] = \
                data.get('type')

        if data.get('time') is not None:
            body['time'] = \
                data.get('time')

        self = Heartbeat(**body)

        return self
コード例 #9
0
ファイル: user.py プロジェクト: englianhu/v20-python
class UserInfo(BaseEntity):
    _summary_format = ""
    _name_format = ""

    _properties = [
        Property("username", "username", "The user-provided username.",
                 "primitive", "string", False, None),
        Property("userID", "userID", "The user's OANDA-assigned user ID.",
                 "primitive", "integer", False, None),
        Property("country", "country",
                 "The country that the user is based in.", "primitive",
                 "string", False, None),
        Property("emailAddress", "emailAddress", "The user's email address.",
                 "primitive", "string", False, None),
    ]

    def __init__(self, **kwargs):
        super(UserInfo, self).__init__()
        for prop in self._properties:
            setattr(self, prop.name, kwargs.get(prop.name, prop.default))

    @staticmethod
    def from_dict(data):

        body = {}
        if data.get('username') is not None:
            body['username'] = \
                data.get('username')

        if data.get('userID') is not None:
            body['userID'] = \
                data.get('userID')

        if data.get('country') is not None:
            body['country'] = \
                data.get('country')

        if data.get('emailAddress') is not None:
            body['emailAddress'] = \
                data.get('emailAddress')

        self = UserInfo(**body)

        return self
コード例 #10
0
ファイル: user.py プロジェクト: englianhu/v20-python
class UserInfoExternal(BaseEntity):
    _summary_format = ""
    _name_format = ""

    _properties = [
        Property("userID", "userID", "The user's OANDA-assigned user ID.",
                 "primitive", "integer", False, None),
        Property("country", "country",
                 "The country that the user is based in.", "primitive",
                 "string", False, None),
        Property(
            "FIFO", "FIFO",
            "Flag indicating if the the user's Accounts adhere to FIFO execution rules.",
            "primitive", "boolean", False, None),
    ]

    def __init__(self, **kwargs):
        super(UserInfoExternal, self).__init__()
        for prop in self._properties:
            setattr(self, prop.name, kwargs.get(prop.name, prop.default))

    @staticmethod
    def from_dict(data):

        body = {}
        if data.get('userID') is not None:
            body['userID'] = \
                data.get('userID')

        if data.get('country') is not None:
            body['country'] = \
                data.get('country')

        if data.get('FIFO') is not None:
            body['FIFO'] = \
                data.get('FIFO')

        self = UserInfoExternal(**body)

        return self
コード例 #11
0
ファイル: trade.py プロジェクト: hamx0r/v20-python
class Trade(BaseEntity):
    _summary_format = "{initialUnits} of {instrument} @ {price}"
    _name_format = "Trade {id}"

    _properties = [
        Property("id", "Trade ID",
                 "The Trade's identifier, unique within the Trade's Account.",
                 "primitive", "trade.TradeID", False, None),
        Property("instrument", "Instrument", "The Trade's Instrument.",
                 "primitive", "primitives.InstrumentName", False, None),
        Property("price", "Fill Price", "The execution price of the Trade.",
                 "primitive", "pricing.PriceValue", False, None),
        Property("openTime", "Open Time",
                 "The date/time when the Trade was opened.", "primitive",
                 "primitives.DateTime", False, None),
        Property("state", "State", "The current state of the Trade.",
                 "primitive", "trade.TradeState", False, None),
        Property(
            "initialUnits", "Initial Trade Units",
            "The initial size of the Trade. Negative values indicate a short Trade, and positive values indicate a long Trade.",
            "primitive", "primitives.DecimalNumber", False, None),
        Property(
            "currentUnits", "Current Open Trade Units",
            "The number of units currently open for the Trade. This value is reduced to 0.0 as the Trade is closed.",
            "primitive", "primitives.DecimalNumber", False, None),
        Property(
            "realizedPL", "Realized Profit/Loss",
            "The total profit/loss realized on the closed portion of the Trade.",
            "primitive", "primitives.AccountUnits", False, None),
        Property(
            "unrealizedPL", "Unrealized Profit/Loss",
            "The unrealized profit/loss on the open portion of the Trade.",
            "primitive", "primitives.AccountUnits", False, None),
        Property(
            "closingTransactionIDs", "Closing Transaction IDs",
            "The IDs of the Transactions that have closed portions of this Trade.",
            "array_primitive", "TransactionID", False, None),
        Property("financing", "Financing",
                 "The financing paid/collected for this Trade.", "primitive",
                 "primitives.AccountUnits", False, None),
        Property(
            "closeTime", "Close Time",
            "The date/time when the Trade was fully closed. Only provided for Trades whose state is CLOSED.",
            "primitive", "primitives.DateTime", False, None),
        Property("clientExtensions", "Client Extensions",
                 "The client extensions of the Trade.", "object",
                 "transaction.ClientExtensions", False, None),
        Property(
            "takeProfitOrder", "Take Profit Order",
            "Full representation of the Trade's Take Profit Order, only provided if such an Order exists.",
            "object", "order.TakeProfitOrder", False, None),
        Property(
            "stopLossOrder", "Stop Loss Order",
            "Full representation of the Trade's Stop Loss Order, only provided if such an Order exists.",
            "object", "order.StopLossOrder", False, None),
        Property(
            "trailingStopLossOrder", "Trailing Stop Loss Order",
            "Full representation of the Trade's Trailing Stop Loss Order, only provided if such an Order exists.",
            "object", "order.TrailingStopLossOrder", False, None),
    ]

    def __init__(self, **kwargs):
        super(Trade, self).__init__()
        for prop in self._properties:
            setattr(self, prop.name, kwargs.get(prop.name, prop.default))

    @staticmethod
    def from_dict(data):

        body = {}
        if data.get('id') is not None:
            body['id'] = \
                data.get('id')

        if data.get('instrument') is not None:
            body['instrument'] = \
                data.get('instrument')

        if data.get('price') is not None:
            body['price'] = \
                data.get('price')

        if data.get('openTime') is not None:
            body['openTime'] = \
                data.get('openTime')

        if data.get('state') is not None:
            body['state'] = \
                data.get('state')

        if data.get('initialUnits') is not None:
            body['initialUnits'] = \
                data.get('initialUnits')

        if data.get('currentUnits') is not None:
            body['currentUnits'] = \
                data.get('currentUnits')

        if data.get('realizedPL') is not None:
            body['realizedPL'] = \
                data.get('realizedPL')

        if data.get('unrealizedPL') is not None:
            body['unrealizedPL'] = \
                data.get('unrealizedPL')

        if data.get('closingTransactionIDs') is not None:
            body['closingTransactionIDs'] = \
                data.get('closingTransactionIDs')

        if data.get('financing') is not None:
            body['financing'] = \
                data.get('financing')

        if data.get('closeTime') is not None:
            body['closeTime'] = \
                data.get('closeTime')

        if data.get('clientExtensions') is not None:
            body['clientExtensions'] = \
                transaction.ClientExtensions.from_dict(
                    data['clientExtensions']
                )

        if data.get('takeProfitOrder') is not None:
            body['takeProfitOrder'] = \
                order.TakeProfitOrder.from_dict(
                    data['takeProfitOrder']
                )

        if data.get('stopLossOrder') is not None:
            body['stopLossOrder'] = \
                order.StopLossOrder.from_dict(
                    data['stopLossOrder']
                )

        if data.get('trailingStopLossOrder') is not None:
            body['trailingStopLossOrder'] = \
                order.TrailingStopLossOrder.from_dict(
                    data['trailingStopLossOrder']
                )

        self = Trade(**body)

        return self
コード例 #12
0
ファイル: pricing.py プロジェクト: englianhu/v20-python
class Price(BaseEntity):
    _summary_format = ""
    _name_format = ""

    _properties = [
        Property(
            "type",
            "Type",
            "The string \"PRICE\". Used to identify the a Price object when found in a stream.",
            "primitive",
            "string",
            False,
            "PRICE"
        ),
        Property(
            "instrument",
            "instrument",
            "The Price's Instrument.",
            "primitive",
            "primitives.InstrumentName",
            False,
            None
        ),
        Property(
            "time",
            "time",
            "The date/time when the Price was created",
            "primitive",
            "primitives.DateTime",
            False,
            None
        ),
        Property(
            "status",
            "status",
            "The status of the Price.",
            "primitive",
            "pricing.PriceStatus",
            False,
            None
        ),
        Property(
            "bids",
            "bids",
            "The list of prices and liquidity available on the Instrument's bid side. It is possible for this list to be empty if there is no bid liquidity currently available for the Instrument in the Account.",
            "array_object",
            "PriceBucket",
            False,
            None
        ),
        Property(
            "asks",
            "asks",
            "The list of prices and liquidity available on the Instrument's ask side. It is possible for this list to be empty if there is no ask liquidity currently available for the Instrument in the Account.",
            "array_object",
            "PriceBucket",
            False,
            None
        ),
        Property(
            "closeoutBid",
            "closeoutBid",
            "The closeout bid Price. This Price is used when a bid is required to closeout a Position (margin closeout or manual) yet there is no bid liquidity. The closeout bid is never used to open a new position.",
            "primitive",
            "pricing.PriceValue",
            False,
            None
        ),
        Property(
            "closeoutAsk",
            "closeoutAsk",
            "The closeout ask Price. This Price is used when a ask is required to closeout a Position (margin closeout or manual) yet there is no ask liquidity. The closeout ask is never used to open a new position.",
            "primitive",
            "pricing.PriceValue",
            False,
            None
        ),
        Property(
            "quoteHomeConversionFactors",
            "quoteHomeConversionFactors",
            "The factors used to convert quantities of this price's Instrument's quote currency into a quantity of the Account's home currency.",
            "object",
            "pricing.QuoteHomeConversionFactors",
            False,
            None
        ),
        Property(
            "unitsAvailable",
            "unitsAvailable",
            "Representation of many units of an Instrument are available to be traded for both long and short Orders.",
            "object",
            "pricing.UnitsAvailable",
            False,
            None
        ),
    ]

    def __init__(self, **kwargs):
        super(Price, self).__init__()
        for prop in self._properties:
            setattr(self, prop.name, kwargs.get(prop.name, prop.default))

    @staticmethod
    def from_dict(data):

        body = {}
        if data.get('type') is not None:
            body['type'] = \
                data.get('type')

        if data.get('instrument') is not None:
            body['instrument'] = \
                data.get('instrument')

        if data.get('time') is not None:
            body['time'] = \
                data.get('time')

        if data.get('status') is not None:
            body['status'] = \
                data.get('status')

        if data.get('bids') is not None:
            body['bids'] = [
                PriceBucket.from_dict(d)
                for d in data.get('bids')
            ]

        if data.get('asks') is not None:
            body['asks'] = [
                PriceBucket.from_dict(d)
                for d in data.get('asks')
            ]

        if data.get('closeoutBid') is not None:
            body['closeoutBid'] = \
                data.get('closeoutBid')

        if data.get('closeoutAsk') is not None:
            body['closeoutAsk'] = \
                data.get('closeoutAsk')

        if data.get('quoteHomeConversionFactors') is not None:
            body['quoteHomeConversionFactors'] = \
                QuoteHomeConversionFactors.from_dict(
                    data['quoteHomeConversionFactors']
                )

        if data.get('unitsAvailable') is not None:
            body['unitsAvailable'] = \
                UnitsAvailable.from_dict(
                    data['unitsAvailable']
                )

        self = Price(**body)

        return self
コード例 #13
0
ファイル: position.py プロジェクト: englianhu/v20-python
class Position(BaseEntity):
    _summary_format = "{instrument}, {pl} PL {unrealizedPL} UPL"
    _name_format = "Position"

    _properties = [
        Property("instrument", "instrument", "The Position's Instrument.",
                 "primitive", "primitives.InstrumentName", False, None),
        Property(
            "pl", "pl",
            "Profit/loss realized by the Position over the lifetime of the Account.",
            "primitive", "primitives.AccountUnits", False, None),
        Property(
            "unrealizedPL", "unrealizedPL",
            "The unrealized profit/loss of all open Trades that contribute to this Position.",
            "primitive", "primitives.AccountUnits", False, None),
        Property(
            "resettablePL", "resettablePL",
            "Profit/loss realized by the Position since the Account's resettablePL was last reset by the client.",
            "primitive", "primitives.AccountUnits", False, None),
        Property("long", "long",
                 "The details of the long side of the Position.", "object",
                 "position.PositionSide", False, None),
        Property("short", "short",
                 "The details of the short side of the Position.", "object",
                 "position.PositionSide", False, None),
    ]

    def __init__(self, **kwargs):
        super(Position, self).__init__()
        for prop in self._properties:
            setattr(self, prop.name, kwargs.get(prop.name, prop.default))

    @staticmethod
    def from_dict(data):

        body = {}
        if data.get('instrument') is not None:
            body['instrument'] = \
                data.get('instrument')

        if data.get('pl') is not None:
            body['pl'] = \
                data.get('pl')

        if data.get('unrealizedPL') is not None:
            body['unrealizedPL'] = \
                data.get('unrealizedPL')

        if data.get('resettablePL') is not None:
            body['resettablePL'] = \
                data.get('resettablePL')

        if data.get('long') is not None:
            body['long'] = \
                PositionSide.from_dict(
                    data['long']
                )

        if data.get('short') is not None:
            body['short'] = \
                PositionSide.from_dict(
                    data['short']
                )

        self = Position(**body)

        return self
コード例 #14
0
ファイル: position.py プロジェクト: englianhu/v20-python
class PositionSide(BaseEntity):
    _summary_format = ""
    _name_format = ""

    _properties = [
        Property(
            "units", "units",
            "Number of units in the position (negative value indicates short position, positive indicates long position).",
            "primitive", "primitives.DecimalNumber", False, None),
        Property(
            "averagePrice", "averagePrice",
            "Volume-weighted average of the underlying Trade open prices for the Position.",
            "primitive", "pricing.PriceValue", False, None),
        Property(
            "tradeIDs", "tradeIDs",
            "List of the open Trade IDs which contribute to the open Position.",
            "array_primitive", "TradeID", False, None),
        Property(
            "pl", "pl",
            "Profit/loss realized by the PositionSide over the lifetime of the Account.",
            "primitive", "primitives.AccountUnits", False, None),
        Property(
            "unrealizedPL", "unrealizedPL",
            "The unrealized profit/loss of all open Trades that contribute to this PositionSide.",
            "primitive", "primitives.AccountUnits", False, None),
        Property(
            "resettablePL", "resettablePL",
            "Profit/loss realized by the PositionSide since the Account's resettablePL was last reset by the client.",
            "primitive", "primitives.AccountUnits", False, None),
    ]

    def __init__(self, **kwargs):
        super(PositionSide, self).__init__()
        for prop in self._properties:
            setattr(self, prop.name, kwargs.get(prop.name, prop.default))

    @staticmethod
    def from_dict(data):

        body = {}
        if data.get('units') is not None:
            body['units'] = \
                data.get('units')

        if data.get('averagePrice') is not None:
            body['averagePrice'] = \
                data.get('averagePrice')

        if data.get('tradeIDs') is not None:
            body['tradeIDs'] = \
                data.get('tradeIDs')

        if data.get('pl') is not None:
            body['pl'] = \
                data.get('pl')

        if data.get('unrealizedPL') is not None:
            body['unrealizedPL'] = \
                data.get('unrealizedPL')

        if data.get('resettablePL') is not None:
            body['resettablePL'] = \
                data.get('resettablePL')

        self = PositionSide(**body)

        return self
コード例 #15
0
class Instrument(BaseEntity):
    _summary_format = ""
    _name_format = ""

    _properties = [
        Property("name", "name", "The name of the Instrument", "primitive",
                 "primitives.InstrumentName", False, None),
        Property("type", "type", "The type of the Instrument", "primitive",
                 "primitives.InstrumentType", False, None),
        Property("displayName", "displayName",
                 "The display name of the Instrument", "primitive", "string",
                 False, None),
        Property(
            "pipLocation", "pipLocation",
            "The location of the \"pip\" for this instrument. The decimal position of the pip in this Instrument's price can be found at 10 ^ pipLocation (e.g. -4 pipLocation results in a decimal pip position of 10 ^ -4 = 0.0001).",
            "primitive", "integer", False, None),
        Property(
            "displayPrecision", "displayPrecision",
            "The number of decimal places that should be used to display prices for this instrument. (e.g. a displayPrecision of 5 would result in a price of \"1\" being displayed as \"1.00000\")",
            "primitive", "integer", False, None),
        Property(
            "tradeUnitsPrecision", "tradeUnitsPrecision",
            "The amount of decimal places that may be provided when specifying the number of units traded for this instrument.",
            "primitive", "integer", False, None),
        Property(
            "minimumTradeSize", "minimumTradeSize",
            "The smallest number of units allowed to be traded for this instrument.",
            "primitive", "primitives.DecimalNumber", False, None),
        Property(
            "maximumTrailingStopDistance", "maximumTrailingStopDistance",
            "The maximum trailing stop distance allowed for a trailing stop loss created for this instrument. Specified in price units.",
            "primitive", "primitives.DecimalNumber", False, None),
        Property(
            "minimumTrailingStopDistance", "minimumTrailingStopDistance",
            "The minimum trailing stop distance allowed for a trailing stop loss created for this instrument. Specified in price units.",
            "primitive", "primitives.DecimalNumber", False, None),
        Property(
            "maximumPositionSize", "maximumPositionSize",
            "The maximum position size allowed for this instrument. Specified in units.",
            "primitive", "primitives.DecimalNumber", False, None),
        Property(
            "maximumOrderUnits", "maximumOrderUnits",
            "The maximum units allowed for an Order placed for this instrument. Specified in units.",
            "primitive", "primitives.DecimalNumber", False, None),
        Property("marginRate", "marginRate",
                 "The margin rate for this instrument.", "primitive",
                 "primitives.DecimalNumber", False, None),
    ]

    def __init__(self, **kwargs):
        super(Instrument, self).__init__()
        for prop in self._properties:
            setattr(self, prop.name, kwargs.get(prop.name, prop.default))

    @staticmethod
    def from_dict(data):

        body = {}
        if data.get('name') is not None:
            body['name'] = \
                data.get('name')

        if data.get('type') is not None:
            body['type'] = \
                data.get('type')

        if data.get('displayName') is not None:
            body['displayName'] = \
                data.get('displayName')

        if data.get('pipLocation') is not None:
            body['pipLocation'] = \
                data.get('pipLocation')

        if data.get('displayPrecision') is not None:
            body['displayPrecision'] = \
                data.get('displayPrecision')

        if data.get('tradeUnitsPrecision') is not None:
            body['tradeUnitsPrecision'] = \
                data.get('tradeUnitsPrecision')

        if data.get('minimumTradeSize') is not None:
            body['minimumTradeSize'] = \
                data.get('minimumTradeSize')

        if data.get('maximumTrailingStopDistance') is not None:
            body['maximumTrailingStopDistance'] = \
                data.get('maximumTrailingStopDistance')

        if data.get('minimumTrailingStopDistance') is not None:
            body['minimumTrailingStopDistance'] = \
                data.get('minimumTrailingStopDistance')

        if data.get('maximumPositionSize') is not None:
            body['maximumPositionSize'] = \
                data.get('maximumPositionSize')

        if data.get('maximumOrderUnits') is not None:
            body['maximumOrderUnits'] = \
                data.get('maximumOrderUnits')

        if data.get('marginRate') is not None:
            body['marginRate'] = \
                data.get('marginRate')

        self = Instrument(**body)

        return self
コード例 #16
0
class Candlestick(BaseEntity):
    _summary_format = ""
    _name_format = ""

    _properties = [
        Property("time", "time", "The start time of the candlestick",
                 "primitive", "primitives.DateTime", False, None),
        Property(
            "bid", "bid",
            "The candlestick data based on bids. Only provided if bid-based candles were requested.",
            "object", "instrument.CandlestickData", False, None),
        Property(
            "ask", "ask",
            "The candlestick data based on asks. Only provided if ask-based candles were requested.",
            "object", "instrument.CandlestickData", False, None),
        Property(
            "mid", "mid",
            "The candlestick data based on midpoints. Only provided if midpoint-based candles were requested.",
            "object", "instrument.CandlestickData", False, None),
        Property(
            "volume", "volume",
            "The number of prices created during the time-range represented by the candlestick.",
            "primitive", "integer", False, None),
        Property(
            "complete", "complete",
            "A flag indicating if the candlestick is complete. A complete candlestick is one whose ending time is not in the future.",
            "primitive", "boolean", False, None),
    ]

    def __init__(self, **kwargs):
        super(Candlestick, self).__init__()
        for prop in self._properties:
            setattr(self, prop.name, kwargs.get(prop.name, prop.default))

    @staticmethod
    def from_dict(data):

        body = {}
        if data.get('time') is not None:
            body['time'] = \
                data.get('time')

        if data.get('bid') is not None:
            body['bid'] = \
                CandlestickData.from_dict(
                    data['bid']
                )

        if data.get('ask') is not None:
            body['ask'] = \
                CandlestickData.from_dict(
                    data['ask']
                )

        if data.get('mid') is not None:
            body['mid'] = \
                CandlestickData.from_dict(
                    data['mid']
                )

        if data.get('volume') is not None:
            body['volume'] = \
                data.get('volume')

        if data.get('complete') is not None:
            body['complete'] = \
                data.get('complete')

        self = Candlestick(**body)

        return self