# DeGate Public SDK Connector Python
[](https://pypi.python.org/pypi/degate-connector)
[](https://www.python.org/downloads/release/python-360/)
[](https://opensource.org/licenses/MIT)
This is a lightweight library that works as a connector to [DeGate public SDK](https://api-docs.degate.com/spot)
- Supported APIs:
- Spot
- Spot Websocket Market Stream
- Spot User Data Stream
- Inclusion of examples
- Customizable base URL
- Response metadata can be displayed
## Installation
```bash
pip install degate-connector
```
## SDK
Usage examples:
```python
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](https://testnet.degate.com/) is available, it can be used to test.
To use testnet:
```python
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`:
```python
from degate.spot import Spot as Client
client = Client(show_header=True)
print(client.time())
```
returns:
```python
{'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
```python
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
```python
from degate.websocket.spot.websocket_client import SpotWebsocketClient as WsClient
wsClient = WsClient(websocketBaseUrl='wss://testnet-ws.degate.com')
```
Raw data
{
"_id": null,
"home_page": "https://github.com/degatedev/degate-sdk-python.git",
"name": "degate-connector",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": "",
"keywords": "degate,Public SDK",
"author": "DeGate",
"author_email": "",
"download_url": "https://files.pythonhosted.org/packages/f2/73/f4c2499267fc3737932038efeb39c2e6e3cd5b7d7f0f4d2e7b0cf710485b/degate-connector-1.6.2.tar.gz",
"platform": null,
"description": "# DeGate Public SDK Connector Python\n[](https://pypi.python.org/pypi/degate-connector)\n[](https://www.python.org/downloads/release/python-360/)\n[](https://opensource.org/licenses/MIT)\n\nThis is a lightweight library that works as a connector to [DeGate public SDK](https://api-docs.degate.com/spot)\n\n- Supported APIs:\n - Spot\n - Spot Websocket Market Stream\n - Spot User Data Stream\n- Inclusion of examples\n- Customizable base URL\n- Response metadata can be displayed\n\n## Installation\n\n```bash\npip install degate-connector\n```\n\n## SDK\nUsage examples:\n```python\nfrom degate.spot import Spot as Client\n\nETH = {\n \"id\": 0,\n \"symbol\": \"ETH\",\n}\nUSDC = {\n \"id\": 8,\n \"symbol\": \"USDC\",\n}\nclient = Client(tokens=[ETH,USDC])\n\n\n# Get server timestamp\nprint(client.time())\n\n# Get klines of ETHUSDC at 1m interval\nprint(client.klines(\"ETHUSDC\", \"1m\"))\n# Get last 10 klines of ETHUSDC at 1h interval\nprint(client.klines(\"ETHUSDC\", \"1h\", limit=10))\n\n# accountAddress\u3001assetPrivateKey\u3001accountId are required for user data endpoints\nclient = Client(accountAddress='<account_address>',assetPrivateKey='<DeGate AssetPrivateKey>',accountId='<account_id>',tokens=[ETH,USDC])\n# Get account and balance information\nprint(client.account())\n\n# Post a new order\nparams = {\n 'symbol': 'ETHUSDC',\n 'side': 'SELL',\n 'type': 'LIMIT',\n 'quantity': 0.1,\n 'price': 9500\n}\n\nresponse = client.newOrder(**params)\nprint(response)\n```\nPlease find `examples` folder to check for more endpoints.\n\n### Testnet\n[Spot Testnet](https://testnet.degate.com/) is available, it can be used to test.\n\nTo use testnet:\n```python\nfrom degate.spot import Spot as Client\n\nclient = Client(baseUrl='https://testnet-backend.degate.com')\nprint(client.time())\n```\n\n### Response Metadata\nThe DeGate API server provides weight usages in the headers of each response.\nYou can display them by initializing the client with `show_header=True`:\n\n```python\nfrom degate.spot import Spot as Client\nclient = Client(show_header=True)\nprint(client.time())\n```\n\nreturns:\n\n```python\n{'data': {'serverTime': 1587990847650}, 'header': {'Context-Type': 'application/json;charset=utf-8', ...}}\n```\n\nIf `ClientError` is received, it'll display full response meta information.\n\n### Display logs\n\nSetting the log level to `DEBUG` will log the request URL, payload and response text.\n\n### Error\n\nThere are 2 types of error returned from the library:\n- `degate.error.ClientError`\n - This is thrown when server returns `4XX`, it's an issue from client side.\n - It has 4 properties:\n - `status_code` - HTTP status code\n - `error_code` - Server's error code, e.g. `-1102`\n - `error_message` - Server's error message, e.g. `Unknown order sent.`\n - `header` - Full response header. \n- `degate.error.ServerError`\n - This is thrown when server returns `5XX`, it's an issue from server side.\n\n## Websocket\n```python\nimport time\nfrom degate.websocket.spot.websocket_client import SpotWebsocketClient as WsClient\n\ndef message_handler(message):\n print(message)\n\nETH = {\n \"id\": 0,\n \"symbol\": \"ETH\",\n}\nUSDC = {\n \"id\": 8,\n \"symbol\": \"USDC\",\n}\nwsClient = WsClient(tokens=[ETH,USDC])\nwsClient.start()\n\nwsClient.subscribeTicker(\n symbol=\"ETHUSDC\",\n id=1,\n callback=message_handler,\n)\ntime.sleep(300)\nwsClient.stop()\n```\nMore websocket examples are available in the `examples` folder\n\n### Testnet\n```python\nfrom degate.websocket.spot.websocket_client import SpotWebsocketClient as WsClient\n\nwsClient = WsClient(websocketBaseUrl='wss://testnet-ws.degate.com')\n```\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "This is a lightweight library that works as a connector to DeGate public SDK.",
"version": "1.6.2",
"project_urls": {
"Homepage": "https://github.com/degatedev/degate-sdk-python.git"
},
"split_keywords": [
"degate",
"public sdk"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "f273f4c2499267fc3737932038efeb39c2e6e3cd5b7d7f0f4d2e7b0cf710485b",
"md5": "48902d79edc6f487acca3b8fcf7b7847",
"sha256": "0ff98b983ffeb7e182420ff9da9259057c9ce7d6a1a72491ecfb33a16ff4f071"
},
"downloads": -1,
"filename": "degate-connector-1.6.2.tar.gz",
"has_sig": false,
"md5_digest": "48902d79edc6f487acca3b8fcf7b7847",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 33656986,
"upload_time": "2024-03-15T05:35:50",
"upload_time_iso_8601": "2024-03-15T05:35:50.276957Z",
"url": "https://files.pythonhosted.org/packages/f2/73/f4c2499267fc3737932038efeb39c2e6e3cd5b7d7f0f4d2e7b0cf710485b/degate-connector-1.6.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-03-15 05:35:50",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "degatedev",
"github_project": "degate-sdk-python",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "degate-connector"
}