Unmanaged Trading
Introduction
Unmanaged trading in HaasScript means that you are in full control of the orders. With this category of trading commands, you are able to create scripts that can handle multiple orders on multiple markets simultaneously.
Executing Orders
Placing orders
Executing orders in unmanaged trading happens with 6 commands: PlaceBuyOrder
, PlaceGoLongOrder
, PlaceExitLongOrder
, PlaceSellOrder
, PlaceGoShortOrder
, and PlaceExitShortOrder
. These commands will return an order identifier (order ID) which can be used to control specific orders in the order books or to get information about their current status.
This demo script places an order if non has been placed yet.
PlaceBuyOrder
This unmanaged trading command is used for spot trading and sends out a buying order for the given price and amount.
PlaceSellOrder
This command is used for spot trading and sends out a selling order for the given price and amount.
PlaceGoLongOrder
This unmanaged trading command is used for futures trading and sends out an order to get long contracts for the given price and amount.
PlaceGoShortOrder
This unmanaged trading command is used for futures trading and sends out an order to get short contracts for the given price and amount.
PlaceExitLongOrder
This unmanaged trading command is used for futures trading and sends out an order to sell the long contracts for the given price and amount.
PlaceExitShortOrder
This unmanaged trading command is used for futures trading and sends out an order to sell the sell contracts for the given price and amount.
Order types
There are multiple order types that can be utilized in several commands, such as SetOrderType and the fore-mentioned PlaceOrder commands.
LimitOrderType
Executes a limit order which can be placed in the order books. The timeout parameter is used when using this order type. The default timeout is 10 minutes.
MarketOrderType
Executes a market order which will trade with the current market price. These order types execute immediately by filling the set trade amount with the orders from the opposite order book.
NoTimeOutOrderType
Executes a limit order which can be placed in the order books. The timeout parameter is ignored when using this order type.
MakerOrCancelOrderType
Executes a limit order which will either be placed in the order book or canceled if the order would execute immediately by filling another order. The timeout parameter is used when using this order type. The default timeout is 10 minutes. If the current exchange does not support this type, a normal limit order will be executed.
Managing orders
Order Management
Order management is crucial for the more advanced bots and trading systems. With these commands you are able to;
Cancel all or specific orders
Check if orders are open or filled
Cancelling orders
To cancel a specific order, we use CancelOrder
.
To cancel ALL orders, we use CancelAllOrders
.
Open orders
There are multiple ways to check for open orders.
We can either do IsAnyOrderOpen
, which checks for any open orders in the bot or a system. If the positionId parameter is not set, then the system will check for all orders that a bot or system has created. This command also works for managed trading.
Or we can do IsOrderOpen
to check for specific order.
Order Information
Gather order information to keep an eye on your orders and let your system know what it needs to do next. Using this category of commands you can check if an order is partially or fully filled, how much the fee costs are, when was the order opened and much more.
Order containers and collections
To get all possible information about partially filled and filled orders, we use GetAllFilledOrders
. This command returns a collection of all (partially) filled orders executed by the bot.
For open orders, we use GetAllOpenOrders
. This command returns a collection of all open orders executed by the bot.
For all order-specific information, we use OrderContainer
. The returned value is an array that contains the information.
Cancelled amount
To get order's canceled amount, we use GetOrderCancelledAmount
. This amount is what was left unfilled when the order was canceled, or the full amount when the order is completed.
Filled amount
To get the order's filled amount, we use GetOrderFilledAmount
. This value tells how much of the order has been filled. The amount will be the same as the executed amount if the order is filled.
Order timestamp
To get the time when the order was created, we use GetOrderOpenTime
. The returned value is presented as minutes by default.
Managing Positions
Position management
Positions in HaasScript are components which you can use to define whether a bot is "bought/long", "sold/short" or in "no position". They also store lots of information which you and your bots can use to monitor performance or even plan ahead.
Creating positions
Positions can be created simply by calling CreatePosition
or doing a trade. You can define the position ID when placing orders and creating position, or you can leave it empty which will auto-generate it. You can also have multiple positions within one script (multi-market trading).
The ID can be used to check on information like last trade prices, (average) entry/exit price and position size, market, profit and much more.
CreatePosition
Doing a trade
Example #1: Auto-generated ID
Example #2: User-defined ID
Position information
PositionContainer
PositionContainer is a collection of all possible information about your bot's position.
Separate information commands
You are also able to extract specific information about bot's position by using LongAmount
, ShortAmount
, GetPositionMarket
, GetPositionDirection
, GetPositionEnterPrice
, GetPositionAmount
, GetPositionProfit
and GetPositionROI
.
Position prices
To extract last trade prices, we use AverageEnterPrice
, AverageExitPrice
, LastExitLongPrice
, LastExitShortPrice
, LastLongPrice
, LastShortPrice
, and LastNoPositionPrice
.
Managing Wallet
Wallet commands
Wallet commands are a great way to check if you have enough assets for entries and exits.
Maximum entry amount
MaxLongAmount
and MaxShortAmount
will calculate the minimum/maximum trade amount which can be used to place entry orders.
Maximum exit amount
MaxExitLongAmount
and MaxExitShortAmount
will calculate the maximum trade amount which can be used to place exit orders.
Coin amount and wallet check
WalletAmount
will get the available amount in the wallet for a specific coin.
With WalletCheck
, you can make sure you have enough assets in the wallet before executing orders.
Last updated