Package: hitbtcapi
hitbtcapiREST API Client for HitBTCFeaturesConvenient methods for making API calls using keyword argumentsAutomatic classification into form-data or query parametersAutomatic packing into JSONNear 100% test coverage.Tab-completable methods and attributes when usingIPython.Installationhitbtcapiis available onPYPI. Install withpip:$pipinstallhitbtcapior witheasy_install:$easy_installhitbtcapiThe library is currently tested against Python versions 2.7 and 3.4+.API ReferenceThe official documentation can be found on theHitBTC API reference page. You can alsoexplore the APIusing Swagger UI.PrerequisitesThe first thing you need to do is toSign Up with HitBTC.Next, you need to obtain anAPI Keyand anAPI Secret. If you’re writing code for your own HitBTC account, you can create API keys onHitBTC API Settingspage. You can create multiple API keys with different permissions for your applications.NOTE: Make sure to enable appropriate permissions for the API key (some require email confirmation).Getting startedCreate aClientobject for interacting with the API:fromhitbtcapi.clientimportClientapi_key='your api key'api_secret='your api secret'client=Client(api_key,api_secret)Error handlingAll errors occurring during interaction with the API will be raised as exceptions. These exceptions will be subclasses ofhitbtcapi.errors.HitBTCError. When the error involves an API request and/or response, the error will be a subclass ofhitbtcapi.errors.APIError, and include more information about the failed interaction. For full details of error responses, please refer to therelevant API documentation.ErrorHTTP Status codeInvalidRequestError400AuthenticationError401TwoFactorRequiredError402InvalidScopeError403NotFoundError404ValidationError422RateLimitExceededError429InternalServerError500ServiceUnavailableError503GatewayTimeoutError504UsageI’ve done my best to make the code clean, commented, and understandable; however it may not be exhaustive. For more details, please refer to theHitBTC API official documentationor theAPI Explorer.IN SHORTUse args for URI pathsUse kwargs for formData or query parametersPublic API (Market Data)Get available currencies, tokens, ICO etc.client.get_currencies()client.get_currency('BTC')Get currency symbols (currency pairs) traded on HitBTC exchange.client.get_symbols()client.get_symbol('ETHBTC')Get ticker informationclient.get_tickers()client.get_ticker('ETHBTC')Get trades for a specific symbolclient.get_trades('ETHBTC')client.get_trades('ETHBTC',sort='ASC',limit=10)# Caution: from is a python keyword,# so cannot be used as a keyword argument to a function,# need to use dict insteadimportdatetimetoday=datetime.datetime.now()yesterday=today-datetime.timedelta(days=1)params={'from':today.isoformat(),'to':yesterday.isoformat()}client.get_trades('ETHBTC',sort='ASC',limit=10,**params)Get orderbook (electronic list of buy and sell orders) for a specific symbol, organized by price levelclient.get_orderbook('ETHBTC')client.get_orderbook('ETHBTC',limit=10)Get candles for a specific symbol (used forOHLC)client.get_candles('ETHBTC')client.get_candles('ETHBTC',limit=10,period='H1')TradingGet trading balance for your accountclient.get_trading_balance()Get a list of active orders or a specific active orderclient.get_active_orders()client.get_active_orders(symbol='ETHBTC')client.get_active_order('840450210')client.get_active_order('840450210',wait=30000)Create a new orderclient.create_order(symbol='ETHBTC',side='buy',quantity='0.063',price='0.046016')# required parametersclient.create_order(symbol='ETHBTC',side='buy',quantity='0.063',price='0.046016',type='stopLimit',stopPrice='0.073')Update an existing orderclient.update_order('840450210',symbol='ETHBTC',side='buy',quantity='0.063',price='0.046016',timeInForce='GDC')Cancel all open orders or a specific open orderclient.cancel_open_orders()client.cancel_open_orders(symbol='ETHBTC')client.cancel_order('840450210')Get personal trading commission rateclient.get_trading_fee('ETHBTC')Trading HistoryGet order historyclient.get_order_history()client.get_order_history(symbol='ETHBTC',limit=10)# Caution: from is a python keyword,# so cannot be used as a keyword argument to a function,# need to use dict insteadimportdatetimetoday=datetime.datetime.now()yesterday=today-datetime.timedelta(days=1)params={'from':today.isoformat(),'to':yesterday.isoformat()}client.get_order_history(symbol='ETHBTC',limit=10,**params)Get trade historyclient.get_trade_history()client.get_trade_history(symbol='ETHBTC',limit=10)# Caution: from is a python keyword,# so cannot be used as a keyword argument to a function,# need to use dict insteadimportdatetimetoday=datetime.datetime.now()yesterday=today-datetime.timedelta(days=1)params={'from':today.isoformat(),'to':yesterday.isoformat()}client.get_trade_history(symbol='ETHBTC',limit=10,**params)Get trades by orderclient.get_trades_by_orderid('840450210')Account InformationGet account balanceclient.get_account_balance()Get deposit address for the cryptocurrencyclient.get_deposit_address('BTC')Add deposit address for the cryptocurrencyclient.add_deposit_address('BTC')Withdraw cryptocurrencyclient.withdraw('BTC',amount='0.01',address='sOmE-cuRR-encY-addR-essH')# required parametersclient.withdraw('BTC',amount='0.01',address='sOmE-cuRR-encY-addR-essH',networkFee='0.0003',includeFee=True,autoCommit=False)Commit cryptocurrency withdrawalclient.commit_withdrawal('d2ce578f-647d-4fa0-b1aa-4a27e5ee597b')Rollback cryptocurrency withdrawalclient.rollback_withdrawal('d2ce578f-647d-4fa0-b1aa-4a27e5ee597b')Transfer money between trading and accountclient.transfer_to_trading(currency='BTC',amount='0.023',type='bankToExchange')Get all transactions or by idclient.get_account_transactions()client.get_account_transactions(currency='BTC',sort='ASC',limit=10)# Caution: from is a python keyword,# so cannot be used as a keyword argument to a function,# need to use dict insteadimportdatetimetoday=datetime.datetime.now()yesterday=today-datetime.timedelta(days=1)params={'from':today.isoformat(),'to':yesterday.isoformat()}client.get_trade_history(currency='BTC',sort='ASC',limit=10,**params)client.get_account_transaction('d2ce578f-647d-4fa0-b1aa-4a27e5ee597b')Testing / ContributingAny contribution is welcome! The process is simple:Fork this repoMake your changesRun the tests (for multiple versions: preferred)Submit a pull request.Testing for your current python versionTests are run vianosetest. To run the tests, clone the repository and then:# Install the required dependencies$pipinstall-rrequirements.txt$pipinstall-rtest-requirements.txt# Run the tests$maketestsIf you’d also like to generate an HTML coverage report (useful for figuring out which lines of code are actually being tested), make sure the requirements are installed and then run:$makecoverageTesting for multiple python versionsI am usingtoxto run the test suite against multiple versions of Python. Tox requires the appropriate Python interpreters to run the tests in different environments. I would recommend usingpyenvfor this.However, the process is a little unintuitive becausetoxdoes not seem to work with multiple versions of python (installed viapyenv) when inside apyenvvirtual environment. So, first deactivate your pyenv virtual environment:$(hitbtcapi-venv)pyenvdeactivateand then installtoxwith pip or easy_install:$pipinstalltox# or$easy_installtoxInstall python versions which you want to test:$pyenvinstall2.7.14$pyenvinstall3.5.0$pyenvinstall3.6.0and so forth. Now, in your project directory:# all versions which are in tox.ini file$pyenvlocal2.7.143.5.03.6.0# run the tests for all the above versions$toxLicenseThis project is licensed under the MIT License. See the LICENSE file for more details.AcknowledgementsHitBTC REST API example