Skip to main content

python_1inch

A python wrapper around the 1INCH exchange API. https://1inch.exchange

API documentation:

https://docs.1inch.exchange/api/

Installation

pip install python_1inch

Usage Example

from python_1inch import OneInchExchange

eth_exchange = OneInchExchange('Some_eth_address')
bsc_exchange = OneInchExchange('Some_eth_address', chain='binance')

eth_exchange.health_check()
# 'OK'

# fetches the tokens from the API
eth_exchange.get_tokens()

# are then stored in memory
eth_exchange.tokens
# {
#  '1INCH': {'address': '0x111111111117dc0aa78b770fa6a738034120c302',
#            'decimals': 18,
#            'logoURI': 'https://tokens.1inch.exchange/0x111111111117dc0aa78b770fa6a738034120c302.png',
#            'name': '1INCH Token',
#            'symbol': '1INCH'},
#   'ETH': {'address': '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee',
#          'decimals': 18,
#          'logoURI': 'https://tokens.1inch.exchange/0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee.png',
#          'name': 'Ethereum',
#          'symbol': 'ETH'},
#   ......
# }

eth_exchange.tokens_by_address
# {
#  '0x111111111117dc0aa78b770fa6a738034120c302': 
#           {'address': '0x111111111117dc0aa78b770fa6a738034120c302',
#            'decimals': 18,
#            'logoURI': 'https://tokens.1inch.exchange/0x111111111117dc0aa78b770fa6a738034120c302.png',
#            'name': '1INCH Token',
#            'symbol': '1INCH'},
#   ......
# }


# fetches the protocols (dexes)
eth_exchange.get_protocols()

# stored in memory
eth_exchange.protocols
# {'protocols': ['WETH',
#                'UNISWAP_V2',
#                 ......
#               ]}


# fetches the protocols images
eth_exchange.get_protocols_images()

# stored in memory
eth_exchange.protocols_images
# {'protocols': [{'id': 'WETH',
#                 'img': 'https://api.1inch.exchange/WETH.png',
#                 'title': 'WETH'},
#                {'id': 'MOONISWAP',
#                 'img': 'https://api.1inch.exchange/mooniswap.png',
#                 'title': 'Mooniswap'},
#               ......
#               ]
# }

# gets the exchange rate of two tokens 
eth_exchange.get_quote(from_token_symbol='ETH', to_token_symbol='USDT', amount=1)
# {'estimatedGas': 313182,
#  'fromToken': {'address': '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee',
#                'decimals': 18,
#                'logoURI': 'https://tokens.1inch.exchange/0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee.png',
#                'name': 'Ethereum',
#                'symbol': 'ETH'},
#  'fromTokenAmount': '1000000000000000000',
#  'protocols': [[[{'fromTokenAddress': '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee',
#                   'name': 'WETH',
#                   'part': 100,
#                   'toTokenAddress': '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'}],
#                 [{'fromTokenAddress': '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
#                   'name': 'SUSHI',
#                   'part': 100,
#                   'toTokenAddress': '0xdac17f958d2ee523a2206206994597c13d831ec7'}]]],
#  'toToken': {'address': '0xdac17f958d2ee523a2206206994597c13d831ec7',
#              'decimals': 6,
#              'logoURI': 'https://tokens.1inch.exchange/0xdac17f958d2ee523a2206206994597c13d831ec7.png',
#              'name': 'Tether USD',
#              'symbol': 'USDT'},
#  'toTokenAmount': '1799077012'}


# converts wei to eth for the specified token
eth_exchange.convert_amount_to_decimal('ETH', 1000000000000000000)
# Decimal('1')

eth_exchange.convert_amount_to_decimal('USDT', 80000000)
# Decimal('80')

# UNSUPPORTED YET
# eth_exchange.do_swap()

Metadata

Release files for python-1inch 0.0.2

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

Source distribution (sdist)

Source distribution for python-1inch 0.0.2
File Size Uploaded
python_1inch-0.0.2.tar.gz 3.9 kB Details

Release files / python_1inch-0.0.2.tar.gz

Download URL python_1inch-0.0.2.tar.gz
Size 3.9 kB
Tags Source
SHA-256 checksum
How to use checksums
72f8a8e9e6ea5f349ba29231f0b920481374d2b0bc3b20c22da4016ba55e8907
BLAKE2b-256 checksum
How to use checksums
15ef621b4c76fe0ec151009d97296c0a6116a541177653d81934b7ad4926c789
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.0

Release history Release notifications | RSS feed

This release

0.0.2 This release

1 release file

0.0.1

1 release file

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