-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
751 additions
and
177 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,23 @@ | ||
Copyright (c) 2016 | ||
The MIT License | ||
|
||
Copyright (c) 2017 | ||
Felipe Aránguiz <[email protected]> | ||
Sebastián Aránguiz <[email protected]> | ||
Sebastián Aránguiz <[email protected]> | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,50 @@ | ||
# Trading API Wrappers | ||
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT) | ||
[![Updates](https://pyup.io/repos/github/delta575/trading-api-wrappers/shield.svg)](https://pyup.io/repos/github/delta575/trading-api-wrappers/) | ||
[![Python 3](https://pyup.io/repos/github/delta575/trading-api-wrappers/python-3-shield.svg)](https://pyup.io/repos/github/delta575/trading-api-wrappers/) | ||
|
||
Trading API Wrappers. | ||
Tested on Python 3.5 | ||
Tested on Python 3.6 | ||
|
||
- [Bitfinex](https://www.bitfinex.com) | ||
- [Kraken](http://www.kraken.com) | ||
- [Kraken](https://www.kraken.com) | ||
- [SURBTC](https://www.surbtc.com) | ||
- [CoinDesk](http://www.coindesk.com) | ||
- [CoinDesk](https://www.coindesk.com) | ||
- [CryptoMKT](https://www.cryptomkt.com) | ||
|
||
## Dev setup | ||
|
||
Install the libs | ||
|
||
pip install -r requirements.txt | ||
```bash | ||
$ pip install -r requirements.txt | ||
``` | ||
|
||
Rename .env.example > .env | ||
Rename `.env.example` to `.env` | ||
|
||
## Installation | ||
|
||
pip install git+https://github.com/delta575/trading-api-wrappers.git | ||
```bash | ||
$ pip install git+https://github.com/delta575/trading-api-wrappers.git | ||
``` | ||
|
||
## Usage | ||
|
||
### Bitfinex | ||
|
||
Public API: | ||
|
||
from trading_api_wrappers import Bitfinex | ||
client = Bitfinex.Public() | ||
```python | ||
from trading_api_wrappers import Bitfinex | ||
client = Bitfinex.Public() | ||
``` | ||
|
||
Authenticated API: | ||
|
||
from trading_api_wrappers import Bitfinex | ||
client = Bitfinex.Auth(API_KEY, API_SECRET) | ||
```python | ||
from trading_api_wrappers import Bitfinex | ||
client = Bitfinex.Auth(API_KEY, API_SECRET) | ||
``` | ||
|
||
Bitfinex API Doc: | ||
https://bitfinex.readme.io/v1/docs | ||
|
@@ -41,13 +53,17 @@ https://bitfinex.readme.io/v1/docs | |
|
||
Public API: | ||
|
||
from trading_api_wrappers import Kraken | ||
client = Kraken.Public() | ||
```python | ||
from trading_api_wrappers import Kraken | ||
client = Kraken.Public() | ||
``` | ||
|
||
Authenticated API: | ||
|
||
from trading_api_wrappers import Kraken | ||
client = Kraken.Auth(API_KEY, API_SECRET) | ||
```python | ||
from trading_api_wrappers import Kraken | ||
client = Kraken.Auth(API_KEY, API_SECRET) | ||
``` | ||
|
||
Kraken API Doc: | ||
https://www.kraken.com/help/api | ||
|
@@ -56,41 +72,66 @@ https://www.kraken.com/help/api | |
|
||
Public API: | ||
|
||
from trading_api_wrappers import SURBTC | ||
client = SURBTC.Public() | ||
```python | ||
from trading_api_wrappers import SURBTC | ||
client = SURBTC.Public() | ||
``` | ||
|
||
Authenticated API: | ||
|
||
from trading_api_wrappers import SURBTC | ||
client = SURBTC.Auth(API_KEY, API_SECRET) | ||
```python | ||
from trading_api_wrappers import SURBTC | ||
client = SURBTC.Auth(API_KEY, API_SECRET) | ||
``` | ||
|
||
SURBTC API Doc: | ||
http://api.surbtc.com/ | ||
https://api.surbtc.com | ||
|
||
### CoinDesk | ||
|
||
from trading_api_wrappers import CoinDesk | ||
client = CoinDesk() | ||
|
||
```python | ||
from trading_api_wrappers import CoinDesk | ||
client = CoinDesk() | ||
``` | ||
Coindesk API Doc: | ||
http://www.coindesk.com/api | ||
https://www.coindesk.com/api | ||
|
||
### CryptoMKT | ||
|
||
Public API: | ||
|
||
from trading_api_wrappers import CryptoMKT | ||
client = CryptoMKT.Public() | ||
```python | ||
from trading_api_wrappers import CryptoMKT | ||
client = CryptoMKT.Public() | ||
``` | ||
|
||
Authenticated API: | ||
|
||
```python | ||
from trading_api_wrappers import CryptoMKT | ||
client = CryptoMKT.Auth(API_KEY, API_SECRET) | ||
``` | ||
|
||
CryptoMKT API Doc: | ||
https://developers.cryptomkt.com/ | ||
https://developers.cryptomkt.com | ||
|
||
## Licence | ||
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT) | ||
|
||
The MIT License | ||
|
||
Copyright (c) 2017 Felipe Aránguiz | Sebastián Aránguiz | ||
Copyright © 2017 | ||
[Felipe Aránguiz](mailto://[email protected]) | [Sebastián Aránguiz](mailto://[email protected]) | ||
|
||
See [LICENSE](LICENSE) | ||
|
||
## Based on | ||
## Donations | ||
|
||
Bitcoin: | ||
|
||
186kDw9LFcPvup17YSrWZbFqdZzELUFad3 | ||
|
||
Ether: | ||
|
||
[scottjbarr/bitfinex](https://github.com/scottjbarr/bitfinex) | ||
0xeF38fA6c0a37A1BdB60CADd7f6e71F351F6d2583 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
coverage==4.4.2 | ||
pytest==3.2.3 | ||
pytest==3.2.5 | ||
python-decouple==3.1 | ||
requests==2.18.4 | ||
tox==2.9.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import unittest | ||
|
||
# local | ||
from trading_api_wrappers import CoinMarketCap | ||
|
||
|
||
class CoinMarketCapTest(unittest.TestCase): | ||
|
||
def setUp(self): | ||
self.client = CoinMarketCap() | ||
|
||
def test_instantiate_client(self): | ||
self.assertIsInstance(self.client, CoinMarketCap) | ||
|
||
# Test Ticker ------------------------------------------------------------- | ||
def test_ticker_list(self): | ||
ticker = self.client.ticker() | ||
self.assertGreater(len(ticker), 1) | ||
self.assertIn('symbol', ticker[0].keys()) | ||
|
||
def test_ticker_list_convert(self): | ||
ticker = self.client.ticker(convert='clp') | ||
self.assertGreater(len(ticker), 1) | ||
self.assertIn('price_clp', ticker[0].keys()) | ||
|
||
def test_ticker_currency(self): | ||
ticker = self.client.ticker('btc') | ||
self.assertIn('symbol', ticker.keys()) | ||
|
||
def test_ticker_currency_convert(self): | ||
ticker = self.client.ticker('btc', 'clp') | ||
self.assertIn('price_clp', ticker.keys()) | ||
|
||
def test_ticker_bad_currency(self): | ||
self.assertRaises(KeyError, lambda: self.client.ticker('clp')) | ||
|
||
# Test Ticker ------------------------------------------------------------- | ||
def test_price_currency(self): | ||
price = self.client.price('btc') | ||
self.assertIsInstance(price, float) | ||
|
||
def test_price_currency_convert(self): | ||
price = self.client.price('btc', 'clp') | ||
self.assertIsInstance(price, float) | ||
|
||
def test_price_bad_currency(self): | ||
self.assertRaises(KeyError, lambda: self.client.price('clp')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
import unittest | ||
from datetime import datetime, timedelta | ||
|
||
# pip | ||
from decouple import config | ||
|
||
# local | ||
from trading_api_wrappers import CryptoMKT, errors | ||
from trading_api_wrappers.cryptomkt import models | ||
|
||
POST_ORDERS = False # Only post orders if explicitly set | ||
|
||
API_KEY = config('CRYPTOMKT_API_KEY') | ||
API_SECRET = config('CRYPTOMKT_API_SECRET') | ||
MARKET_ID = CryptoMKT.Market.ETH_CLP | ||
CURRENCY = CryptoMKT.Currency.ETH | ||
|
||
|
||
class CryptoMKTPublicTest(unittest.TestCase): | ||
|
||
def setUp(self): | ||
self.client = CryptoMKT.Public() | ||
|
||
def test_instantiate_client(self): | ||
self.assertIsInstance(self.client, CryptoMKT.Public) | ||
|
||
def test_markets(self): | ||
markets = self.client.markets() | ||
self.assertEqual(len(markets), len(CryptoMKT.Market)) | ||
|
||
def test_ticker(self): | ||
ticker = self.client.ticker(MARKET_ID) | ||
self.assertIsInstance(ticker, models.Ticker) | ||
|
||
def test_order_book(self): | ||
order_book = self.client.order_book( | ||
MARKET_ID, CryptoMKT.OrderType.BUY) | ||
self.assertIsInstance(order_book, models.OrderBook) | ||
|
||
def test_trades(self): | ||
page, limit = 2, 10 | ||
trades = self.client.trades(MARKET_ID, page=page, limit=limit) | ||
self.assertIsInstance(trades, models.Trades) | ||
self.assertEqual(trades.pagination.page, page) | ||
self.assertEqual(len(trades.trades), limit) | ||
|
||
def test_trades_dates(self): | ||
end = datetime.now() - timedelta(days=1) | ||
trades = self.client.trades(MARKET_ID, end=end) | ||
self.assertIsInstance(trades, models.Trades) | ||
self.assertLess(trades.trades[0].timestamp, end) | ||
|
||
|
||
class CryptoMKTAuthTest(unittest.TestCase): | ||
|
||
def setUp(self): | ||
self.client = CryptoMKT.Auth(API_KEY, API_SECRET) | ||
|
||
def test_instantiate_client(self): | ||
self.assertIsInstance(self.client, CryptoMKT.Auth) | ||
|
||
def test_balance(self): | ||
balance = self.client.balance() | ||
self.assertIsInstance(balance, models.Balance) | ||
|
||
def test_wallet_balance(self): | ||
wallet_balance = self.client.wallet_balance(CURRENCY) | ||
self.assertIsInstance(wallet_balance, models.WalletBalance) | ||
self.assertEquals(wallet_balance.wallet, CURRENCY.value) | ||
|
||
def test_active_orders(self): | ||
page, limit = 2, 10 | ||
active_orders = self.client.active_orders( | ||
MARKET_ID, page=page, limit=limit) | ||
self.assertIsInstance(active_orders, models.Orders) | ||
if active_orders.orders: | ||
self.assertEqual(active_orders.pagination.page, page) | ||
|
||
def test_executed_orders(self): | ||
page, limit = 2, 10 | ||
executed_orders = self.client.executed_orders( | ||
MARKET_ID, page=page, limit=limit) | ||
self.assertIsInstance(executed_orders, models.Orders) | ||
if executed_orders.orders: | ||
self.assertEqual(executed_orders.pagination.page, page) | ||
self.assertEqual(len(executed_orders.orders), limit) | ||
|
||
def test_order_status(self): | ||
orders = self.client.executed_orders( | ||
MARKET_ID, page=1, limit=1).orders | ||
first_order = orders[0] | ||
single_order = self.client.order_status(first_order.id) | ||
self.assertIsInstance(single_order, models.Order) | ||
|
||
@unittest.skipUnless(POST_ORDERS, 'Only run if explicitly set') | ||
def test_create_order_cancel_order(self): | ||
# New order | ||
new_order = self.client.create_order( | ||
MARKET_ID, CryptoMKT.OrderType.SELL, | ||
amount=0.001, price=1000000) | ||
# Cancel order | ||
canceled_order = self.client.cancel_order(new_order.id) | ||
# Assertions | ||
self.assertIsInstance(new_order, models.Order) | ||
self.assertIsInstance(canceled_order, models.Order) | ||
|
||
|
||
class CRYPTOMKTAuthTestBadApi(unittest.TestCase): | ||
|
||
def setUp(self): | ||
self.client = CryptoMKT.Auth('BAD_KEY', 'BAD_SECRET') | ||
|
||
def test_instantiate_client(self): | ||
self.assertIsInstance(self.client, CryptoMKT.Auth) | ||
|
||
def test_key_secret(self): | ||
self.assertRaises(ValueError, lambda: CryptoMKT.Auth()) | ||
|
||
def test_balance_returns_error(self): | ||
self.assertRaises(errors.InvalidResponse, | ||
lambda: self.client.balance()) |
Oops, something went wrong.