Tim55667757 / TKSBrokerAPI

TKSBrokerAPI is the trading platform for automation and simplifying the implementation of trading scenarios, as well as working with Tinkoff Invest API server via the REST protocol. The TKSBrokerAPI platform may be used in two ways: from the console, it has a rich keys and commands, or you can use it as Python module.
https://tim55667757.github.io/TKSBrokerAPI/
Apache License 2.0
25 stars 9 forks source link

TradeRoutines: implement `CalculateLotsForDeal()` method #111

Closed Tim55667757 closed 1 year ago

Tim55667757 commented 1 year ago

CalculateLotsForDeal() method calculates maximum lots for deal depends on current price and volume of instrument in one lot.

Formula: lots = maxCost // (currentPrice * volumeInLot), it means max count of lots, for which will be: cost = lots * currentPrice * volumeInLot <= maxCost.

If costOneLot = currentPrice * volumeInLot > maxCost, then returned lots = 1.

If an error occurred then returned lots = 0.

This method can be used when you need to calculate lots to open position.

Tim55667757 commented 1 year ago

Implemented since build v1.6.dev134

Debug build: https://app.travis-ci.com/github/Tim55667757/TKSBrokerAPI/builds/258615346 PyPI artefact for testing: https://pypi.org/project/tksbrokerapi/1.6.dev134/