Skip to main content

A python wraper around the 1INCH DEX API.

Project description

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()

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

python_1inch-0.0.2.tar.gz (3.9 kB view details)

Uploaded Source

File details

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

File metadata

  • Download URL: python_1inch-0.0.2.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for python_1inch-0.0.2.tar.gz
Algorithm Hash digest
SHA256 72f8a8e9e6ea5f349ba29231f0b920481374d2b0bc3b20c22da4016ba55e8907
MD5 c728b44f5fe96c52e3e6fabd1ef6b535
BLAKE2b-256 15ef621b4c76fe0ec151009d97296c0a6116a541177653d81934b7ad4926c789

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page