Skip to main content

DeGate Public SDK Connector Python

PyPI version Python 3.6 License: MIT

This is a lightweight library that works as a connector to DeGate public SDK

  • Supported APIs:
    • Spot
    • Spot Websocket Market Stream
    • Spot User Data Stream
  • Inclusion of examples
  • Customizable base URL
  • Response metadata can be displayed

Installation

pip install degate-connector

SDK

Usage examples:

from degate.spot import Spot as Client

ETH = {
    "id": 0,
    "symbol": "ETH",
}
USDC = {
    "id": 8,
    "symbol": "USDC",
}
client = Client(tokens=[ETH,USDC])


# Get server timestamp
print(client.time())

# Get klines of ETHUSDC at 1m interval
print(client.klines("ETHUSDC", "1m"))
# Get last 10 klines of ETHUSDC at 1h interval
print(client.klines("ETHUSDC", "1h", limit=10))

# accountAddress、assetPrivateKey、accountId are required for user data endpoints
client = Client(accountAddress='<account_address>',assetPrivateKey='<DeGate AssetPrivateKey>',accountId='<account_id>',tokens=[ETH,USDC])
# Get account and balance information
print(client.account())

# Post a new order
params = {
    'symbol': 'ETHUSDC',
    'side': 'SELL',
    'type': 'LIMIT',
    'quantity': 0.1,
    'price': 9500
}

response = client.newOrder(**params)
print(response)

Please find examples folder to check for more endpoints.

Testnet

Spot Testnet is available, it can be used to test.

To use testnet:

from degate.spot import Spot as Client

client = Client(baseUrl='https://testnet-backend.degate.com')
print(client.time())

Response Metadata

The DeGate API server provides weight usages in the headers of each response. You can display them by initializing the client with show_header=True:

from degate.spot import Spot as Client
client = Client(show_header=True)
print(client.time())

returns:

{'data': {'serverTime': 1587990847650}, 'header': {'Context-Type': 'application/json;charset=utf-8', ...}}

If ClientError is received, it'll display full response meta information.

Display logs

Setting the log level to DEBUG will log the request URL, payload and response text.

Error

There are 2 types of error returned from the library:

  • degate.error.ClientError
    • This is thrown when server returns 4XX, it's an issue from client side.
    • It has 4 properties:
      • status_code - HTTP status code
      • error_code - Server's error code, e.g. -1102
      • error_message - Server's error message, e.g. Unknown order sent.
      • header - Full response header.
  • degate.error.ServerError
    • This is thrown when server returns 5XX, it's an issue from server side.

Websocket

import time
from degate.websocket.spot.websocket_client import SpotWebsocketClient as WsClient

def message_handler(message):
    print(message)

ETH = {
    "id": 0,
    "symbol": "ETH",
}
USDC = {
    "id": 8,
    "symbol": "USDC",
}
wsClient = WsClient(tokens=[ETH,USDC])
wsClient.start()

wsClient.subscribeTicker(
    symbol="ETHUSDC",
    id=1,
    callback=message_handler,
)
time.sleep(300)
wsClient.stop()

More websocket examples are available in the examples folder

Testnet

from degate.websocket.spot.websocket_client import SpotWebsocketClient as WsClient

wsClient = WsClient(websocketBaseUrl='wss://testnet-ws.degate.com')

Metadata

Release files for degate-connector 1.6.2

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

Source distribution (sdist)

Source distribution for degate-connector 1.6.2
File Size Uploaded Provenance Actions
degate-connector-1.6.2.tar.gz 33.7 MB Without provenance Details for degate-connector-1.6.2.tar.gz

Release files / degate-connector-1.6.2.tar.gz

Download URL degate-connector-1.6.2.tar.gz
Size 33.7 MB
Tags Source
SHA-256 checksum
How to use checksums
0ff98b983ffeb7e182420ff9da9259057c9ce7d6a1a72491ecfb33a16ff4f071
BLAKE2b-256 checksum
How to use checksums
f273f4c2499267fc3737932038efeb39c2e6e3cd5b7d7f0f4d2e7b0cf710485b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.13

Security for degate-connector 1.6.2

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