Package: python-switcheo
Python Client for interacting with the Switcheo API.Table of ContentsOverviewInstallationPublic ClientAuthenticated  ClientDonationsOverviewIntroductionThis library is intended to empower developers to more easily interact with the Switcheo Decentralized Exchange through simple Python interfaces.Switcheo is the first functional DEX in the NEO Smart Economy and with the version 2 release of its platform made an API endpoint widely available for developers to build on top of it.  This package is a wrapper around the API endpoints and is attempting to replicate and expand on the original functions available.The official Switcheo documentation can be found athttps://docs.switcheo.network/API RequestsThe Switcheo API uses REST architecture to server data through its endpoints.  The requests and responses of the endpoint use JSON format.While the endpoint returns JSON this package turns the request into a Python dictionary for easier interoperability and function lookup.There are two type of API endpoints presented in this package:Public APIs (Switcheo docs refers to Exchange APIs) - do not require authentication (message signing) that provide access to exchange history, statistics, state, and various other information about the exchange.Authenticated APIs (Switcheo docs refers to Trading APIs) - do require authentication and these endpoints include deposits, withdrawals, trading, and cancellation.Mainnet and Testnet EndpointsWhen developing an application it is best to do testing against the Testnet endpoints, these can be found at:URLUIhttps://beta.switcheo.exchangeAPIhttps://test-api.switcheo.networkFor live market data and trading on the mainnet the following enpoints should be used:URLUIhttps://switcheo.exchangeAPIhttps://api.switcheo.networkInstallationThis package is designed to be light weight and is not designed to create or store NEO wallets.  If this is required for your application please refer to theneo-python(https://github.com/CityOfZion/neo-python) project for your needs.RequirementsPython 3.5 or greaterEnvironment SetupPython InstallationSince this project requires Python 3.5 or greater this can be installed via the recommended methods found athttps://www.python.org/downloads/virtualenvDependency ManagementIt is also highly recommended to use thevirtualenvfunctionality allowing the developer to isolate dependencies between projects.  For more information the following link is worth reading:https://docs.python-guide.org/dev/virtualenvs/Docker ImageThis project also comes with a simple Docker file that can be used to execute the contents of this package inside of.  This package was developed inside of the Docker container so if there are any issues during use please report them.Install withpippython -m pip install switcheoInstall from PyPiThe easiest way to installswitcheoon your machine is to download it and install from PyPi usingpip. First, we recommend you to create a virtual environment in order to isolate this installation from your system directories and then install it as you normally would do:# create project dir
mkdir myproject
cd myproject

# create virtual environment and activate

python3.6 -m venv venv # this can also be python3 -m venv venv depending on your environment
source venv/bin/activate

(venv) pip install switcheoInstall from GitClone the repository athttps://github.com/KeithSSmith/switcheo-pythonand navigate into the project directory.
Make a Python 3 virtual environment and activate it viapython3.6 -m venv venv
source venv/bin/activateThen install the requirements viapip install -U setuptools pip wheel
pip install -e .Updating switcheo-python from GitIf you are updating switcheo-python withgit pull, make sure you also update the dependencies withpip install-rrequirements.txt.Public ClientInstantiate Classswitcheo_pub_client = PublicClient(blockchain=neo)Exchange API Statusswitcheo_pub_client.get_exchange_status()Exchange Time in Epoch Millisecondsswitcheo_pub_client.get_exchange_time()List Smart Contract Hashesswitcheo_pub_client.get_contracts()List Trade Pairsswitcheo_pub_client.get_pairs()
switcheo_pub_client.get_pairs(base="SWTH")List Orders for Address (ScriptHash)switcheo_pub_client.get_orders(address=neo_get_scripthash_from_address(address))List Contract Balance for Address (ScriptHash)switcheo_pub_client.get_balance(address=neo_get_scripthash_from_address(address))Tickersswitcheo_pub_client.get_candlesticks(pair="SWTH_NEO", start_time=round(time.time()) - 350000, end_time=round(time.time()), interval=360))
switcheo_pub_client.get_last_24_hours()
switcheo_pub_client.get_last_price()Offers on Order Bookswitcheo_pub_client.get_offers(pair="GAS_NEO")Executed Trades for a Given Pairswitcheo_pub_client.get_trades(pair="SWTH_NEO", limit=3)Authenticated ClientThe Switcheo docs go into extensive detail about how to authenticate messages (https://docs.switcheo.network/#authentication) on the NEO blockchain.  These complications have been abstracted to make it easier for the developer to use to allow for quicker development of their project.This also means it is no longer necessary to run bothcreateandexecuteportions of the authenticated client tasks since both are handled with the higher level functions listed below.Instantiate Classswitcheo_client = AuthenticatedClient(blockchain="neo")Deposit to Smart Contractswitcheo_client.deposit(asset=product_dict["SWTH"], amount=1, kp=kp)Withdrawal from Smart Contractswitcheo_client.withdrawal(asset=product_dict["SWTH"], amount=0.001, kp=kp)Place a Limit Orderswitcheo_client.order(kp=kp, pair="SWTH_NEO", side="buy", price=0.0002, amount=100, use_native_token=True, order_type="limit")Cancel an Open Orderswitcheo_client.cancel_order(order_id=order['id'], kp=kp)DonationsAccepted at Neo addressANwvg4giWPxrZeJtR3ro9TJf4dUHk5wjKe.