unicorn_binance_trailing_stop_loss package

Submodules

unicorn_binance_trailing_stop_loss.manager module

class unicorn_binance_trailing_stop_loss.manager.BinanceTrailingStopLossManager(api_key: str | None = None, api_secret: str | None = None, borrow_threshold: str | None = None, callback_error: builtin_function_or_method | None = None, callback_finished: builtin_function_or_method | None = None, callback_partially_filled: builtin_function_or_method | None = None, disable_colorama: bool = False, engine: str = 'trail', exchange: str = 'binance.com', keep_threshold: str | None = None, market: str | None = None, print_notifications: bool = False, reset_stop_loss_price: bool = False, send_to_email_address: str | None = None, send_from_email_address: str | None = None, send_from_email_password: str | None = None, send_from_email_server: str | None = None, send_from_email_port: int | None = None, start_engine: bool = True, stop_loss_limit: str | None = None, stop_loss_order_type: str | None = None, stop_loss_price: float | None = None, stop_loss_start_limit: str | None = None, stop_loss_trigger_gap: str = '0.01', telegram_bot_token: str | None = None, telegram_send_to: str | None = None, test: str | None = None, trading_fee_discount_futures_percent: float = 10.0, trading_fee_discount_margin_percent: float = 25.0, trading_fee_discount_spot_percent: float = 25.0, trading_fee_percent: float = 0.1, trading_fee_use_bnb: bool = False, lucit_api_secret: str | None = None, lucit_license_ini: str | None = None, lucit_license_profile: str | None = None, lucit_license_token: str | None = None, ubra_manager: BinanceRestApiManager | None = None, ubwa_manager: BinanceWebSocketApiManager | None = None, warn_on_update=True)[source]

Bases: Thread

After starting the engine, a stop/loss order is placed and trailed until it is completely fulfilled. If desired, a notification can be sent via email and Telegram afterward. Then it calls the function passed with the callback_finished parameter or on error it calls the function passed to callback_error.

Partially filled orders are currently not handled by the engine. If you want to react individually to this event, you can use the function provided to callback_partially_filled.

In addition, there is a smart entry option called jump-in-and-trail. This offers the possibility to buy spot, future and margin assets with a limit or market order and then to trail a stop/loss order until sold.

Supported exchanges: binance.com, binance.com-testnet, binance.com-futures, binance.com-margin, binance.com-isolated_margin

Parameters:
  • api_key (str) – Provide the Binance API key.

  • api_secret (str) – Provide the Binance API secret.

  • borrow_threshold (str) – Provide the private Binance key.

  • callback_error (function or None) – Callback function used if an error occurs.

  • callback_finished (function or None) – Callback function used if stop_loss gets filled.

  • callback_partially_filled (function or None) – Callback function used if stop_loss gets partially filled filled.

  • disable_colorama (bool) – set to True to disable the use of colorama

  • engine (str) – Option trail (default) for standard trailing stop/loss or jump-in-and-trail to activate smart entry function.

  • exchange (str) – Choose the exchange endpoint: binance.com, binance.com-futures, binance.com-margin, binance.com-isolated_margin

  • keep_threshold (str) – If empty we sell the full balance, use integer or percent values.

  • market (str) – The market to enforce stop/loss.

  • print_notifications (bool) – If True the lib is printing user friendly information to terminal.

  • reset_stop_loss_price (bool) – Reset an existing stop_loss_price and calculate a new one. Only True is True, anything else is False!

  • send_to_email_address (str) – Email address of receiver

  • send_from_email_address (str) – Email address of sender

  • send_from_email_password (str) – Password for SMTP auth

  • send_from_email_server (str) – Hostname or IP of SMTP server

  • send_from_email_port (int) – Port of SMTP server

  • start_engine (bool) – Start the trailing stop loss engine. Default is True

  • stop_loss_limit (str) – The limit is used to calculate the stop_loss_price of the highest given price, use integer or percent values.

  • stop_loss_order_type (str) – Can be limit or market - default is None which leads to a stop of the algorithm.

  • stop_loss_price (float) – Set a price to use for stop/loss, this is valid till it get overwritten with a higher price.

  • stop_loss_start_limit (str) – The trailing stop/loss order is trailed with the distance defined in stop_loss_limit. If you want to use a different value at the start, you can specify it with stop_loss_start_limit. This value will be used instead of the stop_loss_limit value until this value is caught up and then trailed.

  • stop_loss_trigger_gap (str) – Gap between stopPrice and limit order price, use integer or percent values.

  • test (str) – Use this to test specific systems like “notification”, “binance-connectivity” and “streams”. The streams test needs a valid exchange and market. If test is not None the engine will NOT start! It only tests!

  • telegram_bot_token (str) – Token to connect with Telegram API.

  • telegram_send_to (str) – Receiver of the message sent via Telegram.

  • trading_fee_use_bnb (bool) – Default is False. Set to True to use BNB for a discount on trading fees: https://www.binance.com/en/support/faq/115000583311.

  • warn_on_update (bool) – set to False to disable the update warning

  • lucit_api_secret (str) – The api_secret of your UNICORN Binance Suite license from https://shop.lucit.services/software/unicorn-binance-suite

  • lucit_license_ini (str) – Specify the path including filename to the config file (ex: ~/license_a.ini). If not provided lucitlicmgr tries to load a lucit_license.ini from /home/oliver/.lucit/.

  • lucit_license_profile (str) – The license profile to use. Default is ‘LUCIT’.

  • lucit_license_token (str) – The license_token of your UNICORN Binance Suite license from https://shop.lucit.services/software/unicorn-binance-suite

  • ubra_manager (BinanceRestApiManager) – Provide a shared unicorn_binance_rest_api.manager instance

  • ubwa_manager (BinanceWebSocketApiManager) – Provide a shared unicorn_binance_websocket_api.manager instance.

calculate_stop_loss_amount(amount: float) float | None[source]

Calculate the tradeable stop/loss asset amount (= owning and free - trading fee)

Parameters:

amount (float) – The full owning asset amount.

Returns:

float or None

static calculate_stop_loss_price(price: str | float | None = None, limit: str | float | None = None) float | None[source]

Calculate the stop/loss price.

Parameters:
  • price (float, str) – Base price used for the calculation

  • limit (float, str) – Stop loss limit in percent or as fixed float value

Returns:

float or None

cancel_open_stop_loss_order() bool[source]

Cancel all open stop/loss orders.

Returns:

bool

create_stop_loss_order(stop_loss_price: float | None = None, current_price: float | None = None) bool[source]

Create a stop/loss order!

Parameters:
  • stop_loss_price (float) – Price to set for the SL order.

  • current_price (float) – Current price is optional and only used for logging.

Returns:

bool

get_exchange_info() dict | bool[source]

Get the exchange info.

Returns:

dict or bool

static get_latest_release_info()[source]

Get infos about the latest available release :return: dict or False

get_latest_version() str | None[source]

Get the version of the latest available release (cache time 1 hour) :return: str or None

get_open_orders(market: str | None = None) dict | None[source]

Get the owning amount of the stop/loss asset.

Returns:

dict or None

get_owning_amount(base_asset: str | None = None) tuple | None[source]

Get the owning amount of the stop/loss asset.

Returns:

tuple (total, free) or None

static get_precision(step_size=None)[source]
get_stop_loss_asset_amount() float | None[source]

Get the current stop/loss asset amount.

Returns:

float

get_stop_loss_asset_amount_free() float | None[source]

Get the free current stop/loss asset amount.

Returns:

float

get_stop_loss_price() float | None[source]

Get the current stop loss price.

Returns:

float

get_stop_loss_trigger_price(stop_loss_price: float = 0.0) float | None[source]

Get the current stop/loss trigger price - if this price gets touched the limit order will get placed in the orderbook.

Returns:

float

get_symbol_info(symbol: str | None = None) dict | None[source]

Get the symbol info of the stop/loss asset.

Returns:

dict

get_user_agent()[source]

Get the user_agent string “lib name + lib version + python version” :return:

static get_version() str[source]

Get the package/module version :return: str

is_manager_stopping()[source]

Returns True if the manager has a stop request, ‘False’ if not.

Returns:

bool

is_update_available() bool[source]

Is a new release of this package available? :return: bool

process_price_feed_stream(stream_data: dict | None = None, stream_buffer_name=False) bool[source]

Process the price feed data: Control current price and update stop_loss_price or trigger stop/loss if needed.

Returns:

bool

process_userdata_stream(stream_data: dict | None = None, stream_buffer_name=False)[source]

Process the received data of the userData stream.

Returns:

bool

static round_decimals_down(number: float, decimals: int = 2) float[source]

Returns a value rounded down to a specific number of decimal places. :param number: The decimal number to round down. :type number: float :param decimals: How many decimals you want to keep. :type decimals: int :return: float

run() None[source]

Start Stop/Loss with provided settings!

Returns:

None

send_email_notification(message: str | None = None) bool[source]

Send a notification via email!

Parameters:

message (str) – Text to send via email.

Returns:

send_telegram_notification(message: str | None = None) bool[source]

Send a notification via telegram!

Parameters:

message (str) – Text to send via Telegram.

Returns:

set_stop_loss_price(stop_loss_price: float | None = None) bool[source]

Set the stop/loss price.

Parameters:

stop_loss_price (float) – Price to set for the SL order.

Returns:

bool

start_streams() bool[source]

Procedure to start the web streams

Returns:

bool

stop() bool[source]

Stop stop_loss! :)

Returns:

bool

stop_manager(close_api_session: bool = True) bool[source]

Stop stop_loss! :)

Returns:

bool

update_stop_loss_asset_amount(total: float | None = None, free: float | None = None) tuple[source]

Update the owning asset amount (total, free)!

Parameters:
  • total (float) – Total amount of the stop_loss_asset!

  • free (float) – Free amount of the stop_loss_asset!

Returns:

tuple

update_stop_loss_quantity(total: float = 0.0, free: float = 0.0) float[source]

Calculate and update the stop_loss_quantity!

Parameters:
  • total (float) – Total asset amount

  • free (float) – Free asset amount

Returns:

float

unicorn_binance_trailing_stop_loss.cli module

async unicorn_binance_trailing_stop_loss.cli.cli()[source]

UNICORN Binance Trailing Stop Loss Command Line Interface Documentation

More info: https://www.lucit.tech/ubtsl-cli.html

unicorn_binance_trailing_stop_loss.cli.main()[source]

Module contents