Skip to main content

The Official Shrimpy API Python Client

Project description

shrimpy-python

The official python library for the Shrimpy Developer API https://developers.shrimpy.io/docs. The library is currently only python3 compatible.

Installation

pip install shrimpy-python

Quick Start

All requests are synchronous. For a comprehensive API usage guide, please see https://developers.shrimpy.io/docs.

If you would like to use the async/await style similar to our Node.js library, consider using the asyncio python library to wrap the synchronous requests provided here.

import shrimpy

public_key = 'bea8edb348af226...'
secret_key = 'df84c39fb49026dcad9d99...'
client = shrimpy.ShrimpyApiClient(public_key, secret_key)
ticker = client.get_ticker('bittrex')

Public Endpoints

The clients for both the public and authenticated endpoints are identical. Please note that if you attempt to use the authenticated endpoints without keys, it will fail.

supported_exchanges = client.get_supported_exchanges()
exchange_assets = client.get_exchange_assets('bittrex')
trading_pairs = client.get_trading_pairs('bittrex')

Market Data Methods

ticker = client.get_ticker('bittrex')
orderbooks = client.get_orderbooks(
    'bittrex',  # exchange
    'XLM',      # base_symbol
    'BTC',      # quote_symbol
    10          # limit
)
candles = client.get_candles(
    'bittrex',  # exchange
    'XLM',      # base_trading_symbol
    'BTC',      # quote_trading_symbol
    '15m'       # interval
)

Authenticated Endpoints

As mentioned above, please use the provided Shrimpy API keys to access the authenticated endpoints. Endpoints such as user management require the master api key, while endpoints such as trading will work with either a master api key or a user api key.

User Management Methods

users = client.list_users()
user = client.get_user(
    '701e0d16-1e9e-42c9-b6a1-4cada1f395b8' # user_id
)
create_user_response = client.create_user(
    'mycustomname' # (optional) name
)
user_id = create_user_response['id']
client.name_user(
    'mycustomname' # name
)
client.enable_user(
    '701e0d16-1e9e-42c9-b6a1-4cada1f395b8' # user_id
)
client.disable_user(
    '701e0d16-1e9e-42c9-b6a1-4cada1f395b8' # user_id
)

User API Keys Methods

public_user_keys = client.get_api_keys(
    '701e0d16-1e9e-42c9-b6a1-4cada1f395b8' # user_id
)
user_api_keys = client.create_api_keys(
    '701e0d16-1e9e-42c9-b6a1-4cada1f395b8' # user_id
)
client.delete_api_keys(
    '701e0d16-1e9e-42c9-b6a1-4cada1f395b8',                            # user_id
    '51ac18b7d208f59b3c88acbb1ecefe6ba6be6ea4edc07e7a2450307ddc27ab80' # public_key
)
permissions = client.get_api_key_permissions(
    '701e0d16-1e9e-42c9-b6a1-4cada1f395b8',                            # user_id
    '51ac18b7d208f59b3c88acbb1ecefe6ba6be6ea4edc07e7a2450307ddc27ab80' # public_key
)
client.set_api_key_permissions(
    '701e0d16-1e9e-42c9-b6a1-4cada1f395b8',                             # user_id
    '51ac18b7d208f59b3c88acbb1ecefe6ba6be6ea4edc07e7a2450307ddc27ab80', # public_key
    True,                                                               # enable account methods
    False                                                               # enable trading methods
)

Account Methods

accounts = client.list_accounts(
    '701e0d16-1e9e-42c9-b6a1-4cada1f395b8' # user_id
)
account = client.get_account(
    '701e0d16-1e9e-42c9-b6a1-4cada1f395b8', # user_id
    123                                     # exchange_account_id
)
link_account_response = client.link_account(
    '701e0d16-1e9e-42c9-b6a1-4cada1f395b8',                             # user_id
    'binance',                                                          # exchange
    'GOelL5FT6TklPxAzICIQK25aqct52T2lHoKvtcwsFla5sbVXmeePqVJaoXmXI6Qd', # public_key (a.k.a. apiKey)
    'SelUuFq1sF2zGd97Lmfbb4ghITeziKo9IvM5NltjEdffatRN1N5vfHXIU6dsqRQw',  # private_key (a.k.a. secretKey
    'mypassphrase'                                                       # (optional)passphrase - required for exchanges with passphrases like CoinbasePro
)
account_id = link_account_response['id']
client.unlink_account(
    '701e0d16-1e9e-42c9-b6a1-4cada1f395b8', # user_id
    456                                     # account_id
)
ip_addresses = client.get_ip_whitelist_addresses(
    '701e0d16-1e9e-42c9-b6a1-4cada1f395b8' # user_id
)

Trading Methods

create_trade_response = client.create_trade(
    '701e0d16-1e9e-42c9-b6a1-4cada1f395b8', # user_id
    123,                                    # account_id
    'BTC',                                  # from_symbol
    'ETH',                                  # to_symbol
    '0.01'                                  # amount of from_symbol
)
trade_id = create_trade_response['id']
trade = client.get_trade_status(
    '701e0d16-1e9e-42c9-b6a1-4cada1f395b8', # user_id
    123,                                    # exchange_account_id
    '72dff099-54c0-4a32-b046-5c19d4f55758'  # trade_id
)
active_trades = client.list_active_trades(
    '701e0d16-1e9e-42c9-b6a1-4cada1f395b8', # user_id
    123,                                    # exchange_account_id
)

Balance Methods

balance = client.get_balance(
    '701e0d16-1e9e-42c9-b6a1-4cada1f395b8', # user_id
    123                                     # account_id
)
total_balance_history = client.get_total_balance_history(
    '701e0d16-1e9e-42c9-b6a1-4cada1f395b8', # user_id
    123                                     # account_id
)

Asset Management Methods

client.rebalance(
    '701e0d16-1e9e-42c9-b6a1-4cada1f395b8', # user_id
    123                                     # account_id
)
rebalance_period_hours = client.get_rebalance_period(
    '701e0d16-1e9e-42c9-b6a1-4cada1f395b8', # user_id
    123                                     # account_id
)
client.set_rebalance_period(
    '701e0d16-1e9e-42c9-b6a1-4cada1f395b8', # user_id
    123,                                    # account_id
    24                                      # rebalance_period in hours
)
strategy = client.get_strategy(
    '701e0d16-1e9e-42c9-b6a1-4cada1f395b8', # user_id
    123                                     # account_id
)
client.set_strategy(
    '701e0d16-1e9e-42c9-b6a1-4cada1f395b8',   # user_id
    123,                                      # account_id
    {
        'isDynamic': False,
        'allocations': [
            { 'symbol': 'BTC', 'percent': '50' },
            { 'symbol': 'ETH', 'percent': '50' }
        ]
    }                                         # strategy
)
client.clear_strategy(
    '701e0d16-1e9e-42c9-b6a1-4cada1f395b8',   # user_id
    123                                       # account_id
)
client.allocate(
    '701e0d16-1e9e-42c9-b6a1-4cada1f395b8',    # user_id
    123,                                       # account_id
    {
        'isDynamic': False,
        'allocations': [
            { 'symbol': 'USDT', 'percent': '100' }
        ]
    }                                          # strategy
)

Limit Order Methods

place_limit_order_response = client.place_limit_order(
    '701e0d16-1e9e-42c9-b6a1-4cada1f395b8', # user_id
    123,                                    # account_id
    'BTC',                                  # base_symbol
    'ETH',                                  # quote_symbol
    '0.01',                                 # quantity of base_symbol
    '0.026',                                # price
    'SELL',                                 # side
    'IOC',                                  # time_in_force
)
limit_order_id = place_limit_order_response['id']
order = client.get_limit_order_status(
    '701e0d16-1e9e-42c9-b6a1-4cada1f395b8', # user_id
    123,                                    # account_id
    '8c2a9401-eb5b-48eb-9ae2-e9e02c174058'  # order_id
)
orders = client.list_open_orders(
    '701e0d16-1e9e-42c9-b6a1-4cada1f395b8', # user_id
    123                                     # account_id
)
order = client.cancel_limit_order(
    '701e0d16-1e9e-42c9-b6a1-4cada1f395b8', # user_id
    123,                                    # account_id
    '8c2a9401-eb5b-48eb-9ae2-e9e02c174058'  # order_id
)

Analytics Methods

backtest_assets = client.get_backtest_assets(
    'kucoin' # exchange
)
backtest_results = client.run_backtest(
    'binance',                                       # exchange
    10,                                              # rebalance_period in hours
    '0.1',                                           # fee in percent
    '2018-05-19T00:00:00.000Z',                      # start_time
    '2018-11-02T00:00:00.000Z',                      # end_time
    '5000',                                          # initial_value in USD
    [
        { 'symbol': "BTC", 'percent': '50' },
        { 'symbol': "ETH", 'percent': '50' }
    ]                                                # allocations
)

Insight Methods

asset_dominance = client.get_asset_dominance()
asset_popularity = client.get_asset_popularity()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

shrimpy_python-0.0.4.tar.gz (10.1 kB view hashes)

Uploaded Source

Built Distribution

shrimpy_python-0.0.4-py3-none-any.whl (8.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page