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

Uploaded Python 3

File details

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

File metadata

  • Download URL: limit_order_sdk-0.0.3.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.3.tar.gz
Algorithm Hash digest
SHA256 b6eb2b7dff30ea82ee71b7428c9853b9d727a6177809e5753ba8cd62f7b6be54
MD5 de4f834724825519df6b671163b64af5
BLAKE2b-256 759510739e121186cd9cc5abe9411351e5310f9b103eaf3ed42b2f80e63dd6bc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for limit_order_sdk-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 935d963773dc52f8ef77133c2888ac7232691f845fd1a054c2c5a1b5fe0f7e66
MD5 eec3a3f0c145987b0309baebaca6dbba
BLAKE2b-256 ab85c1069c3bc0701d4a73a2e2b47b4e044097d168351362171202413b3e677b

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