Package: tradingkit
TradingKitThis file shows the basic usage for TradingKit, for more docs, please see theWikiRequirementspython 3.7+pipInstallationthe recommended way to install TradingKit si viaPyPi.Install fromPyPipip3installtradingkitInstall fromSourcegitclonehttps://github.com/logictraders/tradingkitcdtradingkit# Optional, uncomment the line below if you want a specific version# git checkout v1.2.5python3setup.pyinstallCreating strategiesIn order to create new strategies you need4 stepsCreate separate projectCreate new python3.7+ project, no need to do anymore in this step.Creating strategy classcreate a class extending fromtradingkit.strategy.strategy.Strategy# File my_project/my_strategy.pyimportloggingimportccxt.Exchangefromtradingkit.pubsub.event.tradeimportTradefromtradingkit.pubsub.event.bookimportBookfromtradingkit.pubsub.event.orderimportOrderfromtradingkit.pubsub.core.eventimportEventfromtradingkit.strategy.strategyimportStrategyclassMyStrategy(Strategy):def__init__(self,exchange:Exchange,config):super().__init__(exchange,config)# do whatever initializations you needdefon_event(self,event:Event):ifisinstance(event,Trade):logging.info("Order event happened!")# do whatever you need with the exchangeself.exchange.create_order(...)ifisinstance(event,Book):logging.info("Book event happened!")# do whatever you need with the exchangeself.exchange.create_order(...)ifisinstance(event,Order):logging.info("Order event happened!")# do whatever you need with the exchangeself.exchange.create_order(...)Create main config filecreatesystem/config.jsonfile{"strategy":{"class":"my_strategy.MyStrategy","arguments":["@bridge","@config"]},"config":{"symbol":"%env(SYMBOL)%"}}create.envfile to add some env vars# File .envSYMBOL=BTC/EURConfigure dev environmentcreatesystem/config.dev.jsonfile{"exchange":"@testex","feeder":"@backtest_feeder"}Configure live environmentcreatesystem/config.live.jsonfile{"exchange":"@kraken","feeder":"@kraken_feeder"}create.env.live.localfile to add your bitmex credentials credentials# File .env.live.localKRAKEN_KEY=xxxxxxxxxxxxxxxxxxxKRAKEN_SECRET=yyyyyyyyyyyyyyyyyyyyRun dev (backtest)tk run -e dev -y 2020 -m 1 --plotRun livetk run -e live --plotAvailable configurationsInjectable modules:Module TypeKeyModuleDescriptionArgumentsExchangeexchangekrakenKraken exchange APIapikey, secretExchangeexchangebitmexBitmex exchange APIapikey, secretExchangeexchangebitmex_testnetBitmex testnet exchange APIapikey, secretExchangeexchangetestexkraken exchange simulatorbalances, feesExchangeexchangebitmex_backtestbitmex exchange simulatorbalances, feesFeederfeederkraken_backtest_feederfeeder used for kraken simulationsexchange, symbol, since8601, to8601Feederfeederbitmex_funding_backtest_feederfeeder used for bitmex simulationsexchange, symbol, since8601, to8601Feederfeederbitmex_testnet_feederfeeder used for bitmex-testnet live strategiesapikey, secretFeederfeederbitmex_feederfeeder used for bitmex live strategiesapikey, secretFeederfeederkraken_feederfeeder used for kraken live strategiesapikey, secretFeederfeederoutlier_trade_filterfeeder used to reduce back_test outlier trade dataMAX_PRICE_CHANGE_SINGLE_TRADEBridgebridgebridgeexchange interface for simulator and real exchangeexchangePlotterplotterhighstockplotter used to show simulation result on chartPlotterplotterplotlyplotter used to show simulation result on chart