Skip to main content

1inch Limit Order Protocol v4 SDK

Project description

1inch Limit Order Protocol v4 SDK

Installation

Package manager (Pypi)

pip install ... 

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.1.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.1-py3-none-any.whl (40.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: limit_order_sdk-0.0.1.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.1.tar.gz
Algorithm Hash digest
SHA256 59b9dcc37cb36fc17b8c41eae7c450ffb1fb767f56604b75933f3c40b4903c56
MD5 d38dd339641b6e3583a3ab2e4f3e054f
BLAKE2b-256 d79586906c12cca00c719d4d66f5cf85ef43e2355d7b6e8e26a64851e39f2df0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for limit_order_sdk-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 41cfe56e33b2b5d5f3e0e9fa1ad0778852bb06006350b2563a813bd2377d852b
MD5 84b89327313b6a164640571e945c22da
BLAKE2b-256 2860d41170373edbedc370b879e9c7b5423303913661b670dc6ba22f7d753080

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