Python zero_ex.sra_client

A Python client for interacting with SRA-compatible Relayers.

0x Protocol is an open standard. Many Relayers opt to implementing a set of Standard Relayer API (SRA) endpoints, to make it easier for anyone to source liquidity that conforms to the 0x order format. Here, we will show you how you can use the 0x-sra-client module to interact with 0x relayers that implement the SRA specification.

Setup

Install the package with pip:

pip install 0x-sra-client

To interact with a 0x Relayer, you need the HTTP endpoint of the Relayer you’d like to connect to (eg https://api.radarrelay.com/0x/v3).

For testing one can use the 0x-launch-kit-backend to host orders locally. The examples below assume that this server is running locally and listening on port 3000, so the Relayer URL they use is http://localhost:3000.

By default, Launch Kit will connect to Kovan via Infura. However, it can be configured to connect to any JSON-RPC endpoint, on any network. The examples below assume that Launch Kit is connected to a Ganache development network accessible at http://localhost:8545.

These examples are automatically verified by spinning up docker images 0xorg/ganache-cli, 0xorg/mesh, and 0xorg/launch-kit-backend. You can replicate this environment yourself by using this docker-compose.yml file. (Note: This will only work on Linux, because it uses network_mode: "host", which only works on Linux.)

Configure and create an API client instance

>>> from zero_ex.sra_client import RelayerApi
>>> relayer = RelayerApi("http://localhost:3000")

Preparing to trade

Making and taking orders induces the SRA endpoint to deal with the Ethereum network. Before we can start trading, we need to do a few things with the network directly.

To start, connect to the Ethereum network:

>>> from web3 import HTTPProvider, Web3
>>> eth_node = HTTPProvider("http://localhost:8545")

For our Maker role, we’ll just use the first address available in the node:

>>> maker_address = Web3(eth_node).eth.accounts[0]

The 0x Ganache snapshot loaded into our eth_node has a pre-loaded ZRX balance for this account, so the example orders below have the maker trading away ZRX. Before such an order can be valid, though, the maker must give the 0x contracts permission to trade their ZRX tokens:

>>> from zero_ex.contract_addresses import chain_to_addresses, ChainId
>>> contract_addresses = chain_to_addresses(ChainId(Web3(eth_node).eth.chainId))
>>>
>>> from zero_ex.contract_artifacts import abi_by_name
>>> zrx_token_contract = Web3(eth_node).eth.contract(
...    address=Web3.toChecksumAddress(contract_addresses.zrx_token),
...    abi=abi_by_name("ZRXToken")
... )
>>>
>>> zrx_token_contract.functions.approve(
...     Web3.toChecksumAddress(contract_addresses.erc20_proxy),
...     1000000000000000000
... ).transact(
...     {"from": Web3.toChecksumAddress(maker_address)}
... )
HexBytes('0x...')

Post Order

Post an order for our Maker to trade ZRX for WETH:

>>> from zero_ex.contract_wrappers.exchange.types import Order
>>> from zero_ex.contract_wrappers.order_conversions import order_to_jsdict
>>> from zero_ex.order_utils import (
...     asset_data_utils,
...     sign_hash)
>>> import random
>>> from datetime import datetime, timedelta
>>> order = Order(
...     makerAddress=maker_address,
...     takerAddress="0x0000000000000000000000000000000000000000",
...     senderAddress="0x0000000000000000000000000000000000000000",
...     exchangeAddress=contract_addresses.exchange,
...     feeRecipientAddress="0x0000000000000000000000000000000000000000",
...     makerAssetData=asset_data_utils.encode_erc20(
...         contract_addresses.zrx_token
...     ),
...     makerFeeAssetData=asset_data_utils.encode_erc20('0x'+'00'*20),
...     takerAssetData=asset_data_utils.encode_erc20(
...         contract_addresses.ether_token
...     ),
...     takerFeeAssetData=asset_data_utils.encode_erc20('0x'+'00'*20),
...     salt=random.randint(1, 100000000000000000),
...     makerFee=0,
...     takerFee=0,
...     makerAssetAmount=2,
...     takerAssetAmount=2,
...     expirationTimeSeconds=round(
...         (datetime.utcnow() + timedelta(days=1)).timestamp()
...     )
... )

Before hashing and submitting our order, it’s a good idea to ask the relayer how to configure the order, so that the submission won’t be rejected:

>>> order_config = relayer.get_order_config(
...     relayer_api_order_config_payload_schema={
...         "makerAddress": order["makerAddress"],
...         "takerAddress": order["takerAddress"],
...         "makerAssetAmount": order["makerAssetAmount"],
...         "takerAssetAmount": order["takerAssetAmount"],
...         "expirationTimeSeconds": order["expirationTimeSeconds"],
...         "makerAssetData": '0x' + order["makerAssetData"].hex(),
...         "takerAssetData": '0x' + order["takerAssetData"].hex(),
...         "exchangeAddress": contract_addresses.exchange,
...     }
... )
>>> order_config
{'fee_recipient_address': '0x0000000000000000000000000000000000000001',
 'maker_fee': '0',
 'sender_address': '0x0000000000000000000000000000000000000000',
 'taker_fee': '0'}

Now we’ll apply that configuration to our order before proceeding:

>>> order["feeRecipientAddress"] = order_config.fee_recipient_address
>>> order["makerFee"] = int(order_config.maker_fee)
>>> order["takerFee"] = int(order_config.taker_fee)
>>> order["senderAddress"] = order_config.sender_address
>>> from zero_ex.order_utils import generate_order_hash_hex
>>> order_hash_hex = generate_order_hash_hex(
...     order, contract_addresses.exchange, Web3(eth_node).eth.chainId
... )
>>> relayer.post_order_with_http_info(
...     signed_order_schema=order_to_jsdict(
...         order=order,
...         exchange_address=contract_addresses.exchange,
...         signature=sign_hash(
...             eth_node, Web3.toChecksumAddress(maker_address), order_hash_hex
...         ),
...         chain_id=Web3(eth_node).eth.chainId,
...     )
... )[1]
200

Get Order

(But first sleep for a moment, to give the test relayer a chance to start up.

>>> from time import sleep
>>> sleep(0.2)

This is necessary for automated verification of these examples.)

Retrieve the order we just posted:

>>> relayer.get_order("0x" + order_hash_hex)
{'meta_data': {'orderHash': '0x...',
               'remainingFillableTakerAssetAmount': '2'},
 'order': {'chainId': 1337,
           'exchangeAddress': '0x...',
           'expirationTimeSeconds': '...',
           'feeRecipientAddress': '0x0000000000000000000000000000000000000001',
           'makerAddress': '0x...',
           'makerAssetAmount': '2',
           'makerAssetData': '0xf47261b0000000000000000000000000...',
           'makerFee': '0',
           'makerFeeAssetData': '0xf47261b0000000000000000000000000...',
           'salt': '...',
           'senderAddress': '0x0000000000000000000000000000000000000000',
           'signature': '0x...',
           'takerAddress': '0x0000000000000000000000000000000000000000',
           'takerAssetAmount': '2',
           'takerAssetData': '0xf47261b0000000000000000000000000...',
           'takerFee': '0',
           'takerFeeAssetData': '0xf47261b0000000000000000000000000...'}}

Get Orders

Retrieve all of the Relayer’s orders, a set which at this point consists solely of the one we just posted:

>>> relayer.get_orders()
{'records': [{'meta_data': {'orderHash': '0x...',
                            'remainingFillableTakerAssetAmount': '2'},
              'order': {'chainId': 1337,
                        'exchangeAddress': '0x...',
                        'expirationTimeSeconds': '...',
                        'feeRecipientAddress': '0x0000000000000000000000000000000000000001',
                        'makerAddress': '0x...',
                        'makerAssetAmount': '2',
                        'makerAssetData': '0xf47261b000000000000000000000000...',
                        'makerFee': '0',
                        'makerFeeAssetData': '0xf47261b000000000000000000000000...',
                        'salt': '...',
                        'senderAddress': '0x0000000000000000000000000000000000000000',
                        'signature': '0x...',
                        'takerAddress': '0x0000000000000000000000000000000000000000',
                        'takerAssetAmount': '2',
                        'takerAssetData': '0xf47261b0000000000000000000000000...',
                        'takerFee': '0',
                        'takerFeeAssetData': '0xf47261b0000000000000000000000000...'}}...]}

Get Asset Pairs

Get all of the Relayer’s available asset pairs, which here means just WETH and ZRX, since that’s all there is on this Relayer’s order book:

>>> relayer.get_asset_pairs()
{'records': [{'assetDataA': {'assetData': '0xf47261b0000000000000000000000000...',
                             'maxAmount': '115792089237316195423570985008687907853269984665640564039457584007913129639936',
                             'minAmount': '0',
                             'precision': 18},
              'assetDataB': {'assetData': '0xf47261b0000000000000000000000000...',
                             'maxAmount': '115792089237316195423570985008687907853269984665640564039457584007913129639936',
                             'minAmount': '0',
                             'precision': 18}}]}
>>> asset_data_utils.decode_erc20_asset_data(
...     relayer.get_asset_pairs().records[0]['assetDataA']['assetData']
... ).token_address == contract_addresses.zrx_token
True
>>> asset_data_utils.decode_erc20_asset_data(
...     relayer.get_asset_pairs().records[0]['assetDataB']['assetData']
... ).token_address == contract_addresses.ether_token
True

Get Orderbook

Get the Relayer’s order book for the WETH/ZRX asset pair (which, again, consists just of our order):

>>> orderbook = relayer.get_orderbook(
...     base_asset_data= "0x" + asset_data_utils.encode_erc20(
...         contract_addresses.ether_token
...     ).hex(),
...     quote_asset_data= "0x" + asset_data_utils.encode_erc20(
...         contract_addresses.zrx_token
...     ).hex(),
... )
>>> orderbook
{'asks': {'records': [...]},
 'bids': {'records': [{'meta_data': {'orderHash': '0x...',
                                     'remainingFillableTakerAssetAmount': '2'},
                       'order': {'chainId': 1337,
                                 'exchangeAddress': '0x...',
                                 'expirationTimeSeconds': '...',
                                 'feeRecipientAddress': '0x0000000000000000000000000000000000000001',
                                 'makerAddress': '0x...',
                                 'makerAssetAmount': '2',
                                 'makerAssetData': '0xf47261b0000000000000000000000000...',
                                 'makerFee': '0',
                                 'makerFeeAssetData': '0xf47261b0000000000000000000000000...',
                                 'salt': '...',
                                 'senderAddress': '0x0000000000000000000000000000000000000000',
                                 'signature': '0x...',
                                 'takerAddress': '0x0000000000000000000000000000000000000000',
                                 'takerAssetAmount': '2',
                                 'takerAssetData': '0xf47261b0000000000000000000000000...',
                                 'takerFee': '0',
                                 'takerFeeAssetData': '0xf47261b0000000000000000000000000...'}}...]}}

Select an order from the orderbook

We’ll select the order we just submitted, which must be referred to by order hash. To calculate an order hash, we’ll use the Exchange contract:

>>> from zero_ex.contract_wrappers.exchange import Exchange
>>> exchange = Exchange(
...     web3_or_provider=eth_node,
...     contract_address=chain_to_addresses(ChainId.GANACHE).exchange
... )
>>> from zero_ex.contract_wrappers.order_conversions import jsdict_to_order
>>> order = jsdict_to_order(
...     relayer.get_order(
...         '0x' + exchange.get_order_info.call(order)["orderHash"].hex()
...     ).order
... )
>>> from pprint import pprint
>>> pprint(order)
{'chainId': 1337,
 'expirationTimeSeconds': ...,
 'feeRecipientAddress': '0x0000000000000000000000000000000000000001',
 'makerAddress': '0x...',
 'makerAssetAmount': 2,
 'makerAssetData': b...
 'makerFee': 0,
 'makerFeeAssetData': b...
 'salt': ...,
 'senderAddress': '0x0000000000000000000000000000000000000000',
 'signature': '0x...',
 'takerAddress': '0x0000000000000000000000000000000000000000',
 'takerAssetAmount': 2,
 'takerAssetData': b...,
 'takerFee': 0,
 'takerFeeAssetData': b...}

Filling or Cancelling an Order

Fills and cancels are triggered by dealing directly with the 0x Exchange contract, not by going through a Relayer.

See the 0x-contract-wrappers documentation for more examples.

Filling

>>> taker_address = Web3(eth_node).eth.accounts[1]

Our taker will take a ZRX/WETH order, but it doesn’t have any WETH yet. By depositing some ether into the WETH contract, it will be given some WETH to trade with:

>>> weth_instance = Web3(eth_node).eth.contract(
...    address=Web3.toChecksumAddress(contract_addresses.ether_token),
...    abi=abi_by_name("WETH9")
... )
>>> weth_instance.functions.deposit().transact(
...     {"from": Web3.toChecksumAddress(taker_address),
...      "value": 1000000000000000000}
... )
HexBytes('0x...')

Next the taker needs to give the 0x contracts permission to trade their WETH:

>>> weth_instance.functions.approve(
...     Web3.toChecksumAddress(contract_addresses.erc20_proxy),
...     1000000000000000000
... ).transact(
...     {"from": Web3.toChecksumAddress(taker_address)}
... )
HexBytes('0x...')

Now the taker is ready to trade.

Recall that in a previous example we selected a specific order from the order book. Now let’s have the taker fill it:

>>> from zero_ex.contract_wrappers import TxParams
>>> from zero_ex.order_utils import Order

(Due to an Issue with the Launch Kit Backend, we need to checksum the address in the order before filling it.)

>>> order['makerAddress'] = Web3.toChecksumAddress(order['makerAddress'])

Finally, filling an order requires paying a protocol fee, which can be sent as value in the transaction. The calculation of the amount to send is a function of the gas price, so we need some help from Web3.py for that:

>>> from web3.gas_strategies.rpc import rpc_gas_price_strategy
>>> web3 = Web3(eth_node)
>>> web3.eth.setGasPriceStrategy(rpc_gas_price_strategy)

Before actually executing the fill, it’s a good idea to run it as read-only (non-transactional) so that we can get intelligible errors in case there’s something wrong:

>>> pprint(exchange.fill_order.call(
...     order=order,
...     taker_asset_fill_amount=order['takerAssetAmount']/2, # note the half fill
...     signature=bytes.fromhex(order['signature'].replace('0x', '')),
...     tx_params=TxParams(
...         from_=taker_address, value=web3.eth.generateGasPrice()*150000,
...     ),
... ))
{'makerAssetFilledAmount': 1,
 'makerFeePaid': 0,
 'protocolFeePaid': ...,
 'takerAssetFilledAmount': 1,
 'takerFeePaid': 0}

Now we’re finally ready to execute the fill:

>>> exchange.fill_order.send_transaction(
...     order=order,
...     taker_asset_fill_amount=order['takerAssetAmount']/2, # note the half fill
...     signature=bytes.fromhex(order['signature'].replace('0x', '')),
...     tx_params=TxParams(
...         from_=taker_address, value=web3.eth.generateGasPrice()*150000,
...     ),
... )
HexBytes('0x...')

Cancelling

Note that the above fill was partial: it only filled half of the order. Now we’ll have our maker cancel the remaining order:

>>> exchange.cancel_order.send_transaction(
...     order=order,
...     tx_params=TxParams(from_=maker_address)
... )
HexBytes('0x...')

zero_ex.sra_client.RelayerApi

class zero_ex.sra_client.RelayerApi(url)[source]

API for SRA compliant 0x relayers.

get_asset_pairs(**kwargs)[source]

Retrieves a list of available asset pairs and the information required to trade them (in any order). Setting only assetDataA or assetDataB returns pairs filtered by that asset only. This method makes a synchronous HTTP request by default. To make an asynchronous HTTP request, please pass async_req = True

>>> thread = api.get_asset_pairs(async_req=True) 
>>> result = thread.get() 
Parameters
  • async_req (bool) – Whether request should be asynchronous.

  • asset_data_a (str) – The assetData value for the first asset in the pair.

  • asset_data_b (str) – The assetData value for the second asset in the pair.

  • page (int) – The number of the page to request in the collection.

  • per_page (int) – The number of records to return per page.

Returns

RelayerApiAssetDataPairsResponseSchema. If the method is called asynchronously returns the request thread.

get_asset_pairs_with_http_info(**kwargs)[source]

get_asset_pairs

Retrieves a list of available asset pairs and the information required to trade them (in any order). Setting only assetDataA or assetDataB returns pairs filtered by that asset only. This method makes a synchronous HTTP request by default. To make an asynchronous HTTP request, please pass async_req = True

>>> thread = api.get_asset_pairs_with_http_info(async_req=True) 
>>> result = thread.get() 
Parameters
  • async_req (bool) – Whether request should be asynchronous.

  • asset_data_a (str) – The assetData value for the first asset in the pair.

  • asset_data_b (str) – The assetData value for the second asset in the pair.

  • page (int) – The number of the page to request in the collection.

  • per_page (int) – The number of records to return per page.

Returns

A tuple consisting of a RelayerApiAssetDataPairsResponseSchema, an HTTP status code integer, and a collection of HTTP headers. If the method is called asynchronously returns the request thread.

get_fee_recipients(**kwargs)[source]

Retrieves a collection of all fee recipient addresses for a relayer. This endpoint should be paginated. This method makes a synchronous HTTP request by default. To make an asynchronous HTTP request, please pass async_req = True

>>> thread = api.get_fee_recipients(async_req=True) 
>>> result = thread.get() 
Parameters
  • async_req (bool) – Whether request should be asynchronous.

  • page (int) – The number of the page to request in the collection.

  • per_page (int) – The number of records to return per page.

Returns

RelayerApiFeeRecipientsResponseSchema. If the method is called asynchronously, returns the request thread.

get_fee_recipients_with_http_info(**kwargs)[source]

get_fee_recipients

Retrieves a collection of all fee recipient addresses for a relayer. This endpoint should be paginated. This method makes a synchronous HTTP request by default. To make an asynchronous HTTP request, please pass async_req = True

>>> thread = api.get_fee_recipients_with_http_info(async_req=True) 
>>> result = thread.get() 
Parameters
  • async_req (bool) – Whether request should be asynchronous.

  • page (int) – The number of the page to request in the collection.

  • per_page (int) – The number of records to return per page.

Returns

A tuple consisting of a RelayerApiFeeRecipientsResponseSchema, an HTTP status code integer, and a collection of HTTP headers. If the method is called asynchronously returns the request thread.

get_order(order_hash, **kwargs)[source]

Retrieves the 0x order with meta info that is associated with the hash. This method makes a synchronous HTTP request by default. To make an asynchronous HTTP request, please pass async_req = True

>>> thread = api.get_order(async_req=True) 
>>> result = thread.get() 
Parameters
  • async_req (bool) – Whether request should be asynchronous.

  • order_hash (str) – The hash of the desired 0x order. (required)

Returns

RelayerApiOrderSchema. If the method is called asynchronously, returns the request thread.

get_order_config(**kwargs)[source]

Relayers have full discretion over the orders that they are willing to host on their orderbooks (e.g what fees they charge, etc…). In order for traders to discover their requirements programmatically, they can send an incomplete order to this endpoint and receive the missing fields, specifc to that order. This gives relayers a large amount of flexibility to tailor fees to unique traders, trading pairs and volume amounts. Submit a partial order and receive information required to complete the order: senderAddress, feeRecipientAddress, makerFee, takerFee. This method makes a synchronous HTTP request by default. To make an asynchronous HTTP request, please pass async_req = True

>>> thread = api.get_order_config(async_req=True) 
>>> result = thread.get() 
Parameters
  • async_req (bool) – Whether request should be asynchronous.

  • relayer_api_order_config_payload_schema – instance of RelayerApiOrderConfigPayloadSchema. The fields of a 0x order the relayer may want to decide what configuration to send back.

Returns

RelayerApiOrderConfigResponseSchema. If the method is called asynchronously returns the request thread.

get_order_config_with_http_info(**kwargs)[source]

get_order_config

Relayers have full discretion over the orders that they are willing to host on their orderbooks (e.g what fees they charge, etc…). In order for traders to discover their requirements programmatically, they can send an incomplete order to this endpoint and receive the missing fields, specifc to that order. This gives relayers a large amount of flexibility to tailor fees to unique traders, trading pairs and volume amounts. Submit a partial order and receive information required to complete the order: senderAddress, feeRecipientAddress, makerFee, takerFee. This method makes a synchronous HTTP request by default. To make an asynchronous HTTP request, please pass async_req = True

>>> thread = api.get_order_config_with_http_info(async_req=True) 
>>> result = thread.get() 
Parameters
  • async_req (bool) – Whether request should be asynchronous.

  • relayer_api_order_config_payload_schema – instance of :class: RelayerApiOrderConfigPayloadSchema. The fields of a 0x order the relayer may want to decide what configuration to send back.

Returns

A tuple consisting of a RelayerApiOrderConfigResponseSchema, an HTTP status code integer, and a collection of HTTP headers. If the method is called asynchronously returns the request thread.

get_order_with_http_info(order_hash, **kwargs)[source]

get_order

Retrieves the 0x order with meta info that is associated with the hash. This method makes a synchronous HTTP request by default. To make an asynchronous HTTP request, please pass async_req = True

>>> thread = api.get_order_with_http_info(async_req=True) 
>>> result = thread.get() 
Parameters
  • async_req (bool) – Whether request should be asynchronous.

  • order_hash (str) – The hash of the desired 0x order. (required)

Returns

A tuple consisting of a RelayerApiOrderSchema, an HTTP status code integer, and a collection of HTTP headers. If the method is called asynchronously returns the request thread.

get_orderbook(base_asset_data, quote_asset_data, **kwargs)[source]

Retrieves the orderbook for a given asset pair. This endpoint should be paginated. Bids will be sorted in descending order by price, and asks will be sorted in ascending order by price. Within the price sorted orders, the orders are further sorted by taker fee price which is defined as the takerFee divided by takerTokenAmount. After taker fee price, orders are to be sorted by expiration in ascending order. The way pagination works for this endpoint is that the page and perPage query params apply to both bids and asks collections, and if page * perPage = total for a certain collection, the records for that collection should just be empty. This method makes a synchronous HTTP request by default. To make an asynchronous HTTP request, please pass async_req = True

>>> thread = api.get_orderbook(async_req=True) 
>>> result = thread.get() 
Parameters
  • async_req (bool) – Whether request should be asynchronous.

  • base_asset_data (str) – assetData (makerAssetData or takerAssetData) designated as the base currency in the currency pair calculation of price. (required)

  • quote_asset_data (str) – assetData (makerAssetData or takerAssetData) designated as the quote currency in the currency pair calculation of price. (required)

  • page (int) – The number of the page to request in the collection.

  • per_page (int) – The number of records to return per page.

Returns

RelayerApiOrderbookResponseSchema. If the method is called asynchronously, returns the request thread.

get_orderbook_with_http_info(base_asset_data, quote_asset_data, **kwargs)[source]

get_orderbook

Retrieves the orderbook for a given asset pair. This endpoint should be paginated. Bids will be sorted in descending order by price, and asks will be sorted in ascending order by price. Within the price sorted orders, the orders are further sorted by taker fee price which is defined as the takerFee divided by takerTokenAmount. After taker fee price, orders are to be sorted by expiration in ascending order. The way pagination works for this endpoint is that the page and perPage query params apply to both bids and asks collections, and if page * perPage = total for a certain collection, the records for that collection should just be empty. This method makes a synchronous HTTP request by default. To make an asynchronous HTTP request, please pass async_req = True

>>> thread = api.get_orderbook_with_http_info(async_req=True) 
>>> result = thread.get() 
Parameters
  • async_req (bool) – Whether request should be asynchronous.

  • base_asset_data (str) – assetData (makerAssetData or takerAssetData) designated as the base currency in the currency pair calculation of price. (required)

  • quote_asset_data (str) – assetData (makerAssetData or takerAssetData) designated as the quote currency in the currency pair calculation of price. (required)

  • page (int) – The number of the page to request in the collection.

  • per_page (int) – The number of records to return per page.

Returns

A tuple consisting of a RelayerApiOrderbookResponseSchema, an HTTP status code integer, and a collection of HTTP headers. If the method is called asynchronously returns the request thread.

get_orders(**kwargs)[source]

Retrieves a list of orders given query parameters. This endpoint should be paginated. For querying an entire orderbook snapshot, the orderbook endpoint is recommended. If both makerAssetData and takerAssetData are specified, returned orders will be sorted by price determined by (takerTokenAmount/makerTokenAmount) in ascending order. By default, orders returned by this endpoint are unsorted. This method makes a synchronous HTTP request by default. To make an asynchronous HTTP request, please pass async_req = True

>>> thread = api.get_orders(async_req=True) 
>>> result = thread.get() 
Parameters
Returns

RelayerApiOrdersResponseSchema. If the method is called asynchronously, returns the request thread.

get_orders_with_http_info(**kwargs)[source]

get_orders

Retrieves a list of orders given query parameters. This endpoint should be paginated. For querying an entire orderbook snapshot, the orderbook endpoint is recommended. If both makerAssetData and takerAssetData are specified, returned orders will be sorted by price determined by (takerTokenAmount/makerTokenAmount) in ascending order. By default, orders returned by this endpoint are unsorted. This method makes a synchronous HTTP request by default. To make an asynchronous HTTP request, please pass async_req = True

>>> thread = api.get_orders_with_http_info(async_req=True) 
>>> result = thread.get() 
Parameters
Returns

A tuple consisting of a RelayerApiOrdersResponseSchema, an HTTP status code integer, and a collection of HTTP headers. If the method is called asynchronously returns the request thread.

post_order(**kwargs)[source]

Submit a signed order to the relayer. This method makes a synchronous HTTP request by default. To make an asynchronous HTTP request, please pass async_req = True

>>> thread = api.post_order(async_req=True) 
>>> result = thread.get() 
Parameters
  • async_req (bool) – Whether request should be asynchronous.

  • signed_order_schema – Instance of SignedOrderSchema. A valid signed 0x order based on the schema.

Returns

None. If the method is called asynchronously, returns the request thread.

post_order_with_http_info(**kwargs)[source]

post_order

Submit a signed order to the relayer. This method makes a synchronous HTTP request by default. To make an asynchronous HTTP request, please pass async_req = True

>>> thread = api.post_order_with_http_info(async_req=True) 
>>> result = thread.get() 
Parameters
  • async_req (bool) – Whether request should be asynchronous.

  • signed_order_schema – Instance of SignedOrderSchema A valid signed 0x order based on the schema.

Returns

A tuple consisting of the response data (always empty for this method), an HTTP status code integer, and a collection of HTTP headers. If the method is called asynchronously returns the request thread.

zero_ex.sra_client.models

class zero_ex.sra_client.models.relayer_api_asset_data_pairs_response_schema.RelayerApiAssetDataPairsResponseSchema(records=None)[source]
Attributes:
openapi_types (dict): The key is attribute name

and the value is attribute type.

attribute_map (dict): The key is attribute name

and the value is json key in definition.

property records

Gets the records of this RelayerApiAssetDataPairsResponseSchema.

Returns

The records of this RelayerApiAssetDataPairsResponseSchema.

Return type

list[object]

to_dict()[source]

Returns the model properties as a dict

to_str()[source]

Returns the string representation of the model

class zero_ex.sra_client.models.relayer_api_asset_data_trade_info_schema.RelayerApiAssetDataTradeInfoSchema(asset_data=None, min_amount=None, max_amount=None, precision=None)[source]
Attributes:
openapi_types (dict): The key is attribute name

and the value is attribute type.

attribute_map (dict): The key is attribute name

and the value is json key in definition.

property asset_data

Gets the asset_data of this RelayerApiAssetDataTradeInfoSchema.

Returns

The asset_data of this RelayerApiAssetDataTradeInfoSchema.

Return type

str

property max_amount

Gets the max_amount of this RelayerApiAssetDataTradeInfoSchema.

Returns

The max_amount of this RelayerApiAssetDataTradeInfoSchema.

Return type

str

property min_amount

Gets the min_amount of this RelayerApiAssetDataTradeInfoSchema.

Returns

The min_amount of this RelayerApiAssetDataTradeInfoSchema.

Return type

str

property precision

Gets the precision of this RelayerApiAssetDataTradeInfoSchema.

Returns

The precision of this RelayerApiAssetDataTradeInfoSchema.

Return type

float

to_dict()[source]

Returns the model properties as a dict

to_str()[source]

Returns the string representation of the model

class zero_ex.sra_client.models.relayer_api_error_response_schema.RelayerApiErrorResponseSchema(code=None, reason=None, validation_errors=None)[source]
Attributes:
openapi_types (dict): The key is attribute name

and the value is attribute type.

attribute_map (dict): The key is attribute name

and the value is json key in definition.

property code

Gets the code of this RelayerApiErrorResponseSchema.

Returns

The code of this RelayerApiErrorResponseSchema.

Return type

int

property reason

Gets the reason of this RelayerApiErrorResponseSchema.

Returns

The reason of this RelayerApiErrorResponseSchema.

Return type

str

to_dict()[source]

Returns the model properties as a dict

to_str()[source]

Returns the string representation of the model

property validation_errors

Gets the validation_errors of this RelayerApiErrorResponseSchema.

Returns

The validation_errors of this RelayerApiErrorResponseSchema.

Return type

list[RelayerApiErrorResponseSchemaValidationErrors]

class zero_ex.sra_client.models.relayer_api_error_response_schema_validation_errors.RelayerApiErrorResponseSchemaValidationErrors(field=None, code=None, reason=None)[source]
Attributes:
openapi_types (dict): The key is attribute name

and the value is attribute type.

attribute_map (dict): The key is attribute name

and the value is json key in definition.

property code

Gets the code of this RelayerApiErrorResponseSchemaValidationErrors.

Returns

The code of this RelayerApiErrorResponseSchemaValidationErrors.

Return type

int

property field

Gets the field of this RelayerApiErrorResponseSchemaValidationErrors.

Returns

The field of this RelayerApiErrorResponseSchemaValidationErrors.

Return type

str

property reason

Gets the reason of this RelayerApiErrorResponseSchemaValidationErrors.

Returns

The reason of this RelayerApiErrorResponseSchemaValidationErrors.

Return type

str

to_dict()[source]

Returns the model properties as a dict

to_str()[source]

Returns the string representation of the model

class zero_ex.sra_client.models.relayer_api_fee_recipients_response_schema.RelayerApiFeeRecipientsResponseSchema(records=None)[source]
Attributes:
openapi_types (dict): The key is attribute name

and the value is attribute type.

attribute_map (dict): The key is attribute name

and the value is json key in definition.

property records

Gets the records of this RelayerApiFeeRecipientsResponseSchema.

Returns

The records of this RelayerApiFeeRecipientsResponseSchema.

Return type

list[str]

to_dict()[source]

Returns the model properties as a dict

to_str()[source]

Returns the string representation of the model

class zero_ex.sra_client.models.relayer_api_orderbook_response_schema.RelayerApiOrderbookResponseSchema(bids=None, asks=None)[source]
Attributes:
openapi_types (dict): The key is attribute name

and the value is attribute type.

attribute_map (dict): The key is attribute name

and the value is json key in definition.

property asks

Gets the asks of this RelayerApiOrderbookResponseSchema.

Returns

The asks of this RelayerApiOrderbookResponseSchema.

Return type

RelayerApiOrdersResponseSchema

property bids

Gets the bids of this RelayerApiOrderbookResponseSchema.

Returns

The bids of this RelayerApiOrderbookResponseSchema.

Return type

RelayerApiOrdersResponseSchema

to_dict()[source]

Returns the model properties as a dict

to_str()[source]

Returns the string representation of the model

class zero_ex.sra_client.models.relayer_api_order_config_payload_schema.RelayerApiOrderConfigPayloadSchema(maker_address=None, taker_address=None, maker_asset_amount=None, taker_asset_amount=None, maker_asset_data=None, taker_asset_data=None, exchange_address=None, expiration_time_seconds=None)[source]
Attributes:
openapi_types (dict): The key is attribute name

and the value is attribute type.

attribute_map (dict): The key is attribute name

and the value is json key in definition.

property exchange_address

Gets the exchange_address of this RelayerApiOrderConfigPayloadSchema.

Returns

The exchange_address of this RelayerApiOrderConfigPayloadSchema.

Return type

str

property expiration_time_seconds

Gets the expiration_time_seconds of this RelayerApiOrderConfigPayloadSchema.

Returns

The expiration_time_seconds of this RelayerApiOrderConfigPayloadSchema.

Return type

str

property maker_address

Gets the maker_address of this RelayerApiOrderConfigPayloadSchema.

Returns

The maker_address of this RelayerApiOrderConfigPayloadSchema.

Return type

str

property maker_asset_amount

Gets the maker_asset_amount of this RelayerApiOrderConfigPayloadSchema.

Returns

The maker_asset_amount of this RelayerApiOrderConfigPayloadSchema.

Return type

str

property maker_asset_data

Gets the maker_asset_data of this RelayerApiOrderConfigPayloadSchema.

Returns

The maker_asset_data of this RelayerApiOrderConfigPayloadSchema.

Return type

str

property taker_address

Gets the taker_address of this RelayerApiOrderConfigPayloadSchema.

Returns

The taker_address of this RelayerApiOrderConfigPayloadSchema.

Return type

str

property taker_asset_amount

Gets the taker_asset_amount of this RelayerApiOrderConfigPayloadSchema.

Returns

The taker_asset_amount of this RelayerApiOrderConfigPayloadSchema.

Return type

str

property taker_asset_data

Gets the taker_asset_data of this RelayerApiOrderConfigPayloadSchema.

Returns

The taker_asset_data of this RelayerApiOrderConfigPayloadSchema.

Return type

str

to_dict()[source]

Returns the model properties as a dict

to_str()[source]

Returns the string representation of the model

class zero_ex.sra_client.models.relayer_api_order_config_response_schema.RelayerApiOrderConfigResponseSchema(maker_fee=None, taker_fee=None, fee_recipient_address=None, sender_address=None)[source]
Attributes:
openapi_types (dict): The key is attribute name

and the value is attribute type.

attribute_map (dict): The key is attribute name

and the value is json key in definition.

property fee_recipient_address

Gets the fee_recipient_address of this RelayerApiOrderConfigResponseSchema.

Returns

The fee_recipient_address of this RelayerApiOrderConfigResponseSchema.

Return type

str

property maker_fee

Gets the maker_fee of this RelayerApiOrderConfigResponseSchema.

Returns

The maker_fee of this RelayerApiOrderConfigResponseSchema.

Return type

str

property sender_address

Gets the sender_address of this RelayerApiOrderConfigResponseSchema.

Returns

The sender_address of this RelayerApiOrderConfigResponseSchema.

Return type

str

property taker_fee

Gets the taker_fee of this RelayerApiOrderConfigResponseSchema.

Returns

The taker_fee of this RelayerApiOrderConfigResponseSchema.

Return type

str

to_dict()[source]

Returns the model properties as a dict

to_str()[source]

Returns the string representation of the model

class zero_ex.sra_client.models.relayer_api_orders_channel_subscribe_payload_schema.RelayerApiOrdersChannelSubscribePayloadSchema(maker_asset_proxy_id=None, taker_asset_proxy_id=None, maker_asset_address=None, taker_asset_address=None, maker_asset_data=None, taker_asset_data=None, trader_asset_data=None)[source]
Attributes:
openapi_types (dict): The key is attribute name

and the value is attribute type.

attribute_map (dict): The key is attribute name

and the value is json key in definition.

property maker_asset_address

Gets the maker_asset_address of this RelayerApiOrdersChannelSubscribePayloadSchema.

Returns

The maker_asset_address of this RelayerApiOrdersChannelSubscribePayloadSchema.

Return type

str

property maker_asset_data

Gets the maker_asset_data of this RelayerApiOrdersChannelSubscribePayloadSchema.

Returns

The maker_asset_data of this RelayerApiOrdersChannelSubscribePayloadSchema.

Return type

str

property maker_asset_proxy_id

Gets the maker_asset_proxy_id of this RelayerApiOrdersChannelSubscribePayloadSchema.

Returns

The maker_asset_proxy_id of this RelayerApiOrdersChannelSubscribePayloadSchema.

Return type

str

property taker_asset_address

Gets the taker_asset_address of this RelayerApiOrdersChannelSubscribePayloadSchema.

Returns

The taker_asset_address of this RelayerApiOrdersChannelSubscribePayloadSchema.

Return type

str

property taker_asset_data

Gets the taker_asset_data of this RelayerApiOrdersChannelSubscribePayloadSchema.

Returns

The taker_asset_data of this RelayerApiOrdersChannelSubscribePayloadSchema.

Return type

str

property taker_asset_proxy_id

Gets the taker_asset_proxy_id of this RelayerApiOrdersChannelSubscribePayloadSchema.

Returns

The taker_asset_proxy_id of this RelayerApiOrdersChannelSubscribePayloadSchema.

Return type

str

to_dict()[source]

Returns the model properties as a dict

to_str()[source]

Returns the string representation of the model

property trader_asset_data

Gets the trader_asset_data of this RelayerApiOrdersChannelSubscribePayloadSchema.

Returns

The trader_asset_data of this RelayerApiOrdersChannelSubscribePayloadSchema.

Return type

str

class zero_ex.sra_client.models.relayer_api_orders_channel_subscribe_schema.RelayerApiOrdersChannelSubscribeSchema(type=None, channel=None, request_id=None, payload=None)[source]
Attributes:
openapi_types (dict): The key is attribute name

and the value is attribute type.

attribute_map (dict): The key is attribute name

and the value is json key in definition.

property channel

Gets the channel of this RelayerApiOrdersChannelSubscribeSchema.

Returns

The channel of this RelayerApiOrdersChannelSubscribeSchema.

Return type

str

property payload

Gets the payload of this RelayerApiOrdersChannelSubscribeSchema.

Returns

The payload of this RelayerApiOrdersChannelSubscribeSchema.

Return type

RelayerApiOrdersChannelSubscribePayloadSchema

property request_id

Gets the request_id of this RelayerApiOrdersChannelSubscribeSchema.

Returns

The request_id of this RelayerApiOrdersChannelSubscribeSchema.

Return type

str

to_dict()[source]

Returns the model properties as a dict

to_str()[source]

Returns the string representation of the model

property type

Gets the type of this RelayerApiOrdersChannelSubscribeSchema.

Returns

The type of this RelayerApiOrdersChannelSubscribeSchema.

Return type

str

class zero_ex.sra_client.models.relayer_api_orders_channel_update_schema.RelayerApiOrdersChannelUpdateSchema(type=None, channel=None, request_id=None, payload=None)[source]
Attributes:
openapi_types (dict): The key is attribute name

and the value is attribute type.

attribute_map (dict): The key is attribute name

and the value is json key in definition.

property channel

Gets the channel of this RelayerApiOrdersChannelUpdateSchema.

Returns

The channel of this RelayerApiOrdersChannelUpdateSchema.

Return type

str

property payload

Gets the payload of this RelayerApiOrdersChannelUpdateSchema.

Returns

The payload of this RelayerApiOrdersChannelUpdateSchema.

Return type

list[RelayerApiOrderSchema]

property request_id

Gets the request_id of this RelayerApiOrdersChannelUpdateSchema.

Returns

The request_id of this RelayerApiOrdersChannelUpdateSchema.

Return type

str

to_dict()[source]

Returns the model properties as a dict

to_str()[source]

Returns the string representation of the model

property type

Gets the type of this RelayerApiOrdersChannelUpdateSchema.

Returns

The type of this RelayerApiOrdersChannelUpdateSchema.

Return type

str

class zero_ex.sra_client.models.relayer_api_order_schema.RelayerApiOrderSchema(order=None, meta_data=None)[source]
Attributes:
openapi_types (dict): The key is attribute name

and the value is attribute type.

attribute_map (dict): The key is attribute name

and the value is json key in definition.

property meta_data

Gets the meta_data of this RelayerApiOrderSchema.

Returns

The meta_data of this RelayerApiOrderSchema.

Return type

object

property order

Gets the order of this RelayerApiOrderSchema.

Returns

The order of this RelayerApiOrderSchema.

Return type

OrderSchema

to_dict()[source]

Returns the model properties as a dict

to_str()[source]

Returns the string representation of the model

class zero_ex.sra_client.models.relayer_api_orders_response_schema.RelayerApiOrdersResponseSchema(records=None)[source]
Attributes:
openapi_types (dict): The key is attribute name

and the value is attribute type.

attribute_map (dict): The key is attribute name

and the value is json key in definition.

property records

Gets the records of this RelayerApiOrdersResponseSchema.

Returns

The records of this RelayerApiOrdersResponseSchema.

Return type

list[RelayerApiOrderSchema]

to_dict()[source]

Returns the model properties as a dict

to_str()[source]

Returns the string representation of the model

class zero_ex.sra_client.models.signed_order_schema.SignedOrderSchema(signature=None)[source]
Attributes:
openapi_types (dict): The key is attribute name

and the value is attribute type.

attribute_map (dict): The key is attribute name

and the value is json key in definition.

property signature

Gets the signature of this SignedOrderSchema.

Returns

The signature of this SignedOrderSchema.

Return type

str

to_dict()[source]

Returns the model properties as a dict

to_str()[source]

Returns the string representation of the model

Indices and tables