Strategy Dev: mtTrader Library

Estimated reading time: 1 min

mtTrader (MachinaTrader Trading) Library

The mtTrader library is imported automatically by mtCommon when the Strategy Type (STRAT_TYPE) is TradingStrategy (2). It is available from the python script as _trader and will generally be used in the onTick method of your strategy. It exposes a set of methods for placing Buy or Sell Orders.

Placing Orders

Currently only non-margin trading is supported, two types of orders can be placed: Buy or Sell orders.

buy

Buy orders are placed using the _trader.buy helper. Market and Limit orders are supported (subject to limitations from the Exchange). The _trader.buy helper takes the following parameters:
Market The Market on which to place a buy order
Order Type ‘MARKET’ or ‘LIMIT’ depending on the desired order type
Amount The amount of the selected Symbol / Amount to buy
Target Price (LIMIT only) In case of a ‘LIMIT’ order, the target price at which it should accept buying
Comment (Optional) If a trade is executed, the comment enables to know why this order has been placed
Timeout [Seconds] (LIMIT only) In case of a ‘LIMIT’ order, the time during which the order should remain open before closing automatically.
Example
buyResult = _trader.buy(config.MARKET, ‘MARKET’, assetAmount, 0)
By using config.MARKET as the target Market, it will use the Quote/Asset from the market on which the strategy is being executed

sell

Sell orders are placed using the _trader.sell helper. Market and Limit orders are supported (subject to limitations from the Exchange). The _trader.buy helper takes the following parameters:
Market The Market on which to place a buy order
Order Type ‘MARKET’ or ‘LIMIT’ depending on the desired order type
Amount The amount of the selected Symbol / Amount to buy
Target Price (LIMIT only) In case of a ‘LIMIT’ order, the target price at which it should accept selling
Comment (Optional) If a trade is executed, the comment enables to know why this order has been placed
Timeout [Seconds] (LIMIT only) In case of a ‘LIMIT’ order, the time during which the order is made should remain open before closing automatically.
Example
sellResult = _trader.sell(config.MARKET, ‘MARKET’, assetAmount, 0)
Was this article helpful?
Dislike 0
Views: 112