-
Notifications
You must be signed in to change notification settings - Fork 4
Authenticated Channels
poloniex-sdk edited this page Sep 22, 2022
·
1 revision
WS APIs to access private channels
import asyncio
import os
from polosdk import WsClientAuthenticated
api_key = os.environ['POLO_API_KEY']
api_secret = os.environ['POLO_API_SECRET']
async def ws_authenticated_example():
def on_message(msg):
print(msg)
def on_error(err):
print(err)
ws_client_authenticated = WsClientAuthenticated(on_message, on_error=on_error)
await ws_client_authenticated.connect(api_key, api_secret)
def main():
asyncio.run(ws_authenticated_example())
if __name__ == '__main__':
main()
Real time information about client’s orders. There are three types of events: "place", "trade", and "canceled". Supports 5 connections per user.
Stream Response Field | Data Type | Description |
---|---|---|
symbol | String | symbol name |
type | String | MARKET, LIMIT, LIMIT_MAKER, STOP_LOSS_LIMIT, TAKE_PROFIT_LIMIT |
quantity | String | number of base units for this order |
orderId | String | order id |
tradeFee | String | fee amount for the trade |
clientOrderId | String | user specified id |
accountType | String | SPOT |
feeCurrency | String | fee currency name |
eventType | String | place, trade, canceled |
source | String | WEB, APP, API, SMART, UNKNOWN |
side | String | BUY, SELL |
filledQuantity | String | base units filled in this order |
filledAmount | String | quote units filled in this order |
matchRole | String | MAKER, TAKER |
state | String | NEW, PARTIALLY_FILLED, FILLED, PENDING_CANCEL, PARTIALLY_CANCELED, CANCELED, REJECTED, EXPIRED, FAILED |
tradeTime | Long | time the trade was executed |
tradeAmount | String | number of quote units for a trade |
orderAmount | String | number of quote units for this order |
createTime | Long | time the record was created |
price | String | set price of the order |
tradeQty | String | number of base units for a trade |
tradePrice | String | price of the trade |
tradeId | String | id of the trade |
ts | Long | time the record was pushed |
Example:
# --> Request
await ws_client_authenticated.subscribe(['orders'], ['all'])
# <-- Receipt Confirmation
{
"channel": "orders",
"event": "subscribe"
}
# <-- Stream
{
"channel": "orders",
"data": [
{
"symbol": "BTC_USDT",
"type": "LIMIT",
"quantity": "1",
"orderId": "32471407854219264",
"tradeFee": "0",
"clientOrderId": "",
"accountType": "SPOT",
"feeCurrency": "",
"eventType": "place",
"source": "API",
"side": "BUY",
"filledQuantity": "0",
"filledAmount": "0",
"matchRole": "MAKER",
"state": "NEW",
"tradeTime": 0,
"tradeAmount": "0",
"orderAmount": "0",
"createTime": 1648708186922,
"price": "47112.1",
"tradeQty": "0",
"tradePrice": "0",
"tradeId": "0",
"ts": 1648708187469
}
]
}
Real time information about all of client’s balance(s) updates. The "Symbols” field in a request does not do anything for balances (it is ignored). There are 7 different types of events: "place_order", "canceled_order","match_order", "transfer_in", "transfer_out", "deposit","withdraw"
Stream Response Field | Data Type | Description |
---|---|---|
changeTime | Long | time the change was executed |
accountId | String | account id where the change is taking place |
eventType | String | event type |
available | String | currency amount available |
currency | String | currency name |
id | Long | id of the asset update |
userId | Long | user id |
hold | String | currency amount on hold |
ts | Long | time the record was pushed |
Example:
# --> Request
await ws_client_authenticated.subscribe(['balances'])
# <-- Receipt Confirmation
{
"channel": "balances",
"event": "subscribe"
}
# <-- Stream
{
"channel": "balances",
"data": [{
"changeTime": 1657312008411,
"accountId": "1234",
"eventType": "place_order",
"available": "9999999983.668",
"currency": "BTC",
"id": 60018450912695040,
"userId": 12345,
"hold": "16.332",
"ts": 1657312008443
}]
}
# --> Request
await ws_client_authenticated.subscribe(['orders', 'balances'], ['all'])
# <-- Receipt Confirmation
{
"channel": "orders",
"event": "subscribe",
"symbols": ["all"]
}
# <-- Receipt Confirmation
{
"channel": "balances",
"event": "subscribe"
}
# <-- Stream
{
"channel":"orders",
"data":[
{
"symbol":"LINK_USDC",
"type":"LIMIT",
"quantity":"10",
"orderId":"32482887660077056",
"tradeFee":"0",
"clientOrderId":"4436176",
"accountType":"SPOT",
"feeCurrency":"",
"eventType":"place",
"source":"API",
"side":"SELL",
"filledQuantity":"0",
"filledAmount":"0",
"state":"NEW",
"tradeTime":0,
"tradeAmount":"0",
"orderAmount":"0",
"createTime":1648710923921,
"price":"3",
"tradeQty":"0",
"tradePrice":"0",
"tradeId":"0",
"ts":1648710923948
}
]
}
# <-- Stream (continued)
{
"channel": "balances",
"data": [{
"changeTime": 1657312008411,
"accountId": "1234",
"eventType": "place_order",
"available": "9999999983.668",
"currency": "BTC",
"id": 60018450912695040,
"userId": 12345,
"hold": "16.332",
"ts": 1657312008443
}]
}