Skip to main content

ALP API - official python client for trading platform ALP.COM

Usage

Initialization

from alpcom_api import factories, cache

public_api = factories.get_public_api()
private_api = factories.get_private_api(
    key='** Your private_api Key **',
    secret='** Your private_api Secret **',
    # Optionally use cache to store temp token
    # otherwise it will be generated every time an instance of HTTPClient gets created
    # cache=cache.FileCache('/path/to/token.txt') 
)

Public data

import time
from alpcom_api import factories, dto

public_api = factories.get_public_api()

currency_list = public_api.currencies()
markets_list = public_api.pairs()
orderbook_btc_usdt = public_api.orderbook(pair='BTC_USDT')
tickers_list = public_api.tickers()
last_trades = public_api.trades(pair='BTC_USDT', limit=10)
candle_list = public_api.charts(
    pair='BTC_USDT',
    interval=dto.ChartInterval.DAY,
    since=int(time.time()) - 60 * 60 * 24 * 10  # last 10 days
)

Accounts API

from alpcom_api import factories, dto

private_api = factories.get_private_api(
    key='** Your private_api Key **',
    secret='** Your private_api Secret **',
)

# Get master account and sub-accounts
private_api.accounts().accounts(include_subaccounts=True)

# Get balances of all accounts
private_api.accounts().balances()

# Get fee info 
private_api.accounts().fees()

# Get own orders by pair
private_api.accounts().orders('ETH_USDT', open_only=True)

# Get trade history
private_api.accounts().trades('ETH_USDT')

# Get wallet motion history
private_api.accounts().history('USDT')

Trading API

from alpcom_api import factories, dto

private_api = factories.get_private_api(
    key='** Your private_api Key **',
    secret='** Your private_api Secret **',
)

# Place different order types
req_limit = dto.LimitOrderRequest(
    pair='ETH_USDT',
    order_side=dto.OrderSide.SELL,
    base_amount=0.05,
    limit_price=1800,
)
req_market = dto.MarketOrderRequest(
    pair='ETH_USDT',
    order_side=dto.OrderSide.SELL,
    base_amount=0.1 # base_amount or quote_amount
)
req_stop_limit = dto.StopLimitOrderRequest(
    pair='ETH_USDT',
    order_side=dto.OrderSide.SELL,
    stop_price=1800,
    stop_operator=dto.StopOperator.GTE,
    base_amount=0.05,
    limit_price=1700,
)

order1_id = private_api.trading().place_order(req_limit)
order2_id = private_api.trading().place_order(req_market)
order3_id = private_api.trading().place_order(req_stop_limit)

# Cancel one order by order id
status = private_api.trading().cancel_order(12312332)

# Cancel multiple orders by order ids
status_dict = private_api.trading().cancel_orders([12312332, 12312334, 12312338])

# Cancel multiple orders by pair
status_dict = private_api.trading().cancel_orders_of_pair('ETH_USDT')

# Cancel all open orders
status_dict = private_api.trading().cancel_all_orders()

Deposit API

from alpcom_api import factories

private_api = factories.get_private_api(
    key='** Your private_api Key **',
    secret='** Your private_api Secret **',
)

# get deposit methods (with attributes to make deposit)
methods = private_api.deposits().methods(currency='USDT')

# get deposit history
deposits = private_api.deposits().history(currency='USDT')

Withdraw API

from alpcom_api import factories, dto

private_api = factories.get_private_api(
    key='** Your private_api Key **',
    secret='** Your private_api Secret **',
)

# get withdraws methods
methods = private_api.withdraws().methods(currency='USDT')

# make withdraw request
req = dto.WithdrawRequest(
    amount=10.0,
    method=2,
    attributes={
        'address': '<my_dest_addr>',
        'memo': '<extra memo>'
    },
    client_order_id='order_123'
)
private_api.withdraws().create(req)

# get withdraws history
withdraws = private_api.withdraws().history(currency='USDT')

Margin API

from alpcom_api import factories, dto

private_api = factories.get_private_api(
    key='** Your private_api Key **',
    secret='** Your private_api Secret **',
)

# make margin transfer
req = dto.MarginTransferRequest(
    account_id=384457,
    wallet_type=dto.WalletType.MARGIN_CROSS,
    direction=dto.MarginDirection.ADD,
    amount=1,
    currency='ETH',
)

operation_id = private_api.margin().transfer(req)

# make borrow
req = dto.BorrowRequest(
    account_id=384457,
    borrow=1,
    currency='ETH',
    wallet_type=dto.WalletType.MARGIN_CROSS,
)

operation_id = private_api.margin().borrow(req)

# repay debt
req = dto.RepayRequest(
    account_id=384457,
    amount=0.03,
    currency='ETH',
    wallet_type=dto.WalletType.MARGIN_CROSS,
)

operation_id = private_api.margin().repay(req)

# close position
private_api.margin().close_position(account_id=384457, wallet_type=dto.WalletType.MARGIN_CROSS)

# Get loans
loans = private_api.margin().loans(cross_margin=True)

# Get transfer history
transfers = private_api.margin().transfers('ETH', start_time=None, end_time=None)

# Get borrow history
borrows = private_api.margin().borrows('ETH', start_time=None, end_time=None)

# Get repay history
repays = private_api.margin().repays('ETH', start_time=None, end_time=None)

# Get interest history
repays = private_api.margin().interests('ETH', start_time=None, end_time=None)

# Get liquidation history
repays = private_api.margin().liquidations('ETH', start_time=None, end_time=None)

Web Socket API

import asyncio
from pprint import pprint

from alpcom_api import ws, clients, cache
from alpcom_api.dto import ws as dto


class MyHandler(ws.Handler):
    def on_ticker(self, ticker: dto.Ticker):
        pprint(ticker)

    def on_trade(self, trade: dto.Trade):
        pprint(trade)

    def on_rate(self, rate: dto.Rate):
        pprint(rate)

    def on_diff(self, diff: dto.Diff):
        pprint(diff)

    def on_depth(self, depth: dto.Depth):
        pprint(depth)

    def on_wallet(self, wallet: dto.Wallet):
        pprint(wallet)

    def on_order(self, order: dto.Order):
        pprint(order)


async def main():
    cli = clients.ALPAuthClient(
        key='**API_KEY**',
        secret='**API_KEY**',
        token_cache=cache.FileCache('dev_token.txt')
    )

    async with ws.Client(handler=MyHandler()) as client:
        await client.auth(cli)
        await client.subscribe(ws.tps.tickers_all, ws.tps.trades_of('ETH_USDT'), ws.tps.diff_of('ETH_USDT'))
        await client.receive_messages()


asyncio.get_event_loop().run_until_complete(main())

Metadata

Release files for alpcom-api 1.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for alpcom-api 1.0.3
File Size Uploaded Provenance
alpcom_api-1.0.3.tar.gz 10.9 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for alpcom-api 1.0.3
File Interpreter ABI Platform
alpcom_api-1.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 23.9 kB

Release files / alpcom_api-1.0.3.tar.gz

Download URL alpcom_api-1.0.3.tar.gz
Size 10.9 kB
Tags Source
SHA-256 checksum
How to use checksums
651871ab0dee3cc130b18926f337ac58ce00990312d1770ed1137bc41463ae30
BLAKE2b-256 checksum
How to use checksums
fd2bc78309e7cf096aa10c2ca2b0d4a8065303dba6505270d36b2080aa8a1373
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.1

Release files / alpcom_api-1.0.3-py3-none-any.whl

Download URL alpcom_api-1.0.3-py3-none-any.whl
Size 13.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4c2051f68e3dfe4eeb32036b9fe945068de8dbd8da8621eda14715537b6f388a
BLAKE2b-256 checksum
How to use checksums
94fc7cb26f71784c78b6805f7871f3bd0684cb31a89aef0700864b955e5378c0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.1

Security for alpcom-api 1.0.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page