TradePatio uses cookies to provide necessary site functionality and improve your experience. By using our website, you agree to our privacy policy.

Module 'trade'

Module 'trade'

Contains functions necessary for trading on the exchanges.

Functions:

create_limit_fok(ex: EX_ID, pair_source: string, quantity: number, price: number,is_buy: boolean) return: order_id: string(may throw an error)

Creates a FOK (Fill Or Kill) policy order on the exchange.

  • ex - exchange ID. Use EX_ID constant.
  • pair_source  - short pair name.
  • quantity  - order quantity.
  • price  - order price.
  • is_buy  - "true" if this is "buy" order, otherwise "false".
  • order_id - order ID. Using it you can get information about the order or close it.

It will throw an error if an order with the specified parameters cannot be placed on this exchange.

create_limit_gtc(ex: EX_ID, pair_source: string, quantity: number, price: number,is_buy: boolean) return: order_id: string(may throw an error)

Creates a GTC (Good Till Cancel) policy order on the exchange.

  • ex - exchange ID. Use the EX_ID constant.
  • pair_source  - short pair name.
  • quantity  - order quantity.
  • price  - order price.
  • is_buy  - "true" if this is "buy" order, otherwise "false".
  • order_id - order ID.

It will throw an error if an order with the specified parameters cannot be placed on this exchange.

close_limit_gtc(ex:EX_ID, order_id: string, skip_check?: boolean) return: quantity_done: number(may throw an error)

Closes an order on the exchange.

  • ex - exchange ID. Use theEX_ID constant.
  • order_id  - order ID .
  • skip_check  - if false the order will not be closed if it's already partially executed.
  • quantity_done  - the executed order volume.

It will throw an error if it is impossible to close the order.

get_order(ex: EX_ID, order_id: string) return: order: Order(may throw an error)

Get the order data.

  • ex - exchange ID. Use the EX_ID constant.
  • order_id  - order ID.
  • order  - Lua object containing information about the warrant. See the Order model.
get_orders(ex: EX_ID) return: orders: []Order(may throw an error)

Get the list of all orders on the exchange.

  • ex - exchange ID. Use the EX_ID constant.
  • orders  - array of Lua objects. See the Order model.
get_orders_by_pair_source(ex: EX_ID, pair_source: string, status: ORDER_STATUS) return: orders: []Order(may throw an error)

Get the list of all orders on the exchange for a certain pair.

  • ex - exchange ID. Use the EX_ID constant.
  • pair_source  - short pair name.
  • status - order status. Use ORDER_STATUS
  • orders  - array of Lua objects. See the Order model.
pair_source_to_pair(ex: EX_ID, pair_source: string) return: pair: string(may throw an error)

Translates the pair's short name to full name.

  • ex - exchange ID. Use the EX_ID constant.
  • pair_source  - short pair name.
  • pair - full pair name.

Throws an error if exchange does not have such pair_source .

pair_to_pair_source(ex: EX_ID, pair: string) return: pair_source: string(may throw an error)

Translates the pair's full name to short name.

  • ex - exchange ID. Use the EX_ID constant.
  • pair  - full pair name.
  • pair_source - short pair name.

Throws an error if exchange does not have such pair .

currency_to_long(ex: EX_ID, currency: string) return: long: string(may throw an error)

Translates the coin's short name to full name.

  • ex - exchange ID. Use the EX_ID constant.
  • currency - short coin name.
  • long - full coin name.

Throws an error if exchange does not have such currency .

currency_to_long(ex: EX_ID, long: string) return:currency: string(may throw an error)

Translates the coin's full name to short name.

  • ex - exchange ID. Use the EX_ID constant.
  • long - full coin name.
  • currency - short coin name

Throws an error if exchange does not have such long .

get_balance(ex: EX_ID) return: balance: map[string]: number(may throw an error)

Get an array of balance information on the exchange.

  • ex - exchange ID. Use the EX_ID constant.
  • balance map[currency]: quantity
    • currency - short coin name.
    • quantity  - coin balance.
get_balance_by_currency(ex: EX_ID, currency: string) return: balance: number(may throw an error)

Get a balance on a certain coin.

  • ex - exchange ID. Use the EX_ID constant.
  • currency short coin name.
  • balance - coin balance.
long_coin_to_btc(ex: EX_ID, long: string, value: number) return: btc: number(may throw an error)

Find out the coin-bitcoin ratio.

  • ex - exchange ID. Use the EX_ID constant.
  • long - full coin name.
  • value - coin amount.
  • btc - bitcoin amount.
btc_to_long_coin(ex: EX_ID, long: string, btc: number) return: value: number(may throw an error)

Find out the Bitcoin to Coin ratio.

  • ex - exchange ID. Use the EX_ID constant.
  • long - full coin name.
  • btc - bitcoin amount.
  • value - coin amount.
is_allow_withdrawal_by_currency(ex: EX_ID, currency: string) return: is_allow: boolean(may throw an error)

Find out if it is possible to withdraw a coin from the exchange.

  • ex - exchange ID. Use the EX_ID constant.
  • currency - full coin name.
  • is_allow - "true" if withdrawal is allowed.
is_allow_deposit_by_currency(ex: EX_ID, currency: string) return: is_allow: boolean(may throw an error)

Find out if it is possible to deposit a coin on the exchange.

  • ex - exchange ID. Use the EX_ID constant.
  • currency - full coin name.
  • is_allow - "true" if deposit is allowed.

 

Constants:

EX_ID
map[string - ex_name]:number - ex_id

EX_NAME
map[number - ex_id]:string - ex_name
ORDER_STATUS
{
skip,
work,
done,
close
}

 

Models:

Order
id: string;
ex_id: EX_ID;
pair_source: string;
is_buy: boolean;
status: ORDER_STATUS;
quantity: number;
price: number;
executed_quantity: number;
total: number;
timestamp_nano: number;