Package: python-infinity
python-infinityThis is a Python3 connector for Infinity exchange's REST APIs and WebSocket.Please note that the python-infinity package is anunofficialproject and should be used at your own risk.
It isNOTaffiliated with the Infinity exchange and doesNOTprovide financial or investment advice.Table of ContentsOverviewFeaturesDocumentationQuick StartExample UsageDisclaimerContactOverviewThepython-infinitypackage is a Python3 connector that allows you to interact with the Infinity Exchange.
The package utilizes threads to handle concurrent execution of REST API requests and WebSocket subscriptions.
This allows for efficient handling of multiple requests and real-time data streams without blocking the main execution thread.The connector provides aREST clientthat allows you to make requests to all the available REST API endpoints of the Infinity exchange.
You can perform actions such as retrieving user information, and more.
It also includes aWebSocket clientthat enables you to subscribe to real-time data streams from the Infinity exchange.
You can subscribe to channels like orderbook data, user order data etc.To access private endpoints and perform actions on behalf of a user, the package includes aLoginClientclass.
This class handles the login process and manages the authentication using aJWT access token.
You can create an instance of the LoginClient class and pass it to the REST or WebSocket client for private session usage.This project is undergoing active development, ensuring that new changes to the Infinity API will
be promptly integrated.For feedback or suggestions, please reach out via one of the contact methods specified inContact.FeaturesREST API HandlingWebSocket HandlingLogin ClientThread-based ExecutionException Handling and ReconnectionRelease VersionChangelog0.0.7Stable release for testnet (recommended)DocumentationFor more detailed information, please refer to theInfinity Exchange Docs.Quick StartPrerequisitespython-infinityis tested on python version:3.11to3.11.6.
Earlier or Later versions of Python might work, but they have not been thoroughly tested and could potentially conflict with the external web3 library.python-infinityutilizes web3, threading, websocket-client and requests for its methods, alongside other
built-in modules.
As the package utilizes the web3 library, we suggest to use version>=6.0.0here.InstallationTo get started with thepython-infinitypackage, you can install it manually or viaPyPIwithpip:pip install python-infinityKnown IssuesThegetargspecError (web3 version <= 5.31.4)If you are using web3 version<=5.31.4You may encounter the following error:ImportError: cannot import name 'getargspec' from 'inspect'This error message is the result of a slight conflict between the various package versions we need.We will continue to look for a more permanent solution to this. But for the time being, please do the following quick fix to resolve this issue.You can update web3 version:>=6.0.0Or apply fix onexpressions.pyFind.../site-packages/parsimonious/expressions.pyand double-clickexpressions.pyto open itInsideexpressions.pyfile, changeinspect import getargspectoinspect import getfullargspecError should be resolved, please run the code againExample UsageTo be able to interact with private endpoints, an ethereum EOA account (wallet address) and the corresponding private
key isrequired.
We suggest to not include those information in your source code directly but alternatively store them in environment
variables.
Again, please note that the python-infinity package is anunofficialproject and should be used at your own risk.JWT access tokenhandling is managed in this package for authentication. For interacting with private endpoints and private websocket, a login is
required on the Infinity exchange side.
If you are planning to interact with any private endpoints, please create an instance of the LoginClient class and parse
it into the corresponding client (RestClient or WebSocketClient).
If you want to only interact with public endpoints and public websocket, the login step2. Create an instance of the LoginClient
classcan be skipped.1. Import the required modules# Infinity Exchange Login clientfrominfinity.loginimportLoginClient# Infinity Exchange REST clientfrominfinity.rest_clientimportRestClient# Infinity Exchange Websocket clientfrominfinity.websocket_clientimportWebSocketClient2. Create an instance of the LoginClient class (Optional)The login process will be carried out in the initializer of the LoginClient class.
If you only interact with public session, this part can be skipped.
Please refer to the documentation for information on how to use other parameters.frominfinity.loginimportLoginClientasInfinityLogininfinity_login=InfinityLogin(rest_url="Infinity Exchange REST URL",chain_id="Chain ID",account_address=account_address,# user wallet addressprivate_key=private_key)# user private key3. REST / WEBSOCKET client3.1 REST clientCreate a REST client instance, parse the infinity_login instance from2. Create an instance of the LoginClient
classfor private endpoint usage.
Please refer to the documentation for information on how to use other parameters.frominfinity.rest_clientimportRestClientasInfinityRestClient# =============================================================================# For public REST# =============================================================================infinity_public_rest=InfinityRestClient(rest_url="Infinity Exchange REST URL")# =============================================================================# For public and private REST# =============================================================================infinity_rest=InfinityRestClient(rest_url="Infinity Exchange REST URL",login=infinity_login)# Infinity Exchange Login ClientUsage example:# Public endpoint method examplemarket_info_floating_rate=infinity_rest.get_floating_rate(instrument_id="ETH-SPOT")# Private endpoint method exampleuser_info=infinity_rest.get_user_info()3.2 WEBSOCKET clientCreate a WEBSOCKET client instance, parse the infinity_login instance from2. Create an instance of the
LoginClient classfor private channel usage.Please refer to the documentation for information on how to use other parameters.frominfinity.websocket_clientimportWebSocketClientasInfinityWebsocketClient# =============================================================================# For public WEBSOCKET channel# =============================================================================infinity_public_ws=InfinityWebsocketClient(ws_url="Infinity Exchange Websocket URL",auto_reconnect_retries=3)# default is 0 which would disable reconnection retriesinfinity_public_ws.run_all()infinity_public_ws.disconnect_all_ws_connection()# disconnect all the websocket connection# =============================================================================# For private and public WEBSOCKET channel# =============================================================================infinity_ws=InfinityWebsocketClient(ws_url="Infinity Exchange Websocket URL",login=infinity_login,# Infinity Exchange Login Clientauto_reconnect_retries=3)infinity_ws.run_all()infinity_ws.disconnect_all_ws_connection()# disconnect all the websocket connectionUsage example - channel subscription / unsubscription:# =============================================================================# For public WEBSOCKET channel, e.g. orderbook data, recent trades# =============================================================================# Subscribing - recent tradesinfinity_ws.subscribe_public_trades(instrument_id="USDC-SPOT")# Unsubscribing - recent tradesinfinity_ws.unsubscribe_public_trades(instrument_id="USDC-SPOT")# Subscribing - orderbook datainfinity_ws.subscribe_orderbook(instrument_id="WBTC-2023-12-29")# Unsubscribing - orderbook datainfinity_ws.unsubscribe_orderbook(instrument_id="WBTC-2023-12-29")# =============================================================================# For private WEBSOCKET channel, e.g. user order data, user trade data# =============================================================================# Subscribing - user order datainfinity_ws.subscribe_user_order(instrument_id="USDC-2023-11-03")# Unsubscribing - user order datainfinity_ws.unsubscribe_user_order(instrument_id="USDC-2023-11-03")# Subscribing - user trade datainfinity_ws.subscribe_user_trade(instrument_id="DAI-SPOT")# Unsubscribing - user trade datainfinity_ws.unsubscribe_user_trade(instrument_id="DAI-SPOT")Usage example - callbacks for extracting relevant datawhileTrue:# =============================================================================# For public WEBSOCKET channel, e.g. orderbook data, recent trades# =============================================================================public_trade=infinity_ws.get_received_data(channel="recentTrades")orderbook=infinity_ws.get_received_data(channel="orderBook")# =============================================================================# For private WEBSOCKET channel, e.g. user order data, user trade data# =============================================================================user_order=infinity_ws.get_received_data(channel="userOrder")user_trade=infinity_ws.get_received_data(channel="userTrade")Infinity Websocket package also provides functions to be overridden for processing websocket data stream.defprocess_orderbook_data(self,orderbook:dict)->None:pass# please refer to websocket client's process_orderbook_datadefprocess_public_trade(self,public_trade:dict)->None:pass# please refer to websocket client's process_public_tradedefprocess_user_order(self,user_order:dict)->None:pass# please refer to websocket client's process_user_orderdefprocess_user_trade(self,user_trade:dict)->None:pass# please refer to websocket client's process_user_tradeError CodesInfinity Exchange uses the following error codes:Error codeDescription1Success2Permission Denied9Unexpected Error1000Pemission Denied1001Validation Error1002Operation Failed9999Unexpected Error10000Invalid Wallet (Deposit)10001Invalid Token (Deposit)10010Invalid Wallet (Withdraw)10011Invalid Token (Withdraw)10012Not Enough Funds to Withdraw10020Not Enough Tokens To Liquidate10021No Liquidation Steps Found10022Liquidation Swap FailedOrder API error codes tableError codeDescription102INVALID_ACCOUNT104TIMEOUT107MINIMUM_QUANTITY_NOT_REACH108NO_ORDER109ORDER_DONE_OR_CANCELLED110TRADE_SERVER_PARSE111TRADE_SERVER_ORDER_BOOK_ERROR112TRADE_SERVER_DB113TRADE_SERVER_DB_CONNECTION114MARKET_EXPIRED115RATE_TRANSACTION_ERROR120QUANTITY_STEP_NOT_MATCH121NO_TWAP122INVALID_DEDUPLICATE_STRING191ORDER_AUTO_CANCELLED192ORDER_MANUALLY_CANCELLEDOrdersOrder SidesBooleanSide0 (False)Lend1 (True)BorrowOrder Status CodesStatus CodeStatusDescription0STATUS_PENDINGPending (i.e. Not yet sent to market)1STATUS_ONBOOKOn Book (i.e. Live order in market)10STATUS_DONEDone (i.e. Fully executed)11STATUS_MANUALLY_CANCELLEDManually cancelled12STATUS_AUTO_CANCELLEDAuto cancelled13STATUS_PARTIALLY_FILLEDPartially Filled14STATUS_EXPIREDMarket expired99STATUS_ERRORErrorOrder TypesType CodeMeaning1Market Order2Limit OrderResponse CodesCodeDescription200OK403Forbidden500Internal Server Error or Invalid Response503Service UnavailableToken IDsCodeNameToken IDQuantity StepMinimum QuantityRate StepETHETH10.000010.0010.0001USDTUSDT20.0110.0001USDCUSDC30.0110.0001DAIDAI40.0110.0001WBTCWrapped BTC50.0000010.00010.0001Token Valuation ProtocolsCodeProtocol0No protocol / Not relevant1Aave2Uniswap3Compound4CurveTransaction TypesCodeMeaning1Borrow2Lend3Repay4Unlend5Interest6Transfer In (Between Wallets)7Transfer Out (Between Wallets)8External Transfer In9External Transfer Out10Trade11System Airdrop12LP Fee13Swap Secondary Token14Withdrawal Fee15Transaction Fee16LP Setup In17LP Setup Out18LP Unwind In19LP Unwind Out20Liquidation UnlendDisclaimerThis is an unofficial Python project (the "Package") and made available for informational purpose only and does not
constitute financial, investment or trading advice.
You acknowledge and agree to comply with the Terms of service athttps://www.infinity.exchange/terms-conditions. If you
do not agree, please do not use this package.
Any unauthorised use of the Package is strictly prohibited.ContactFor support, suggestions or feedback please reach out to us via the following email addresspydevbuzz@gmail.com