Tradegen
  • Introduction
  • Tradegen Platform
    • Use Cases
    • Supported Assets
    • Supported Projects
    • Pools
    • NFT Pools
    • Marketplace
  • Tutorial
    • Investing in a Pool
    • Withdrawing From a Pool
    • Creating a Pool
    • Managing a Pool
    • Investing in an NFT Pool
    • Withdrawing From an NFT Pool
    • Creating an NFT Pool
  • Token Info
    • Introduction
    • Allocation
  • SDK
    • Getting Started
    • Entities
      • Price
      • TokenAmount
      • Percent
      • Fraction
      • Token
      • Pool
    • Fetcher
    • Other Exports
  • Technical
    • Implementation
    • Synthetic Trading Bots
    • Mining System
    • Trading Strategies
  • Contracts
    • Asset Management V1
    • Data Feeds
      • Protocol
      • Candlestick Data Feeds
        • 1-Minute Timeframe
        • 5-Minute Timeframe
        • 1-Hour Timeframe
        • 1-Day Timeframe
    • Tradegen Token
    • Algo Trading
      • Core Contracts
      • Indicators
      • Comparators
      • Component IDs
      • Initial Instances and Keepers
    • Asset Management V2
      • Core Contracts
      • Price Calculators
      • Adapters
      • Asset Verifiers
      • Contract Verifiers
    • Virtual Trading Environments
    • Farming System
    • Synthetic Trading Bots
  • Resources
    • Roadmap
    • Equations
    • Protocol Settings
    • Changelog
      • Pre-launch
      • Phase 1
      • Phase 2
    • Links
    • Github
    • Analytics
    • Whitepaper
  • Deprecated
    • Pools
      • Investing in Pools
      • Farming
      • Creating a Pool
      • Managing a Pool
      • System Architecture
    • Strategies
      • Investing in Strategies
      • Claiming Yield
      • Running Backtests
      • Strategy Approval
        • Voting for a Strategy
        • Submitting a Strategy
      • Trading LP Tokens
      • Building a Strategy
      • System Architecture
    • Components
      • Components Marketplace
      • Building Custom Components
      • Submitting Custom Components
Powered by GitBook
On this page
  • Communicating with External Protocols
  • Oracles
  • Running Trading Bots
  • Architecture

Was this helpful?

  1. Technical

Implementation

PreviousOther ExportsNextSynthetic Trading Bots

Last updated 3 years ago

Was this helpful?

Communicating with External Protocols

Pool managers can execute transactions on whitelisted DeFi projects by specifying the external contract, encoding the function signature as bytes data, and passing the data as a parameter to a pool’s executeTransaction() function. The data gets verified by a ‘verifier’ contract for the specified external contract. The ‘verifier’ contract checks the function signature against whitelisted signatures and checks for valid parameters. This prevents pool managers from withdrawing funds from Tradegen or interacting with unsupported protocols.

Oracles

Tradegen collects price data from an oracle provider (either Chainlink or Band) for a list of supported assets. Oracle providers update the on-chain price of a supported asset in the Price Aggregator contract once every 30 seconds. The price data for each asset is represented as a ‘Candlestick’ struct, with high price, low price, open price, and close price (volume might be added if the data is provided) for each 5-minute interval. Whenever the Price Aggregator receives an update, it checks the latest price against the Candlestick data and updates the struct accordingly.

At the end of each 5-minute interval, the Candlestick struct is marked as complete. Trading bots would then have 30 seconds to respond to the price data to remain valid. If the bot does not respond in time, minting will be disabled for the bot until the next interval and the keeper in charge of managing the bot will be penalized.

Running Trading Bots

Each strategy has an on-chain trading bot that responds to updates from the bots dedicated keeper once per interval (determined by the bot’s timeframe). When the bot receives an update, it decides whether to enter/exit/avoid a trade by checking the latest oracle price of the target asset against the strategy’s entry/exit criteria. If the entry/exit criteria are met, the bot’s artificial order history is updated to reflect a simulated trade.

The bot is implemented as a state machine, storing the state of each entry/exit rule and updating the state when the price feed updates. Entry/exit rules have two indicators and a comparator, each with their own state that gets updated whenever the price feed updates.

The price of a trading bot’s token is calculated using its artificial order history and the oracle price of the bot’s traded asset.

Architecture