pyjuque开源项目

我要开发同款
匿名用户2021年11月08日
150阅读

技术信息

开源地址
https://github.com/esl/elarm
授权协议
MIT License

作品详情

PythoJujuQuatEgie

PYJUQUE  (pai-jook)(Py-thoJu-juQu-atE-gie)

Thisprojectimplemetsthebasicfuctioalityrequiredtoegageialgorithmictradig.Itcaberegardedasastartigpoitformorecomplextradigbots.

Istallatio

Makesureyouhavepipistalled.Ru:

pipistallpyjuque

Youshouldbegoodtogo!Checkouttheexamplesectio.

GettigStarted

Checkouttheseexamplestogetstartedstratghtaway: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()RuaSimpleBot

Theideabehidthislibraryistoallowyoutoimplemetwhatevertradigstrategyyouwat,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_symbol

Thebeautyofthisisthatyoucadowhatevertheheckyouwatithatcustometryfuctio,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:ShortBotOCOordersSelligosigalsTrailigStopLossMultipleEtriesModules

Thislibraryimplemetsthefollowigmodules:

BotCotroller

Atpyjuque/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,ayaspispierusedforloggig

Youcaalsoaccessthefollowigfuctios

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)whichallowsyoutogetallopeordersExchageCoectors

Implemetigmultipleexchageswithccxt.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}ComigSooMoreExchages

BiaceFutures,Bitmex,Bitfiex,FTX,Bybit.MargiTradig,MarketMakig,HyperParameterTuig.

Cotributig

Tocotributesimplyforktherepo,writeyourdesiredfeatureiyourowforkadmakeapullrequestupofiishig.Writigtestsisalsoappreciated.

功能介绍

Python Juju Quant Engine PYJUQUE (pai-jook) (Py-thon Ju-ju Qu-ant E-ngine) This project implement...

声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态

评论