Last active
December 11, 2019 08:25
-
-
Save reddec/e91da5d33f8bacb71b423e2689166455 to your computer and use it in GitHub Desktop.
Very very simple logic for crix automatic trading
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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