Developers can use the Tradegen SDK to build custom indicators and comparators. These smart contracts are submitted for approval (to check for uniqueness and to make sure there are no security vulnerabilities) and can be sold on the Tradegen marketplace to users wanting to integrate them into their trading bots.
Building a Comparator
Comparators need to implement the IComparator interface shown below:
interface IComparator {
/**
* @dev Returns the sale price and the developer of the comparator
* @return (uint, address) Sale price of the comparator and the comparator's developer
*/
function getPriceAndDeveloper() external view returns (uint, address);
/**
* @dev Updates the sale price of the comparator; meant to be called by the comparator developer
* @param newPrice The new sale price of the comparator
*/
function editPrice(uint newPrice) external;
/**
* @dev Initializes the state of the trading bot; meant to be called by a trading bot
* @param firstIndicatorAddress Address of the comparator's first indicator
* @param secondIndicatorAddress Address of the comparator's second indicator
*/
function addTradingBot(address firstIndicatorAddress, address secondIndicatorAddress) external;
/**
* @dev Returns whether the comparator's conditions are met
* @return bool Whether the comparator's conditions are met after the latest price feed update
*/
function checkConditions() external returns (bool);
// Events
event UpdatedPrice(address indexed comparatorAddress, uint newPrice, uint timestamp);
}
The following state variables should be added to your comparator:
struct State {
address firstIndicatorAddress;
address secondIndicatorAddress;
uint firstIndicatorPreviousValue;
uint secondIndicatorPreviousValue;
}
uint public _price;
address public _developer;
mapping (address => State) private _tradingBotStates;
The 'State' struct should always contain first indicator address and second indicator address. Additional variables in the 'State' struct may be needed depending on the comparator logic.
Building an Indicator
Indicators need to implement the IIndicator interface shown below:
interface IIndicator {
/**
* @dev Returns the name of the indicator
* @return string Name of the indicator
*/
function getName() external pure returns (string memory);
/**
* @dev Returns the sale price and the developer of the indicator
* @return (uint, address) Sale price of the indicator and the indicator's developer
*/
function getPriceAndDeveloper() external view returns (uint, address);
/**
* @dev Updates the sale price of the indicator; meant to be called by the indicator's developer
* @param newPrice The new sale price of the indicator
*/
function editPrice(uint newPrice) external;
/**
* @dev Initializes the state of the trading bot; meant to be called by a trading bot
* @param param Value of the indicator's parameter
*/
function addTradingBot(uint param) external;
/**
* @dev Updates the indicator's state based on the latest price feed update
* @param latestPrice The latest price from oracle price feed
*/
function update(uint latestPrice) external;
/**
* @dev Given a trading bot address, returns the indicator value for that bot
* @param tradingBotAddress Address of trading bot
* @return uint[] Indicator value for the given trading bot
*/
function getValue(address tradingBotAddress) external view returns (uint[] memory);
/**
* @dev Given a trading bot address, returns the indicator value history for that bot
* @param tradingBotAddress Address of trading bot
* @return uint[] Indicator value history for the given trading bot
*/
function getHistory(address tradingBotAddress) external view returns (uint[] memory);
// Events
event UpdatedPrice(address indexed indicatorAddress, uint newPrice, uint timestamp);
}