Update for steemengine - token precision taken into account and several new CLI commands added
utopian-io·@holger80·
0.000 HBDUpdate for steemengine - token precision taken into account and several new CLI commands added
## Repository https://github.com/holgern/steemengine  ## steemengine [steemengine](https://github.com/holgern/steemengine) is a python library for working with [steem-engine.com](https://steem-engine.com/) tokens. I released version 0.4.1 which can be installed by ``` pip install steemengine ``` ## New features ### The token precision is taken into account for transfer, issue, buy, sell, withdraw and deposit I added a new `quantize` function to the Token class. ``` def quantize(self, amount): """Round down a amount using the token precision and returns a Decimal object""" amount = decimal.Decimal(amount) places = decimal.Decimal(10) ** (-self["precision"]) return amount.quantize(places, rounding=decimal.ROUND_DOWN) ``` This function returns a rounded Decimal object, which takes the token precision into account. The amount is rounded down to a valid amount. ``` from steemengine.tokenobject import Token steemp = Token("STEEMP") steemp.quantize(1.0001) Decimal('1.000') steemp.quantize(0.999999) Decimal('0.999') steemp.quantize(0.0001) Decimal('0.000') ``` This function is then used in transfer, issue, buy, sell, withdraw and deposit: ``` token = Token(symbol) quant_amount = token.quantize(amount) if quant_amount <= decimal.Decimal("0"): raise InvalidTokenAmount("Amount to transfer is below token precision of %d" % token["precision"]) ``` If the quantized amount is zero, an InvalidTokenAmount exception is raised. ### New commands for the CLI The acting account, which needs an active key stored in the beem wallet, is either the default beempy account or set by `-a`, e.g. `steemengine transfer -a holger80 beembot 0.001 DRAGON test`. The default account can be set by `beempy set default_account holger80` and checked by `beempy config`. #### steemengine transfer  This command can be used to sent token to other steem accounts. ``` steemengine transfer -a holger80 beembot 0.001 DRAGON test Password to unlock wallet: Wallet Unlocked! { "expiration": "2019-03-20T10:12:49", "ref_block_num": 55237, "ref_block_prefix": 1423306811, "operations": [ [ "custom_json", { "required_auths": [ "holger80" ], "required_posting_auths": [], "id": "ssc-mainnet1", "json": "{\"contractName\":\"tokens\",\"contractAction\":\"transfer\",\"contractPayload\":{\"symbol\":\"DRAGON\",\"to\":\"beembot\",\"quantity\":\"0.0010000\",\"memo\":\"test\"}}" } ] ], "extensions": [], "signatures": [ "206b0d9b6d0939108c2156cefbafa99bccb5bb206c2ca129ebb2cf336112abbaab0ff1151917bec552357d400b6d72b98425f2052735c723522a9537589046b1e7" ] } ```   #### steemengine issue  Issues new token, only possible when the active account is also the issuer of the token. #### steemengine deposit  This command can be used to deposit STEEM and receive STEEMP for buying token. The following command transfers 0.1 STEEM to steem-peg and 0.1 STEEMP are transferred to the account in return. ``` steemengine deposit -a holger80 0.1 ```  #### steemengine withdraw  This command can be used to withdraw STEEMP and receive STEEM. ``` steemengine withdraw -a holger80 0.1 ```  #### steemengine buy  This command can be used to place buy orders. ``` steemengine buy -a holger80 1 JAR 0.9 ``` This places a buy order, for buying 1 JAR for 0.9 STEEMP. The accounts must have 0.9 STEEMP, otherwise a InsufficientTokenAmount exception will be raised. The 0.9 STEEMP are locked until the order is fullfilled or canceled. #### steemengine sell  This command can be used to place a sell order. ``` steemengine sell -a holger80 1 JAR 3 ``` In this examle, holger80 creates a sell order for selling 1 JAR for 3 STEEMP. The accounts needs 1 JAR to broadcast this, otherwise a InsufficientTokenAmount exception is raised. The 1 JAR is locked until the order is fullfilled or canceled. #### steemengine cancel  In order to cancel, the order id must be know. It can be checked with the buybook command. ``` steemengine buybook -a holger80 JAR ```  The buy order can then be canceled by: ``` steemengine cancel -a holger80 buy 1824 ``` A sell order is canceled by ``` steemengine cancel -a holger80 sell 923 ``` #### steemengine buybook  ``` steemengine buybook -a holger80 JAR ``` returns the buybook for account holger80 and token JAR. ``` steemengine buybook JAR ``` returns the complete buy book. #### steemengine sellbook  ``` steemengine sellbook -a holger80 JAR ``` returns the sellbook for account holger80 and token JAR. ``` steemengine sellbook JAR ``` returns the complete sell book. ## Commits ### Fix cancel order id (cast to int) * [commit f63baba](https://github.com/holgern/steemengine/commit/f63babab5ca356d61534b5a2c311739110a03daf) ### Add changelog * [commit 14164d1](https://github.com/holgern/steemengine/commit/14164d1fbae80a70f3185e5db0ec49f11f7bb630) ### Add transfer, issue, withdraw, deposit, buy, sell, cancel, buybook, sellbook to CLI * [commit 31f2e76](https://github.com/holgern/steemengine/commit/31f2e7628b11de694c6a3a0fa63c4ff6747bba12) ### Add amount quantization to deposit, withdraw, buy and sell * [commit 63ee650](https://github.com/holgern/steemengine/commit/63ee650b5170bead53056d2757997e7c2be76510) ### Add token amount quantize and add issue to wallet * [commit c0b7e8d](https://github.com/holgern/steemengine/commit/c0b7e8d13fc00ebc16fe3d3ceae55d2f96dce36d) * quantize added to Token class * TokenDoesNotExists is raised in the Token class when token does not exists * Exception InvalidTokenAmount is raised when amount to transfer or to issue is below precision * new issue function added to wallet * token precision is taken into account for transfer and issue * TokenIssueNotPermitted is raised when an account which is not the token issuer tries to issue ## GitHub Account https://github.com/holgern
👍 sargoon, wstanley226, upgoat, lukasmining, shahabudin, linkerstinker, nurah, orbo, pgshow, changeangels, bubbleburst, someonefun, funlands, robofox, resheep, upcroak, themuffinman, funbox, funanime, funnyfun, dmonia, goldrym, thefunfactory, funkyfun, qeoddrir, dodrorth, beggars, soundworks, akifane, dfen, eforucom, accelerator, sudefteri, flugschwein, alitavirgen, neokuduk, literaturk, steemexpress, bluesniper, rasit, maveraunnehr, bluerobo, reazuliqbal, jacekw.dev, dera123, steembasicincome, sbi2, drorion, sbi3, sbi4, sbi5, sbi6, sbi7, sbi8, sbi9, sbi10, carlpei, jordonemmer, jonasalt, zandrachilcote, voneller, pataty69, allancovelli, charitacaruso, ilonavandam, bertahessler, munhenhos, bhaski, crokkon, ewkaw, jacekw, holger.random, abitcoinskeptic, amosbastian, rufans, helo, jaff8, asaj, bestofph, tobias-g, kendallron, pinas, codingdefined, espoem, mops2e, steemtank, killerbot, make-a-whale, ew-and-patterns, curbot, genuinehuman, shammi, elleok, michealb, maxpatternman, ulockblock, stevescoins, swedishdragon, sashas, brujas, warfeed, thomasgift, backinblackdevil, jasonbu, isnochys, votum, lanzjoseg, revisesociology, feedyourminnows, snwolak, freebornsociety, lauchmelder, zcool, fullnodeupdate, wherein, reggaemuffin, badham, mohaaking, muscara, condeas, mcfarhat, qurator, yadamaniart, emdesan, qberry, ogsenti, mytechtrail, satren, linnyplant, raspibot, flodor, sternekoechin, linuxbot, busy.pay, skycae, oliverschmid, uwelang, thecryptodrive, glitterbooster, kingnosa, abigail-dantes, jeffrey24864, kamikaze, anthive, ambercookie, samantha-w, haiyangdeperci, michaelizer, alvinvoo, commonlaw, perepilichnyy, coquiunlimited, jayna, ikarus56, verhp11, indayclara, arsadulislam, vmiranda, redheadpei, marygourmet, dakeshi, steempty, fminerten, loshcat, greenorange, steemcartel, tommy-gun, hope-on-fire, timcliff, krnel, cryptouno, new-world-steem, harpagon, insiders, mcoinz79, kaczynski, aggroed, satoshi-group, steemik, singhcapital, reseller, jarvie, utopian.trail, walnut1, elear, mcyusuf, gentleshaid, aussieninja, stem-espanol, abh12345, tykee, silviu93, vishalsingh4997, zoneboy, emiliomoron, ulisesfl17, netizens, bflanagin, ubaldonet, jk6276, dssdsds, jayplayco, lupafilotaxia, aleestra, mrsbozz, jk6276.mons, jaxson2011, eternalinferno, techslut, lorenzor, tsoldovieri, iamphysical, felixrodriguez, azulear, che-shyr, amestyj, ivymalifred, eliaschess333, ydavgonzalez, yrmaleza, miguelangel2801, didic, arac, tomastonyperez, elvigia, luiscd8a, elpdl, josedelacruz, joseangelvs, viannis, erickyoussif, yusvelasquez, jesusfl17, fran.frey, jrevilla, giulyfarci52, wilmer14molina, minersean, erikaflynn, jakipatryk, suesa, andrick, joelsegovia, amart29, alaiza, lapp, steemtpistia, crassipes, ajayyy, agrovision, rewarding, vanarchist, steem-ua, newsrx, eastmael, dalz, scienceangel, eniolw, geadriana, alexs1320, alex-hm, steem-star, smjn, znnuksfe, ennyta, endopediatria, anaestrada12, carlos84, sandracarrascal, gaming.yer, steem-familia, evangelista.yova, asmeira, rubenp, jeferc, jcmontilva, moyam, darys, sibaja, balcej, anaka, benhurg, judisa, juddarivv, ilikeit, bubke, bitcoinjake09, ienzi, jjay, ryuna.siege, mattclarke, f21steem, cardboard, cfminer, gameo, tipu.curator, tdre, fredrikaa, hotbit, asgarth, jefferyphurley, sn0n, yabapmatt, borislavzlatanov, theb0red1, amirhuda, dotwin1981, gamer0815, steem-plus, partiko, steemitbuzz, birdinc, jarunik, djenny.floro, bejust, feronio, progressing, utopian-io, tombstone, jga, swapsteem, ascorphat, gandalfthewhite, temitemi131, praveen40, alexei83, aikid, cristhianarturo, adolfobravo, pennsif, apostle-thomas, vezo, trevado, detlev, grzesiekb, eaatts, never-giveup, gustavovivas, whatsup, zephyraijunzo, steemedbot, kgakakillerg, steemit-susu, cryptotokeneur, ausbitbank, comedyopenmic, rahul.stan, idikuci, bitfiend, com-judge,