Skip to main content

1inch Limit Order Protocol v4 SDK

Project description

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)

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

limit_order_sdk-0.0.2.tar.gz (27.4 kB view details)

Uploaded Source

Built Distribution

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

limit_order_sdk-0.0.2-py3-none-any.whl (40.2 kB view details)

Uploaded Python 3

File details

Details for the file limit_order_sdk-0.0.2.tar.gz.

File metadata

  • Download URL: limit_order_sdk-0.0.2.tar.gz
  • Upload date:
  • Size: 27.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.9

File hashes

Hashes for limit_order_sdk-0.0.2.tar.gz
Algorithm Hash digest
SHA256 99dd6b2139052c16f26f38cf56ef8de7a3955c6e78a4daee5a10f08e168af235
MD5 0161087ede9e441d196286bf95b82aec
BLAKE2b-256 016e6c7f40dbfdd264d8b617a0d42a4b467b30a8ad15edfa5ca11b27d9f02e1d

See more details on using hashes here.

File details

Details for the file limit_order_sdk-0.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for limit_order_sdk-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e0f3d41de382e869890c30f342d0f610a1620ebb572fe582321bc6345d4da4f7
MD5 190da27693b718310dbf9595421f1245
BLAKE2b-256 4441e527d19d531ae68ec8dbcac7faac361b3212dbd3cab3acca76df37008243

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