CodeBull · Trading basics, lesson 4

Your first bot

Same book, but this time you don’t click Buy. A few lines of CodeBull strategy code watch the price and place the order for you. Press Run and watch your code act. DEMO is a coin made up for these lessons.

Your code: real CodeBull Python

class Strategy:
    def __init__(self):
        self.ordered = False

    def on_new_tick(self, symbol, price, ctx):
        # 99 and 98 are DEMO's prices: change them for the symbol you test.
        if price < 99 and not self.ordered:
            ctx.place_order(symbol, "buy", 1, "limit", price=98)
            self.ordered = True
DEMO / USDFictional coin last $100

Asks: people selling (cheapest at the bottom)

spread $2

Bids: people buying (highest at the top)

Your account

$1,000.00

Available cash

Your bot’s order

None yet. Press Run.

Total held 0 DEMO
step 0 The code on the left is a CodeBull strategy. On every tick, CodeBull calls on_new_tick with the latest trade price. Each tick here is a trade in this book. It starts at last $100, with no trade yet. Press Run.