Skip to content

Instantly share code, notes, and snippets.

@reddec
Last active December 11, 2019 08:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reddec/e91da5d33f8bacb71b423e2689166455 to your computer and use it in GitHub Desktop.
Save reddec/e91da5d33f8bacb71b423e2689166455 to your computer and use it in GitHub Desktop.
Very very simple logic for crix automatic trading
# Welcome to CRIX.
# This file is a minimal example to get you started.
# If you have any questions, you can always ask us on Telegram: https://t.me/joinchat/AAKXwhUQzCJTcSd4h76LYQ
# Or check out Catalyst's documentation: https://enigma.co/catalyst/
# Happy trading!
# youtube: https://www.youtube.com/watch?v=yswBW0uyqgQ&t=5s
# Imports
import pandas as pd
import numpy as np
from cryzen import plot, param
# Exchange, symbol to trade, and starting capital
SYMBOL_NAME = 'eth_btc'
CAPITAL_BASE = 1.0 # Units in `QUOTE_CURRENCY` below
QUOTE_CURRENCY = 'btc'
# Trading frequency, and time range to backtest over
DATA_FREQUENCY = 'daily' # choices: 'minute', or 'daily'
START_TIME = pd.to_datetime('2019-01-01', utc=True)
END_TIME = pd.to_datetime('2019-11-19', utc=True)
BOUGHT = False
def initialize(context):
context.asset = symbol(SYMBOL_NAME)
def handle_data(context, data):
global BOUGHT
historical_data = data.history(
context.asset,
bar_count=3,
fields=['price', 'open', 'high', 'low', 'close', 'volume'],
frequency='1D') # frequency can be '1D' for daily, or
print(historical_data)
current_close = historical_data['close'][-1]
starting_close = historical_data['close'][0]
net_charge = (current_close - starting_close) / starting_close
plot(context, net_charge = net_charge)
if (net_charge > 0 ) and (not BOUGHT):
order_target_percent(context.asset, 0.75)
BOUGHT = True
if (net_charge < 0) and BOUGHT:
order_target_percent(context.asset, 0)
BOUGHT = False
def analyze_live(context, results):
pass
# `analyze` runs at the end of a job
def analyze(context, results):
print("Runs after job ends")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment