PythoJujuQuatEgie
PYJUQUE (pai-jook)(Py-thoJu-juQu-atE-gie)
Thisprojectimplemetsthebasicfuctioalityrequiredtoegageialgorithmictradig.Itcaberegardedasastartigpoitformorecomplextradigbots.
IstallatioMakesureyouhavepipistalled.Ru:
pipistallpyjuqueYoushouldbegoodtogo!Checkouttheexamplesectio.
GettigStartedCheckouttheseexamplestogetstartedstratghtaway:strategy1,strategy2.Belowisthesimplestexampleofhowtogetstartedwithpyjuque.Readtheextsectiotouderstadthethikigbehidit.
frompyjuque.BotimportdefieBotimporttimedefcustomEtryStrategy(bot_cotroller,symbol):#sigal=will_moo(symbol)#bool#last_price=get_price(symbol)#floatretursigal,last_price##Defiestheoverallcofiguratioofthebotbot_cofig={'ame':'my_bot','test_ru':False#settoTruetoruisimulatiomode'exchage':{'ame':'biace','params':{#puthereayparamthatccxtaccepts'api_key':'YOUR_API_KEY','secret':'YOUR_API_SECRET'},},'symbols':['LINK/BTC','ETH/BTC'],#!!allsymbolsmusttradeagaistsamecoi#!!IE:[XX/BTC,YY/BTC]OR[AA/EUR,CC/EUR]'startig_balace':0.0005,#deomiatedithequoteassetagaistwhich#thesymbolsaretradig(BTCithiscase)'strategy':{'custom':True,'etry_fuctio':customEtryStrategy,},'etry_settigs':{'iitial_etry_allocatio':100,#100%ofstartig_balacegoesieverytrade'sigal_distace':0.3#uporeceivigaetry_sigal,etryorder#isplaced0.3%awayfrommarketprice},'exit_settigs':{'take_profit':3,#takeprofit3%aboveetryorders'stop_loss_value':10#stoploss10%belowetryorders},}##Rusthebotiaifiiteloopthatexecutesevery60secods##stoppablefromthetermialwithCTRL+CdefMai():bot_cotroller=defieBot(bot_cofig)whileTrue:try:bot_cotroller.executeBot()exceptKeyboardIterrupt:returtime.sleep(60)if__ame__=='__mai__':Mai()RuaSimpleBotTheideabehidthislibraryistoallowyoutoimplemetwhatevertradigstrategyyouwat,withouthavigtoworryabouthowtocoecttothedifferetexchagesviaapis,orhowtoplace,caceladkeeptrackoforders.Yousimplyprovidethesigalsadpyjuquedoestherest.
Thereareaumberofsettigsthatyoudefie,likewhatsymbolstotradeo,howmuchmoeytoplacepertradeadwhatexchagetouse.Youalsogettosetexitsettigssuchasatakeprofitvalueadastoplossvalue.Allthesesettigsgetspecifiediacofigdict.Belowisacompleteexampleofacofigdict:
##Defiestheoverallcofiguratioofthebotbot_cofig={#Nameofthebot,asstoredithedatabase'ame':'my_bot',#exchageiformatio(fillwithyourapikeyadsecret)'exchage':{'ame':'biace',#or'okex''params':{#ayparameteracceptedbyccxtcagohere'api_key':'your_api_key_here','secret':'your_secret_here',#'password':'your_password_here'#ifusig'okex'},},#startigbalaceforbot'startig_balace':0.0005,#symbolstotradeo#!IMPORTANT!allsymbolsmusttradeagaistthesamecoi#!!IE:[AAA/BTC,BBB/BTC]OR[AAA/USDT,CCC/USDT]'symbols':['LINK/BTC','ETH/BTC'],#strategyclass/fuctio(herewedefietheetryadexitstrategies.)#thisbotplacesaetryorderwhe'customEtryFuctio'retrustrue'strategy':{'custom':True,'etry_fuctio':customEtryFuctio},#whethebotreceivesthebuysigal,theorderisplacedaccordig#tothesettigsspecifiedbelow'etry_settigs':{#betwee0ad100,the%ofthestartig_balacetoputiaorder'iitial_etry_allocatio':100,#umberbetwee0ad100-1%measthatwhewegetabuysigal,#weplacebuyorder1%belowcurretprice.if0,weplaceamarket#orderimmediatelyuporeceivigsigal'sigal_distace':0.3},#Thisbotexitswheourfilledordershavereachedatake_profit%above#thebuyprice,orastop_loss_value%belowit'exit_settigs':{#takeprofitvaluebetwee0adifiity,3%measweplaceoursell#orders3%abovethepricesthatourbuyordersfilledat'take_profit':3,#stoplossvalueipercet-10%measstoplossat10%belowour#buyorder'sfilledprice'stop_loss_value':10},}Besidesthesesettigs,youeedtoprovideaetrystrategy.Itcabeassimpleasafuctio,oramorecomplexstrategyclass.We'llgooverthesimpleexample:
#Thisisoursigalfuctio.#Itreceivestwoparameters-thebot_cotroller,#whichgivesusaccesstotheexchageadtothe#database,adthesymbolowhichthebotis#curretlycheckigetrysigals.##Itmustreturtwovalues,abooleaadaumber.#Thebooleaisthesigal,adtheumberisthe#latestpriceofthatsymbol#defcustomEtryFuctio(bot_cotroller,symbol):#...dosomestuffhere...retursigal,last_price_of_symbolThebeautyofthisisthatyoucadowhatevertheheckyouwatithatcustometryfuctio,becauseaslogasyoureturasymboladthelatestprice,pyjuquewillbehappy.Youcacheckcoispricesadtheiridicators,thevolumeomultipleexchages,differetorderbooks,eveweatherdata,twitterfeedsorastroomicalevets.
Here'sacompleteexampleofhowtogetstartedwithpyjuque:
frompyjuque.BotimportdefieBot##Thisisoursigalfuctioforow.defcustomEtryFuctio(bot_cotroller,symbol):#...dosomestuffhere...retursigal,last_price##Defiestheoverallcofiguratioofthebotbot_cofig={...}##Rusthebotiaifiiteloop,stoppable##fromthetermialwithCTRL+CdefMai():bot_cotroller=defieBot(bot_cofig)whileTrue:try:bot_cotroller.executeBot()exceptKeyboardIterrupt:returtime.sleep(60)if__ame__=='__mai__':Mai()Upocreatigthebot,adatabasewillbecreatediyourcomputer,keepigtrackofordersplaced.Youcaruthisexampleaditwillwork-butyoushouldupdatecustomEtryFuctiotodosomecalculatios&returtruesometimes,becauseiitscurretstatethebotwo'tevermakeaytrades.
Checkouttheseexamplesformoreifo:strategy1,strategy2.
FeaturesCurretFeatures:LogBot(PlacigBuyOrdersoCustomSigals)Market,Limit&StopLossOrdersAutomaticallyPlacigExitOrderwheEtryOrderwasfulfilledStatePersistace,thebotstorestradeslocallyBiaceLocalOrderBookPlottigCapabilitiesSimpleDefiiitiaofEtryStrategy&ExitRules(viabot_cofig)StatePersisteceUsigSQLAlchemy,forayflavourofSQLIDevelopmet:GridBotFutureFeatures:ShortBotOCOordersSelligosigalsTrailigStopLossMultipleEtriesModulesThislibraryimplemetsthefollowigmodules:
BotCotrollerAtpyjuque/Egie/BotCotroller.py.
Amodulewhichhadlesthebuyigadselligofassets,givesimpleormoreadvacedrules,allowigustoruastrategyidefiitely.
Throughthebotcotrolleryoucaaccessthefollowigobjects
bot_cotroller.exchagebot_cotroller.exchagehassomemethodsthatareuseduderthehoodbypyjquue,likegetOHLCVplaceLimitOrderplaceMarketOrderetcbot_cotroller.exchage.ccxt,accxtobjectwhichusesthecredetialsyouprovidedithebot_cofigbot_cotroller.sessio,SQLAlchemysessiothroughwhichyoucaquerythedatabasebot_cotroller.botmodel,themodelofthebotasstoredithedbbot_cotroller.status_priter,ayaspispierusedforloggigYoucaalsoaccessthefollowigfuctios
bot_cotroller.executeBot(),whichgoesthroughabotloopof:checkigsigalsosymbolsadplacigordersifsigalsaretruecheckigallopeordersplacedbythebotadupdatigthem,likeso:ifabuyorderwasfilleditplacesthesubsequetexitorder,atatake_profitpriceabovethebuypriceifthecurretpriceisbelowstop_loss_valueforaopebuyorder,exitsusigmarketpricebot_cotroller.log()whichallowsyoutopritsomestufftothetermialbot_cotroller.bot_model.getOrders(bot_cotroller.sessio)whichallowsyoutogetallordersbot_cotroller.bot_model.getOpeOrders(bot_cotroller.sessio)whichallowsyoutogetallopeordersExchageCoectorsImplemetigmultipleexchageswithccxt.CheckoutimplemetatioatCcxtExchage.Curretlyimplemeted:
biaceokex
Older(Deprecated):
Atpyjuque/Exchages.
Biace-basedotheofficialRESTAPILocalOrderBook(forBiace)Atpyjuque/Exchages/BiaceOrderBook.py.
Createsadstoresalocalorderbookforthespecifiedsymbols.OrderBookisupdatedeverysecodthroughawebsocketcoectiototheExchage(curretlyBiace).Checkoutthisexample.
frompyjuque.Exchages.BiaceOrderBookimportOrderBook#Iitialize&startOrderBookwithdesiredsymbolsob=OrderBook(symbols=['BTC/USDT','LTC/USDT'])ob.startOrderBook()...#GetUpdatedOrderBookdataataypoitiyourcodeordb=ob.getOrderBook()prit(ordb){'BTC/USDT':{'asks':[['13662.31000000','3.24473100'],['13662.82000000','0.06815300'],['13663.08000000','0.00900000'],...['20000.00000000','95.22325900']],'bids':[['13662.30000000','1.26362900'],['13661.78000000','0.04395000'],['13661.62000000','0.01439200'],...['10188.00000000','1.11546400']],'lastUpdateId':6382686192#igorethis},'LTC/USDT':{'asks':[...],'bids':[...],'lastUpdateId':1521585540#igorethis},'couter':11#igorethis}ComigSooMoreExchagesBiaceFutures,Bitmex,Bitfiex,FTX,Bybit.MargiTradig,MarketMakig,HyperParameterTuig.
CotributigTocotributesimplyforktherepo,writeyourdesiredfeatureiyourowforkadmakeapullrequestupofiishig.Writigtestsisalsoappreciated.







评论