Skip to main content

Primary API models

Project description

Primary API Models

Models for Primary API (REST / WS) messages

API Documentation: https://apihub.primary.com.ar/

Use with

Installation

pip install primary-api-models

Usage

  • Segments
import pyRofex
from primary_api_models import SegmentsResponse

pyRofex.initialize(...)

# Get all segments
response = pyRofex.get_segments()
data = SegmentsResponse.model_validate(response)
print(data.segments)
  • All Instruments
import pyRofex
from primary_api_models import AllInstrumentsResponse

pyRofex.initialize(...)

# Get available instrument list
response = pyRofex.get_all_instruments()
data = AllInstrumentsResponse.model_validate(response)
print(data.instruments)
  • Instruments by Segments/Cficode
import pyRofex
from primary_api_models import InstrumentsByResponse

pyRofex.initialize(...)

# Get instrument list by given cfi code or segment:
response = pyRofex.get_instruments('by_cfi', ...)
response = pyRofex.get_instruments('by_segments', ...)
data = InstrumentsByResponse.model_validate(response)
print(data.instruments)
  • Detailed Instruments List
import pyRofex
from primary_api_models import DetailedInstrumentsResponse

pyRofex.initialize(...)

# Get detailed instrument list
response = pyRofex.get_detailed_instruments()
data = DetailedInstrumentsResponse.model_validate(response)
print(data.instruments)
  • Instrument Details
import pyRofex
from primary_api_models import InstrumentDetailsResponse

pyRofex.initialize(...)

# Get instrument details
response = pyRofex.get_instrument_details(ticker="MERV - XMEV - AAPL - 24hs")
data = InstrumentDetailsResponse.model_validate(response)
print(data.instrument)
  • Order Status
import pyRofex
from primary_api_models import OrderStatusResponse

pyRofex.initialize(...)

# Get all order reports for the configured account
response = pyRofex.get_all_orders_status()
data = OrderStatusResponse.model_validate(response)
print(data.orders)

# Get order status
response = pyRofex.get_order_status(...)
data = OrderStatusResponse.model_validate(response)
print(data.order)
  • Market Data
import pyRofex
from primary_api_models import StatusResponse
from primary_api_models import MarketDataResponse, MarketData

pyRofex.initialize(...)

# Makes a request to the Rest API and get bids, offers and last price
# Use the MarketDataEntry enum to specify the data
entries = [pyRofex.MarketDataEntry.BIDS,
           pyRofex.MarketDataEntry.OFFERS,
           pyRofex.MarketDataEntry.LAST]

response = pyRofex.get_market_data(ticker="MERV - XMEV - AAPL - 24hs", entries=entries)
data = MarketDataResponse.model_validate(response)

if data.status == StatusResponse.OK:
    md = data.market_data
    bids = md.BI
    asks = md.OF
    last_trade = md.LA
    print(last_trade)
  • Send Order
import pyRofex
from primary_api_models import StatusResponse
from primary_api_models import Order, OrderConfirmationResponse

pyRofex.initialize(...)

new_order = Order(
    ticker="MERV - XMEV - AAPL - 24hs",
    side=pyRofex.Side.BUY,
    price=1000,
    size=5,
    order_type=pyRofex.OrderType.LIMIT,
)

response = pyRofex.send_order(**new_order.model_dump())
data = OrderConfirmationResponse.model_validate(response)
if data.status == StatusResponse.OK:
    print(data.client_id)
  • Account Report
import pyRofex
from primary_api_models import AccountReportResponse

pyRofex.initialize(...)

# Get account report
response = pyRofex.get_account_report(...)
data = AccountReportResponse.model_validate(response)
print(data.account_data)
  • Account Positions
import pyRofex
from primary_api_models import PositionsResponse

pyRofex.initialize(...)

# Get all positions for an account
response = pyRofex.get_account_report(...)
data = PositionsResponse.model_validate(response)
print(data.positions)
  • Detailed Positions
import pyRofex
from primary_api_models import DetailedPositionsResponse

pyRofex.initialize(...)

# Get detailed positions for an account
response = pyRofex.get_detailed_position(...)
data = DetailedPositionsResponse.model_validate(response)
print(data.detailed_position)

Model list

[
    // Enums
    "StatusResponse",
    "MessageType",
    "MarketId",
    "Side",
    "OrderType",
    "OrderStatus",
    "TimeInForce",
    "Currency",
    "CurrencyIndex",
    "SettlementIndex",
    "MarketDataEntry",
    "CFICode",
    "MarketSegment",
    "ContractType",
    // Models
    "AccountReportResponse",
    "AccountData",
    "CommonResponse",
    "PriceSize",
    "PriceSizeDate",
    "InstrumentId",
    "Instrument",
    "DetailedInstrumentsResponse",
    "DetailedPositionsResponse",
    "DetailedPositionData",
    "DetailedPosition",
    "EnhancedOrderReport",
    "InstrumentDetailsResponse",
    "InstrumentDetails",
    "AllInstrumentsResponse",
    "InstrumentsByResponse",
    "MarketDataResponse",
    "MarketDataMessage",
    "MarketData",
    "Order",
    "OrderReportMessage",
    "OrderReport",
    "OrderStatusResponse",
    "OrderConfirmationResponse",
    "PositionsResponse",
    "Position",
    "SegmentsResponse"
]

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

primary_api_models-0.4.8.tar.gz (13.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

primary_api_models-0.4.8-py3-none-any.whl (12.3 kB view details)

Uploaded Python 3

File details

Details for the file primary_api_models-0.4.8.tar.gz.

File metadata

  • Download URL: primary_api_models-0.4.8.tar.gz
  • Upload date:
  • Size: 13.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.13

File hashes

Hashes for primary_api_models-0.4.8.tar.gz
Algorithm Hash digest
SHA256 d98c727a99f77aa726101cbca1a99bf1dd6acf46b2d4e5a3be6f820abfcf9eb3
MD5 e28f8029e2081d94352a07fc022d4353
BLAKE2b-256 c380915dee38b7964194c933bb471162d7c248c3508473e4fa4eea3e9e6f1ae3

See more details on using hashes here.

File details

Details for the file primary_api_models-0.4.8-py3-none-any.whl.

File metadata

File hashes

Hashes for primary_api_models-0.4.8-py3-none-any.whl
Algorithm Hash digest
SHA256 50aa32351d95892710065d215b43483db7b01aef9fbc7b98935d3c589fe10155
MD5 a602299e5896dc5b44e188082b2a85bb
BLAKE2b-256 690fd6dc5d149132186d6ef451dfecbff5e430af1e998f5a38e6f21f5c81c422

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page