Skip to content
poloniex-sdk edited this page Nov 10, 2022 · 5 revisions

Create Order

create

create(time_in_force=None, account_type=None, client_order_id=None, **kwargs)

Create an order for an account.

Args:

  • time_in_force (str, optional): GTC, IOC, FOK. (Default: GTC)
  • account_type (str, optional): SPOT is the default and only supported one.
  • client_order_id (str, optional): Custom client order id, Maximum 64-character length.

Keyword Args:

  • symbol (str, required): Controls aggregation by price.
  • side (str, required): BUY, SELL.
  • type (str, optional): MARKET, LIMIT, LIMIT_MAKER. (Default: MARKET)
  • price (str, optional): Price is required for non-market orders.
  • quantity (str, optional): Quantity is required for MARKET type and SELL side.
  • amount (str, optional): Amount is required for MARKET and BUY side.

Returns:

Json object with order id and client order id:

{
    'id': (str) Order id,
    'clientOrderId': (str) ClientOrderId user specifies in request or an empty string
}

Raises:

  • RequestError: An error occurred communicating with trade engine.

Example:

Limit Buy 0.00025 BTC_USDT at 20,000.00:

response = client.orders().create(client_order_id='123Abc',
                                  price='20000',
                                  quantity='0.00025',
                                  side='BUY',
                                  symbol='BTC_USDT',
                                  type='LIMIT',
                                  time_in_force='IOC')
print(response)

Market Buy 5 USDT worth of BTC on BTC_USDT:

response = client.orders().create(side='BUY', amount='5', symbol='BTC_USDT')
print(response)

Open Orders

get_all

get_all(account_type=None, begins_from=None, **kwargs)

Get a list of active orders for an account.

Args:

  • account_type (str, optional): SPOT is the default and only supported one.
  • begins_from (int, optional): It is 'orderId'. The query begin at 'from', and it is 0 when you first query.

Keyword Args:

  • symbol (str, optional): The symbol to trade,like BTC_USDT. Default is for all symbols if not specified.
  • side (str, optional): Possible sides. (BUY, SELL)
  • direction (str, optional): Possible values. (PRE, NEXT)
  • limit (int, optional): The max number of orders could be returned.

Returns:

A list of json object's with order status':

[
    {
        'id': (str) Order id,
        'clientOrderId': (str) User specified id or an empty string,
        'symbol': (str) The symbol to trade, like BTC_USDT,
        'state': (str) Possible states(PENDING_NEW, NEW, PARTIALLY_FILLED, FILLED, PENDING_CANCEL, PARTIALLY_CANCELED, CANCELED, REJECTED, EXPIRED, FAILED),
        'accountType': (str) Account type,
        'side': (str) Possible sides(BUY, SELL),
        'type': (str) Possible types(MARKET, LIMIT, LIMIT_MAKER),
        'timeInForce': (str) Possible values(GTC, IOC, FOK),
        'quantity': (str) Quote units to be traded for order,
        'price': (str) Price for the order,
        'avgPrice': (str) avgPrice = filledAmount/filledQuantity,
        'amount': (str) Base units to be traded for order,
        'filledQuantity': (str) Quote units already filled,
        'filledAmount': (str) Base units already filled,
        'createTime': (int) Create time,
        'updateTime': (int) Update time
    },
    {...}
    ...
]

Raises:

  • RequestError: An error occurred communicating with trade engine.

Example:

response = client.orders().get_all()
print(response)

Order Details

get_by_id

get_by_id(order_id=None, client_order_id=None)

Create an order for an account. order_id or client_order_id is required.

Args:

  • order_id (str, optional): Order id.
  • client_order_id (str, optional): Client order id.

Returns:

Json object with order's status:

{
    'id': (str) Order id,
    'clientOrderId': (str) User specified id or an empty string,
    'symbol': (str) The symbol to trade, like BTC_USDT,
    'state': (str) Possible states(PENDING_NEW, NEW, PARTIALLY_FILLED, FILLED, PENDING_CANCEL, PARTIALLY_CANCELED, CANCELED, REJECTED, EXPIRED, FAILED),
    'accountType': (str) Account type,
    'side': (str) Possible sides(BUY, SELL),
    'type': (str) Possible types(MARKET, LIMIT, LIMIT_MAKER),
    'timeInForce': (str) Possible values(GTC, IOC, FOK),
    'quantity': (str) Quote units to be traded for order,
    'price': (str) Price for the order,
    'avgPrice': (str) avgPrice = filledAmount/filledQuantity,
    'amount': (str) Base units to be traded for order,
    'filledQuantity': (str) Quote units already filled,
    'filledAmount': (str) Base units already filled,
    'createTime': (int) Create time,
    'updateTime': (int) Update time
}

Raises:

  • RequestError: An error occurred communicating with trade engine.

Example:

Get order by client order id:

response = client.orders().get_by_id(client_order_id='123Abc')
print(response)

Get order by order id:

response = client.orders().get_by_id(order_id='21934611974062080')
print(response)

Cancel Order by Id

cancel_by_id

cancel_by_id(order_id=None, client_order_id=None)

Cancel an active order. Order_id or client_order_id is required, order_id is used if both are provided.

Args:

  • order_id (str, optional): Order's id.
  • client_order_id (str, optional): Order's clientOrderId.

Returns:

Json object with information on deleted order:

{
    'orderId': (str) The order id,
    'clientOrderId': (str) clientOrderId of the order,
    'state': (str) Order's state (PENDING_CANCEL),
    'code': (int) Response code,
    'message': (str) Response message
}

Raises:

  • RequestError: An error occurred communicating with trade engine.

Example:

Cancel order by client order id:

response = client.orders().cancel_by_id(client_order_id='123Abc')
print(response)

Cancel order by order id:

response = client.orders().cancel_by_id(order_id='21934611974062080')
print(response)

Cancel Multiple Orders by Ids

cancel_by_multiple_ids

cancel_by_multiple_ids(order_ids=None, client_order_ids=None)

Batch cancel one or many active orders in an account by IDs. Order_ids or client_order_ids is required.

Args:

  • order_ids (str, optional): List of order ids.
  • client_order_ids (str, optional): List of client order ids.

Returns:

List of json objects with information on deleted orders:

[
    {
        'orderId': (str) The order id,
        'clientOrderId': (str) clientOrderId of the order,
        'state': (str) Order's state (PENDING_CANCEL),
        'code': (int) Response code,
        'message': (str) Response message
    },
    {...},
    ...
]

Raises:

  • RequestError: An error occurred communicating with trade engine.

Example:

Cancel order multiple orders:

response = client.orders().cancel_by_multiple_ids(order_ids=["12345", "67890"], client_order_ids=["33344", "myId-1"])
print(response)

Cancel All Orders

cancel

cancel(symbol=None, account_type=None)

Batch cancel all orders in an account. symbol or account_type is required.

Args:

  • symbol (str[], optional): If symbols are specified then all orders with those symbols will be canceled. If symbols are not specified or array is empty, it will cancel user's all orders for all symbols.
  • account_type (str[], optional): SPOT is the only supported one.

Returns:

A list of json objects with information on all deleted orders:

[
    {
        'orderId': (str) The order id,
        'clientOrderId': (str) clientOrderId of the order,
        'state': (str) Order's state (PENDING_CANCEL),
        'code': (int) Response code,
        'message': (str) Response message
    },
    {...},
    ...
]

Raises:

  • RequestError: An error occurred communicating with trade engine.

Example:

Cancel all orders on 'BTC_USDT':

response = client.orders().cancel(symbol='BTC_USDT')
print(response)

Cancel all orders on 'SPOT' account:

response = client.orders().cancel(account_type='SPOT')
print(response)

Kill Switch

set_kill_switch

set_kill_switch(timeout)

Kill switch mechanism allows to set a timer that cancels all regular and smartorders after the timeout has expired. Timeout can be reset by calling this command again with a new timeout value. A timeout value of -1 disables the timer. Timeout is defined in seconds.

Args:

  • timeout (str, required): Timer value in seconds; range is -1 and 10 to 600. Must be a number.

Returns:

A list of json objects with kill switch results:

{
    'startTime': (int) Time when timer is started (milliseconds since UNIX epoch),
    'cancellationTime': (int) Time when timer is set to expire which will trigger cancellation (milliseconds since UNIX epoch)
}

Raises:

  • RequestError: An error occurred communicating with trade engine.

Example:

response = client.orders().set_kill_switch('15')
print(response)

Kill Switch Status

get_kill_switch

get_kill_switch()

Get status of kill switch. If there is an active kill switch then the start and cancellation time is returned. If no active kill switch then an error message with code is returned.

Returns:

Json object with kill switch results:

{
    'startTime': (int) Time when timer is started (milliseconds since UNIX epoch),
    'cancellationTime': (int) Time when timer is set to expire which will trigger cancellation (milliseconds since UNIX epoch)
}

Raises:

  • RequestError: An error occurred communicating with trade engine.

Example:

response = client.orders().get_kill_switch()
print(response)
Clone this wiki locally