Module "Autotrade" - ThisIsntTheWay/ps_binance_interface GitHub Wiki

Autotrade usage

This page documents the usage of the module 'autoTrade.ps1'.

Overview

At its current stage,'autoTrade.ps1' simply executes orders based on JSON data.
This data is fed into the script, or rather bot, using files on the system.
(It is not possible to feed data into this bot using alternate methods just yet.)

Additionally, this bot is incapable of automating trades based on a trading strategy.
It simply executes whatever it parses in those JSON files.

The bot expects JSON files to be located in "./automation/FILE.JSON".
Additionally, for logging purposes, the directory "./log" must also exist.
If none of these folders exist, they will be created.

Usage

❗ Prior to usage, you must have saved a valid API key and its corresponding secret into the SQLite DB 'bdb.db'.
❗ To create this DB and populate it with correct data, execute "main.ps1" first!

To start the bot, simply execute 'autoTrade.ps1'.

Parameters

With its default parameters - i.e. none supplied - , the following configuration applies:

  • Log to console (in addition to file).
  • Dispatch all orders as tests.
  • ABORT if the specified quote asset limit is exceeded.
  • ABORT if wallet balance is too low to satisfy order.

These parameters can be overwritten with the following switches:

  • (Bool) logConsole
    • TRUE = enable logging to console in addition to file.
    • FALSE = limit logging to file only.
  • (int) quoteAssetLimit
    • Sets the limit for the maximum amount of 'quoteAsset' that can be used with a market order.
    • The context of "quoteAsset" is best explained in the JSON data reference.
  • (string) quoteAssetLimitViolation
    • Controls the behaviour in case 'quoteAssetLimit' is exceeded.
      • "CONTINUE" = Ignore limit violation.
      • "OVERRIDE" = Override order quantity with the limit as specified in "quoteAssetLimit".
      • "ABORT" = Discard the order.
  • (string) quoteAssetInsufficency
    • Controls the behaviour in case of insufficient wallet balance
      • "OVERRIDE" = Use max amount of available wallet balance for order
      • "ABORT" = Discard the order.
  • (bool) testOrders
    • Specifies if all orders are to be treated as tests.
      • TRUE = Treat as test order.
      • FALSE = Treat as full orders.

JSON data structure

❗ Currently, the bot can handle only MARKET orders.
LIMIT orders are to be implemented.

Here's an example of a valid JSON market order:

{
	"Name": "BUY_ORDERS",
	"Type": "MARKET",
	"Orders": [
		{
			"description": "Test 1",
			"targetAsset": "XRP",
			"quoteAsset": "USDT",
			"side": "BUY",
			"sideMode": "QUOTE",
			"quantity": "5000",
			"schedule": "27.12.2020 18:38:14",
			"options": [
				{
					"requireWallet": "TRUE",
					"retryOnPrematurity": "TRUE",
					"retryInterval": "5",
					"liquidate": "FALSE",
					"liquidateMode": "LastOrder"
				}
			]
		}
	]
}

Refer to the following table for an explanation of all these params:

Parameter Description Datatype Mandatory
name Name of order collection STRING Yes
type Type of order (MARKET/LIMIT) STRING No
orders[] Place all orders here ARRAY Yes
> description Description for this order STRING No
> targetAsset Target asset to buy/sell STRING Yes
> quoteAsset Quote asset/Trading pair STRING Yes
> side Side of order book (Buy/sell) STRING Yes
> sideMode Controls how the market order should buy/sell.
"QUOTE" = Buy/sell with (quantity * quoteAsset)
"ASSET" = Buy/sell with (quantity * targetAsset)

STRING Yes
> quantity Amount of targetAsset/quoteAsset to use with order STRING Yes
> schedule When the bot should execute this order.
MUST be specified in the following format:
'dd.MM.yyyy HH:mm:ss'
DATE Yes
> options[] Set options for the CURRENT order ARRAY Yes
- > requireWallet TRUE = User must have sufficient quoteAsset in wallet
FALSE = Ignore wallet balance
BOOL Yes
- > retryOnPrematurity TRUE = Retry this order if it is ahead of schedule
FALSE = Discard this order if it is ahead of schedule
BOOL Yes
- > retryInterval Amount of seconds to wait before retrying this order.
Only used if retryOnprematurity is set to TRUE.
INT Yes
- > liquidate Controls whether or not this order should liquidate targetAsset.
Only used if side is set to SELL.
BOOL No
- > liquidateMode Controls how liquidation behaves.
Only used if liquidate is set to TRUE.
STRING No

Explanation: sideMode

Depending on the specified value, the bot will attempt to buy/sell with (quantity * sideMode):

  • In the case of "ASSET", The bot will spend as much of 'quoteAsset' available to achieve X amount of 'targetAsset'.
    • Example: Spend as much USDT (quoteAsset) as needed to obtain 500 (quantity) XRP (targetAsset).
  • In the case of "QUOTE", The bot will spend X amount of 'quoteAsset' to acquire 'targetAsset'.
    • Example: Spend 200 (quantity) USDT (quoteAsset) to obtain XRP (targetAsset).

Explanation: liquidate

Depending on the specified value, the bot will attempt to liquidate the entirety of the users targetAsset position.
This param accepts two values:

  • All
    • Sells ALL of the users targetAsset possessions.
      This will set sideMode to ASSET.
    • For best accuracy, this will make an API call to obtain user wallet info prior to execution.
      This data will not be stored in the userInfo table to save time.
  • LastOrder
    • Sells X amount of targetAsset obtained in the last BUY order of the same targetAsset.
    • The last order is identified by the highest ID in the orderInfo table.
⚠️ **GitHub.com Fallback** ⚠️