Skip to main content

CoinGate Python SDK (API v2)

Project description

CoinGate Python SDK (API v2)

StaticCheckAndTestCI

This SDK provides conveniet way to communicate between CoinGate API v2 and your Python code.

Requirements

Python 3.7+

Installing

pip install coingate-python

Dependencies

This library requires the following packages to work properly:

Getting started

You can sign up for a CoinGate account at https://coingate.com for production and https://sandbox.coingate.com for testing (sandbox).

Please note, that for Sandbox you must generate separate API credentials on https://sandbox.coingate.com. API credentials generated on https://coingate.com will not work for Sandbox mode.

Usage of SDK looks like:

>>> from coingate import CoinGate
>>> client = CoinGate("YOUR_API_TOKEN")

In order, to use sandbox mode, you need to pass second parameter as True

>>> from coingate import CoinGate
>>> client = CoinGate("YOUR_API_TOKEN", True)

If you planning to use only Public API endpoints, you can initialize client without parameters

>>> from coingate import CoinGate
>>> client = CoinGate()

Payment Gateway API

Create Order

Create order at CoinGate and redirect shopper to invoice (payment_url). This is private API endpoint and requires authentication.

>>> client.order.create(Decimal('10'), 'EUR', 'EUR')
NewOrder(
    id=1,
    status='new',
    do_not_convert=False,
    price_currency='EUR',
    price_ammount=Decimal('10'),
    lightning_network=False,
    receive_currency='EUR',
    receive_amount=Decimal('10'),
    created_at=datetime(2022, 10, 10, 12, 23, 22),
    order_id='',
    payment_url='',
    underpaid_amount=Decimal('0.000543'),
    overpaid_amount=Decimal('0.000543'),
    is_refundable=True,
    token='token'
)

Checkout

Placing created order with pre-selected payment currency (BTC, LTC, ETH, etc). Display payment_address and pay_amount for shopper or redirect to payment_url. Can be used to white-label invoices. This is private API endpoint and requires authentication.

>>> client.order.checkout(123, 'EUR')
Checkout(
    pay_currency='EUR',
    pay_amount=Decimal('10'),
    expire_at=datetime(2022, 10, 10, 12, 23, 22),
    payment_address='addy',
    platform=CheckoutPlatform(id=1, title='title', id_name='id_name')
)

Get Order

Retrieves a specific order. This is private API endpoint and requires authentication.

>>> client.order.get(123)
Order(
    id=123,
    status='new',
    do_not_convert=False,
    price_currency='EUR',
    price_ammount=Decimal('10'),
    lightning_network=False,
    receive_currency='EUR',
    receive_amount=Decimal('10'),
    created_at=datetime(2022, 10, 10, 12, 23, 22),
    order_id='',
    payment_url='',
    underpaid_amount=Decimal('0.000543'),
    overpaid_amount=Decimal('0.000543'),
    is_refundable=True,
    orderable_type='order',
    orderable_id=1,
    payment_address='addy'
)

List Orders

Retrieving information of all placed orders. This is private API endpoint and requires authentication.

>>> client.order.get_all(123)
PaginatedOrders(
    current_page=1,
    per_page=100,
    total_orders=500,
    total_pages=5,
    orders=[
        Order(
            id=123,
            status='new',
            do_not_convert=False,
            price_currency='EUR',
            price_ammount=Decimal('10'),
            lightning_network=False,
            receive_currency='EUR',
            receive_amount=Decimal('10'),
            created_at=datetime(2022, 10, 10, 12, 23, 22),
            order_id='',
            payment_url='',
            underpaid_amount=Decimal('0.000543'),
            overpaid_amount=Decimal('0.000543'),
            is_refundable=True,
            orderable_type='order',
            orderable_id=1,
            payment_address='addy'
        )
    ]
)

Refunds API

Create Order Refund

Creates a refund for an order. This is private API endpoint and requires authentication.

>>> client.refund.create_order_refund(1, Decimal('10'), 'addy', 1, 1, 'refund', 'email@email.com', 'id')
Refund(
    id=1,
    request_amount=Decimal('10'),
    refund_amount=Decimal('10'),
    address='addy',
    status='new',
    memo=None,
    created_at=datetime(2022, 10, 10, 12, 23, 22),
    order=RefundOrder(id=1),
    transactions=['tx_id'],
    ledger_account=RefundLedgerAccount(id=1, currency=RefundLedgerAccountCurrency(id=1, title='Bitcoin', symbol='BTC'))
)

Get Order Refund

Retrieves a specific refund for an order. This is private API endpoint and requires authentication.

>>> client.refund.get_order_refund(1, 1)
Refund(
    id=1,
    request_amount=Decimal('10'),
    refund_amount=Decimal('10'),
    address='addy',
    status='new',
    memo=None,
    created_at=datetime(2022, 10, 10, 12, 23, 22),
    order=RefundOrder(id=1),
    transactions=['tx_id'],
    ledger_account=RefundLedgerAccount(id=1, currency=RefundLedgerAccountCurrency(id=1, title='Bitcoin', symbol='BTC'))
)

Get Order Refunds

Retrieves all refunds for an order. This is private API endpoint and requires authentication.

>>> client.refund.get_order_refunds(1)
PaginatedRefunds(
    current_page=1,
    per_page=100,
    total_refunds=500,
    total_pages=5,
    refunds=[
        PaginatedRefundsRefund(
            id=1,
            request_amount=Decimal('10'),
            refund_amount=Decimal('10'),
            crypto_address='addy',
            crypto_address_memo=None,
            status='new',
            order=RefundOrder(id=1),
            refund_currency=RefundCurrency(
                id=1,
                title='Bitcoin',
                symbol='BTC',
                platform=RefundCurrencyPlatform(id=1, title='platform')
            )
        )
    ]
)

Get Refunds

Retrieves all refunds. This is private API endpoint and requires authentication.

>>> client.refund.get_refunds()
PaginatedRefunds(
    current_page=1,
    per_page=100,
    total_refunds=500,
    total_pages=5,
    refunds=[
        PaginatedRefundsRefund(
            id=1,
            request_amount=Decimal('10'),
            refund_amount=Decimal('10'),
            crypto_address='addy',
            crypto_address_memo=None,
            status='new',
            order=RefundOrder(id=1),
            refund_currency=RefundCurrency(
                id=1,
                title='Bitcoin',
                symbol='BTC',
                platform=RefundCurrencyPlatform(id=1, title='platform')
            )
        )
    ]
)

Public API

Get Exchange Rate

Current exchange rate for any two currencies, fiat or crypto. This endpoint is public, authentication is not required.

# Get exchange rate for Merchants
>>> client.public.get_exchange_rate_for_merchant(from_currency="EUR", to_currency="BTC")
Decimal('0.0000472')

# Get exchange rate for Traders
>>> client.public.get_exchange_rate_for_trader(kind="buy", from_currency="EUR", to_currency="ETH")
Decimal('0.00063213')

List Exchange Rates

Current CoinGate exchange rates for Merchants and Traders. This endpoint is public, authentication is not required.

# Get all exchange rates for Merchants and Traders
>>> client.public.get_all_exchange_rates()
ExchangeRates(
    merchant={
        'BTC': {
            'EUR': Decimal('7449.99'),
            'USD': Decimal('9139.34'),
            'ETH': Decimal('13.18044023')
        },
        'EUR': {
            'BTC': '0.00013351',
            'USD': '1.2317',
            'ETH': '0.00175954'
        }
    }
    trader=ExchangeTrader(
        buy={
            'BTC': {
                'EUR': Decimal('7449.99'),
                'USD': Decimal('9139.34'),
                'ETH': Decimal('13.18044023')
            },
            'EUR': {
                'BTC': '0.00013351',
                'USD': '1.2317',
                'ETH': '0.00175954'
            }
        }
        sell={
            'BTC': {
                'EUR': Decimal('7449.99'),
                'USD': Decimal('9139.34'),
                'ETH': Decimal('13.18044023')
            },
            'EUR': {
                'BTC': '0.00013351',
                'USD': '1.2317',
                'ETH': '0.00175954'
            }
        }
    )
)

# Get all exchange rates for Merchants
>>> client.public.get_merchant_exchange_rates()
{
    'BTC': {
        'EUR': Decimal('7449.99'),
        'USD': Decimal('9139.34'),
        'ETH': Decimal('13.18044023')
    },
    'EUR': {
        'BTC': '0.00013351',
        'USD': '1.2317',
        'ETH': '0.00175954'
    }
}

# Get all exchange rates for Traders
>>> client.public.get_trader_exchange_rates()
ExchangeTrader(
    buy={
        'BTC': {
            'EUR': Decimal('7449.99'),
            'USD': Decimal('9139.34'),
            'ETH': Decimal('13.18044023')
        },
        'EUR': {
            'BTC': '0.00013351',
            'USD': '1.2317',
            'ETH': '0.00175954'
        }
    }
    sell={
        'BTC': {
            'EUR': Decimal('7449.99'),
            'USD': Decimal('9139.34'),
            'ETH': Decimal('13.18044023')
        },
        'EUR': {
            'BTC': '0.00013351',
            'USD': '1.2317',
            'ETH': '0.00175954'
        }
    }
)

Ping

A health check endpoint for CoinGate API. This endpoint is public, authentication is not required.

>>> client.public.ping()
Ping(ping='pong', time='2017-12-13T19:07:18+00:00')

IP Addresses

Get IP addresses of CoinGate servers

>>> client.public.get_ip_addresses(separator="|")
'52.28.22.118|35.156.68.160'

Get Currencies

Retrieves all currencies.

>>> client.public.get_currencies(native=True, enabled=True, merchant_pay=True, merchant_receive=True, kind="crypto")
[
    Currency(id=1,
        title='Bitcoin',
        kind='crypto',
        native=True,
        disabled=False,
        disabled_message=None,
        merchant=CurrencyMerchant(price=True, pay=True, receive=True),
        platforms=[
            CurrencyPlatform(id=8, id_name='bitcoin', title='Bitcoin' enabled=True)
        ]
    ),
    Currency(
        id=2,
        title='Euro',
        kind='fiat',
        symbol='EUR',
        native=True,
        disabled=False,
        disabled_message=None,
        merchant=CurrencyMerchant(price=True, pay=False, receive=True),
        platforms=None
    ),
    Currency(
        id=3,
        title='United States dollar',
        kind='fiat',
        symbol='USD',
        native=True,
        disabled=False,
        disabled_message=None,
        merchant=CurrencyMerchant(price=True, pay=False, receive=True),
        platforms=None
    ),
    Currency(
        id=4,
        title='British Pound',
        kind='fiat',
        symbol='GBP',
        native=True,
        disabled=False,
        disabled_message=None,
        merchant=CurrencyMerchant(price=True, pay=False, receive=True),
        platforms=None
    ),
    Currency(
        id=5,
        title='Ethereum',
        kind='crypto',
        symbol='ETH',
        native=True,
        disabled=False,
        disabled_message=None,
        merchant=CurrencyMerchant(price=True, pay=True, receive=True),
        platforms=[
            CurrencyPlatform(id=2, id_name='binance_chain', title='Binance Chain (BEP2)', enabled=True),
            CurrencyPlatform(id=7, id_name='ethereum', title='Ethereum', enabled=True)
        ]
    )
]

Platforms

Get all platforms

>>> client.public.get_platforms(enabled=True)
[
    Platform(
        id=1,
        title='Ethereum (ERC20)',
        id_name='ethereum',
        disabled=False,
        disabled_message=None,
        currencies=[
            PlatformCurrency(id=50, title='Ethereum', symbol='ETH', enabled=True),
            PlatformCurrency(id=61, title='DAI', symbol='DAI', enabled=True),
            PlatformCurrency(id=71, title='Basic Attention Token', symbol='BAT', enabled=True)
        ]
    ),
    Platform(
        id=2,
        title='Binance Chain (BEP2)',
        id_name='binance_chain',
        disabled=False,
        disabled_message=None,
        currencies=[
            PlatformCurrency(id=50, title='Ethereum', symbol='ETH', enabled=True)
            PlatformCurrency(id=91, title='Binance Coin', symbol='BNB', enabled=True)
        ]
    )
]

Custom Request Timeout

To modify request timeout time, you need to call method which will change it.

>>> from coingate import CoinGate
>>> client = CoinGate("YOUR_API_TOKEN", True)
>>> client.set_timeout(10)

Setting API Key after initialization

If you decided to initialize client without API Key and you need to do it later, you can call method which will update auth headers.

>>> from coingate import Coingate
>>> client = CoinGate()
>>> client.public.ping()
Ping(ping='pong', time='2017-12-13T19:07:18+00:00')
>>> client.set_api_key('YOUR_API_KEY')

Attention plugin developers

Are you writing a plugin that integrates CoinGate and embeds our library? Then please use the setAppInfo function to identify your plugin. For example:

>>> from coingate import Coingate
>>> coingate.set_app_info("MyAwesomePlugin", "1.0.0")

The method should be called once, before any request is sent to the API. The second parameter is optional.

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

coingate-client-1.0.0.tar.gz (15.3 kB view details)

Uploaded Source

Built Distribution

coingate_client-1.0.0-py3-none-any.whl (15.0 kB view details)

Uploaded Python 3

File details

Details for the file coingate-client-1.0.0.tar.gz.

File metadata

  • Download URL: coingate-client-1.0.0.tar.gz
  • Upload date:
  • Size: 15.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.15 CPython/3.10.1 Linux/5.13.0-44-generic

File hashes

Hashes for coingate-client-1.0.0.tar.gz
Algorithm Hash digest
SHA256 c046ab83cd7c45e54d09a82b1b6b24e271e4f2305e700d602286ec3c13b0ed62
MD5 93e83d7993daf934840d7b6ccbe0d3e1
BLAKE2b-256 24034bbc033f7599cbd94559ba1b9fc4d6503d5ff338f066cdc5369cfdabfa78

See more details on using hashes here.

File details

Details for the file coingate_client-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: coingate_client-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 15.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.15 CPython/3.10.1 Linux/5.13.0-44-generic

File hashes

Hashes for coingate_client-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7d87cfb975a79083e8f3e33a02b8aa77ce4df85f47f85f8043cfd3694c9cf7b3
MD5 23e4095240c3bc6648f78e9c7fe71ee6
BLAKE2b-256 85e8fb7d60e84b134245db63cd25cfc443dbc41b70058b1aebe1fd8f3d747ee1

See more details on using hashes here.

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