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
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)
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)
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)
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)
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)
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)
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)
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)
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"
]