Skip to main content

1inch Limit Order Protocol v4 SDK

Installation

Package manager (Pypi)

pip install limit-order-sdk

From source

pip install git+https://github.com/1inch/limit-order-sdk-py.git

Docs

Usage examples

Order creation

from eth_account import Account
import time
import math
from limit_order_sdk import Address, OrderInfoData, LimitOrder, MakerTraits

chain_id = 1 # Ethereum

wallet = Account.from_key(PRIV_KEY)

# Expiration time setup
expires_in = 120  # 2 minutes in seconds
expiration = math.floor(time.time() / 1000) + expires_in

# Creating a LimitOrder
maker_traits = MakerTraits.default().with_expiration(expiration)
order_info_data = OrderInfoData(
    maker_asset=Address("0xdac17f958d2ee523a2206206994597c13d831ec7"),
    taker_asset=Address("0x111111111117dc0aa78b770fa6a738034120c302"),
    making_amount=100_000000,
    taking_amount=10_00000000000000000,
    maker=Address(wallet.address),
    # Optional fields like salt or receiver can be added here if necessary
)
order = LimitOrder(order_info_data, maker_traits)

typed_data = order.get_typed_data(chain_id)
signed_message = Account.sign_typed_data(PRIV_KEY, typed_data.domain, {"Order": typed_data.types["Order"]}, typed_data.message)

print(f"Limit Order signed message: {signed_message}\n")

RFQ Order creation

RfqOrder is a light, gas efficient version of LimitOrder, but it does not support multiple fills and extension Mainly used by market makers

from eth_account import Account
import time
import math
from limit_order_sdk import RfqOrder, rand_int, UINT_40_MAX

chain_id = 1 # Ethereum

wallet = Account.from_key(PRIV_KEY)

expires_in = 120  # 2 minutes in seconds
expiration = math.floor(time.time() / 1000) + expires_in

order_info = OrderInfoData(
    maker_asset=Address("0xdac17f958d2ee523a2206206994597c13d831ec7"),
    taker_asset=Address("0x111111111117dc0aa78b770fa6a738034120c302"),
    making_amount=100_000000,  # 100 USDT
    taking_amount=10_00000000000000000,  # 10 1INCH
    maker=Address(wallet.address),
)
options = {"allowedSender": Address("0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045"), "expiration": expiration, "nonce": rand_int(UINT_40_MAX)}
order = RfqOrder(order_info=order_info, options=options)

typed_data = order.get_typed_data(chain_id)
signed_message = Account.sign_typed_data(PRIV_KEY, typed_data.domain, {"Order": typed_data.types["Order"]}, typed_data.message)

print(f"RFQ Order signed message: {signed_message}")

API

from limit_order_sdk import Api, FetchProviderConnector, LimitOrder, ApiConfig

config = ApiConfig(
    chain_id=chain_id,
    auth_key="key",  # get it at https://portal.1inch.dev/
    http_connector=FetchProviderConnector(),  # or use any connector which implements `HttpProviderConnector`
)
api = Api(config)
# submit order
order = LimitOrder(...)  # see `Order creation` section
signature = "0x"
api.submit_order(order, signature)

# get order by hash
order_hash = order.get_order_hash(chain_id)
order_info = api.get_order_by_hash(order_hash)

# get orders by maker
orders = api.get_orders_by_maker(order.maker)

Metadata

Release files for limit-order-sdk 0.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for limit-order-sdk 0.0.3
File Size Uploaded
limit_order_sdk-0.0.3.tar.gz 27.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for limit-order-sdk 0.0.3
File Interpreter ABI Platform
limit_order_sdk-0.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 68.1 kB

Release files / limit_order_sdk-0.0.3.tar.gz

Download URL limit_order_sdk-0.0.3.tar.gz
Size 27.4 kB
Tags Source
SHA-256 checksum
How to use checksums
b6eb2b7dff30ea82ee71b7428c9853b9d727a6177809e5753ba8cd62f7b6be54
BLAKE2b-256 checksum
How to use checksums
759510739e121186cd9cc5abe9411351e5310f9b103eaf3ed42b2f80e63dd6bc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.11.9

Release files / limit_order_sdk-0.0.3-py3-none-any.whl

Download URL limit_order_sdk-0.0.3-py3-none-any.whl
Size 40.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
935d963773dc52f8ef77133c2888ac7232691f845fd1a054c2c5a1b5fe0f7e66
BLAKE2b-256 checksum
How to use checksums
ab85c1069c3bc0701d4a73a2e2b47b4e044097d168351362171202413b3e677b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.11.9

Release history Release notifications | RSS feed

This release

0.0.3 This release

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page