Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

various cleanup #104

Merged
merged 1 commit into from
Dec 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Installation
Example Usage for Bittrex API

```python
from bittrex import Bittrex
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does from bittrex import Bittrex not work? I thought the import in the __init__.py would make it work. Seems like a nicer way to import versus from bittrex.bittrex import Bittrex

from bittrex.bittrex import Bittrex, API_V2_0

my_bittrex = Bittrex(None, None, api_version=API_V2_0) # or defaulting to v1.1 as Bittrex(None, None)
my_bittrex.get_markets()
Expand All @@ -34,7 +34,7 @@ Make sure you save the secret, as it will not be visible
after navigating away from the page.

```python
from bittrex import Bittrex
from bittrex.bittrex import *

my_bittrex = Bittrex("<my_api_key>", "<my_api_secret>", api_version="<API_V1_1> or <API_V2_0>")

Expand Down
2 changes: 1 addition & 1 deletion bittrex/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .bittrex import *
from .bittrex import * # noqa
26 changes: 14 additions & 12 deletions bittrex/bittrex.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@

try:
from urllib import urlencode
from urlparse import urljoin
except ImportError:
from urllib.parse import urlencode
from urllib.parse import urljoin

try:
from Crypto.Cipher import AES
Expand Down Expand Up @@ -154,7 +152,7 @@ def _api_query(self, protection=None, path_dict=None, options=None):

return self.dispatch(request_url, apisign)

except:
except Exception:
return {
'success': False,
'message': 'NO_API_RESPONSE',
Expand All @@ -167,7 +165,7 @@ def get_markets(self):
at Bittrex along with other meta data.

1.1 Endpoint: /public/getmarkets
2.0 Endpoint: /pub/Markets/GetMarkets
2.0 NO Equivalent
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not so sure that these endpoints are permanently gone... but they are definitely broken now. If they come back we can re-enable this functionality.


Example ::
{'success': True,
Expand All @@ -192,7 +190,6 @@ def get_markets(self):
"""
return self._api_query(path_dict={
API_V1_1: '/public/getmarkets',
API_V2_0: '/pub/Markets/GetMarkets'
}, protection=PROTECTION_PUB)

def get_currencies(self):
Expand Down Expand Up @@ -295,7 +292,7 @@ def get_market_history(self, market):

Endpoint:
1.1 /market/getmarkethistory
2.0 /pub/Market/GetMarketHistory
2.0 NO Equivalent

Example ::
{'success': True,
Expand All @@ -318,7 +315,6 @@ def get_market_history(self, market):
"""
return self._api_query(path_dict={
API_V1_1: '/public/getmarkethistory',
API_V2_0: '/pub/Market/GetMarketHistory'
}, options={'market': market, 'marketname': market}, protection=PROTECTION_PUB)

def buy_limit(self, market, quantity, rate):
Expand Down Expand Up @@ -514,18 +510,24 @@ def get_order_history(self, market=None):

Endpoint:
1.1 /account/getorderhistory
2.0 /key/orders/getorderhistory
2.0 /key/orders/getorderhistory or /key/market/GetOrderHistory

:param market: optional a string literal for the market (ie. BTC-LTC).
If omitted, will return for all markets
:type market: str
:return: order history in JSON
:rtype : dict
"""
return self._api_query(path_dict={
API_V1_1: '/account/getorderhistory',
API_V2_0: '/key/orders/getorderhistory'
}, options={'market': market, 'marketname': market} if market else None, protection=PROTECTION_PRV)
if market:
return self._api_query(path_dict={
API_V1_1: '/account/getorderhistory',
API_V2_0: '/key/market/GetOrderHistory'
}, options={'market': market, 'marketname': market}, protection=PROTECTION_PRV)
else:
return self._api_query(path_dict={
API_V1_1: '/account/getorderhistory',
API_V2_0: '/key/orders/getorderhistory'
}, protection=PROTECTION_PRV)

def get_order(self, uuid):
"""
Expand Down
29 changes: 9 additions & 20 deletions bittrex/test/bittrex_tests.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import unittest
import json
import os
from bittrex.bittrex import Bittrex, API_V2_0, API_V1_1, BUY_ORDERBOOK, TICKINTERVAL_ONEMIN

IS_CI_ENV = True if 'IN_CI' in os.environ else False
try:
open("secrets.json").close()
IS_CI_ENV = False
except Exception:
IS_CI_ENV = True


def test_basic_response(unit_test, result, method_name):
Expand Down Expand Up @@ -83,7 +86,7 @@ def test_get_candles(self):

def test_get_latest_candle(self):
self.assertRaisesRegexp(Exception, 'method call not available', self.bittrex.get_latest_candle, market='BTC-LTC',
tick_interval=TICKINTERVAL_ONEMIN)
tick_interval=TICKINTERVAL_ONEMIN)


class TestBittrexV20PublicAPI(unittest.TestCase):
Expand All @@ -98,23 +101,17 @@ def setUp(self):
def test_handles_none_key_or_secret(self):
self.bittrex = Bittrex(None, None, api_version=API_V2_0)
# could call any public method here
actual = self.bittrex.get_markets()
actual = self.bittrex.get_market_summaries()
self.assertTrue(actual['success'], "failed with None key and None secret")

self.bittrex = Bittrex("123", None, api_version=API_V2_0)
actual = self.bittrex.get_markets()
actual = self.bittrex.get_market_summaries()
self.assertTrue(actual['success'], "failed with None secret")

self.bittrex = Bittrex(None, "123", api_version=API_V2_0)
actual = self.bittrex.get_markets()
actual = self.bittrex.get_market_summaries()
self.assertTrue(actual['success'], "failed with None key")

def test_get_markets(self):
actual = self.bittrex.get_markets()
test_basic_response(self, actual, "get_markets")
self.assertTrue(isinstance(actual['result'], list), "result is not a list")
self.assertTrue(len(actual['result']) > 0, "result list is 0-length")

def test_get_currencies(self):
actual = self.bittrex.get_currencies()
test_basic_response(self, actual, "get_currencies")
Expand All @@ -135,14 +132,6 @@ def test_get_orderbook(self):
actual = self.bittrex.get_orderbook('BTC-LTC')
test_basic_response(self, actual, "get_orderbook")

def test_get_market_history(self):
actual = self.bittrex.get_market_history('BTC-LTC')
test_basic_response(self, actual, "get_market_history")

def test_list_markets_by_currency(self):
actual = self.bittrex.list_markets_by_currency('LTC')
self.assertListEqual(['BTC-LTC', 'ETH-LTC', 'USDT-LTC'], actual)

def test_get_wallet_health(self):
actual = self.bittrex.get_wallet_health()
test_basic_response(self, actual, "get_wallet_health")
Expand Down
2 changes: 1 addition & 1 deletion setup.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(name='python-bittrex',
version='0.2.1',
url = "https://github.com/ericsomdahl/python-bittrex",
url="https://github.com/ericsomdahl/python-bittrex",
packages=['bittrex'],
modules=['bittrex'],
install_requires=['requests'],
Expand Down