Skip to content
poloniex-sdk edited this page Jan 10, 2023 · 5 revisions

Create Order

create

create(time_in_force=None, account_type=None, client_order_id=None, allow_borrow=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
  • allow_borrow (bool, optional): Allow order to be placed by borrowing funds (Default: false)

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 18,000.00 when price hits 20000 USDT
response = client.orders().create(client_order_id='123Abc',
                                   price='18000',
                                   stop_price='20000.00'
                                   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)

Create Multiple Orders

create_multiple

create_multiple(orders)

Create multiple orders via a single request. Max limit of 20 orders.

Args:

  • orders ([{}], required): List of dictionaries, each item in list should contain parameters to create one order. Each order dictionary can have the following parameters {
  • 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
  • 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:

List of json objects 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:

multi_order_request =
        [
            {
                'price': '20000',
                'quantity': '0.00025',
                'side': 'SELL',
                'symbol': 'BTC_USDT',
                'type': 'LIMIT'
            },
            {
                'price': '50',
                'quantity': '0.05',
                'side': 'BUY',
                'symbol': 'LTC_USDT',
                'type': 'LIMIT'
            },
            {
                'price': '22000',
                'quantity': '0.00024',
                'side': 'SELL',
                'symbol': 'BTC_USDT',
                'type': 'LIMIT'
            }
        ]

response = client.orders().create_multiple(multi_order_request)

Cancel Replace Order

cancel_replace

cancel_replace(order_id, time_in_force=None, proceed_on_failure=None, client_order_id=None, allow_borrow=None, **kwargs)

Cancel an existing active order, new or partially filled, and place a new order on the same symbol with details from existing order unless amended by new parameters. The replacement order can amend price, quantity, amount, type, timeInForce, and allowBorrow fields. Specify the existing order id in the path; if id is a clientOrderId, prefix with cid: e.g. cid:myId-1. The proceedOnFailure flag is intended to specify whether to continue with new order placement in case cancelation of the existing order fails.

Args:

  • order_id (int, required): Id of original order
  • client_order_id (str, optional): clientOrderId of the new order*
  • time_in_force (str, optional): Amended timeInForce; GTC, IOC, FOK (Default: GTC)
  • allow_borrow (bool, optional): Allow order to be placed by borrowing funds (Default: false)
  • proceed_on_failure (str, optional): If set to true then new order will be placed even if cancelation of the existing order fails; if set to false (DEFAULT value) then new order will not be placed if the cancelation of the existing order fails.

Keyword Args:

  • price (str, optional): Amended price
  • quantity (str, optional): Amended quantity
  • amount (str, optional): Amended amount (needed for MARKET buy)
  • type (str, optional): Amended type; MARKET, LIMIT, LIMIT_MAKER (for placing post only orders)

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:

response = client.orders().cancel_replace(order_id, price='19000', proceed_on_failure=True)
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)

Get 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.authenticated().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)