diff --git a/README.md b/README.md index 38723fb..725a985 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,28 @@ myAddress.sendAsset(otherAddress, myToken, 50) ``` +#### Code Example using a different asset for the matcher fee on a DeX and placing an order +```python +import PyCWaves +pw = PyCWaves.PyCWaves() + +pw.setMatcher(node='https://dex.polarity.exchange') +pw.setDatafeed(wdf='https://api.marketdata.turtlenetwork.eu/') +pw.setNode('https://node.mortysnode.nl', 'turtlenetwork', 'L') +pw.DEFAULT_CURRENCY = 'TN' +pw.DEFAULT_MATCHER_FEE_ASSET_ID = '7RB3BWayeCVPq3kkpkeJZAFv2DYCB5gEwnutEpRofaw4' #USDT is set as the asset for the matcher fee +pw.DEFAULT_MATCHER_FEE = int(0.01 * pow(10, 6)) + +myAddress = pw.Address(privateKey='CtMQWJZqfc7PRzSWiMKaGmWFm4q2VN5fMcYyKDBPDx6S') + +amount_asset = pw.Asset('AVJc3uYu8HdjQEx4rroaq6v4Xv4L1etG1tQPeuqs38Sf') +price_asset = pw.Asset('7RB3BWayeCVPq3kkpkeJZAFv2DYCB5gEwnutEpRofaw4') +pair = pw.AssetPair(amount_asset, price_asset) +o = myAddress.sell(assetPair=pair, amount=1000000, price=2354, maxLifetime=86400) +print(o.orderId) + +``` + ### Address Class __pywaves.Address(address, publicKey, privateKey, seed)__ _Creates a new Address object_ diff --git a/__init__.py b/__init__.py index 5c0948b..8d42fce 100644 --- a/__init__.py +++ b/__init__.py @@ -39,6 +39,7 @@ def __init__(self): self.DEFAULT_SET_SCRIPT_FEE = 1000000 self.DEFAULT_INVOKE_SCRIPT_FEE = 500000 self.DEFAULT_CURRENCY = 'WAVES' + self.DEFAULT_MATCHER_FEE_ASSET_ID = self.DEFAULT_CURRENCY self.VALID_TIMEFRAMES = (5, 15, 30, 60, 240, 1440) self.MAX_WDF_REQUEST = 100 diff --git a/address.py b/address.py index 54366fa..40f078d 100644 --- a/address.py +++ b/address.py @@ -696,35 +696,70 @@ def _postOrder(self, amountAsset, priceAsset, orderType, amount, price, maxLifet expiration = timestamp + maxLifetime * 1000 asset1 = b'\0' if amountAsset.assetId=='' else b'\1' + base58.b58decode(amountAsset.assetId) asset2 = b'\0' if priceAsset.assetId=='' else b'\1' + base58.b58decode(priceAsset.assetId) - sData = b'\2' + \ - base58.b58decode(self.publicKey) + \ - base58.b58decode(self.pycwaves.MATCHER_PUBLICKEY) + \ - asset1 + \ - asset2 + \ - orderType + \ - struct.pack(">Q", price) + \ - struct.pack(">Q", amount) + \ - struct.pack(">Q", timestamp) + \ - struct.pack(">Q", expiration) + \ - struct.pack(">Q", matcherFee) - signature = crypto.sign(self.privateKey, sData) - otype = "buy" if orderType==b'\0' else "sell" - data = json.dumps({ - "senderPublicKey": self.publicKey, - "matcherPublicKey": self.pycwaves.MATCHER_PUBLICKEY, - "assetPair": { - "amountAsset": amountAsset.assetId, - "priceAsset": priceAsset.assetId, - }, - "orderType": otype, - "price": price, - "amount": amount, - "timestamp": timestamp, - "expiration": expiration, - "matcherFee": matcherFee, - "signature": signature, - "version": 2 - }) + if self.pycwaves.DEFAULT_MATCHER_FEE_ASSET_ID != self.pycwaves.DEFAULT_CURRENCY: + sData = b'\3' + \ + base58.b58decode(self.publicKey) + \ + base58.b58decode(self.pycwaves.MATCHER_PUBLICKEY) + \ + asset1 + \ + asset2 + \ + orderType + \ + struct.pack(">Q", price) + \ + struct.pack(">Q", amount) + \ + struct.pack(">Q", timestamp) + \ + struct.pack(">Q", expiration) + \ + struct.pack(">Q", matcherFee) + \ + b'\1' + \ + base58.b58decode(self.pycwaves.DEFAULT_MATCHER_FEE_ASSET_ID) + signature = crypto.sign(self.privateKey, sData) + otype = "buy" if orderType==b'\0' else "sell" + data = json.dumps({ + "senderPublicKey": self.publicKey, + "matcherPublicKey": self.pycwaves.MATCHER_PUBLICKEY, + "assetPair": { + "amountAsset": amountAsset.assetId, + "priceAsset": priceAsset.assetId, + }, + "orderType": otype, + "price": price, + "amount": amount, + "timestamp": timestamp, + "expiration": expiration, + "matcherFee": matcherFee, + "signature": signature, + "matcherFeeAssetId" : self.pycwaves.DEFAULT_MATCHER_FEE_ASSET_ID, + "version": 3 + }) + else: + sData = b'\3' + \ + base58.b58decode(self.publicKey) + \ + base58.b58decode(self.pycwaves.MATCHER_PUBLICKEY) + \ + asset1 + \ + asset2 + \ + orderType + \ + struct.pack(">Q", price) + \ + struct.pack(">Q", amount) + \ + struct.pack(">Q", timestamp) + \ + struct.pack(">Q", expiration) + \ + struct.pack(">Q", matcherFee) + \ + b'\0' + signature = crypto.sign(self.privateKey, sData) + otype = "buy" if orderType==b'\0' else "sell" + data = json.dumps({ + "senderPublicKey": self.publicKey, + "matcherPublicKey": self.pycwaves.MATCHER_PUBLICKEY, + "assetPair": { + "amountAsset": amountAsset.assetId, + "priceAsset": priceAsset.assetId, + }, + "orderType": otype, + "price": price, + "amount": amount, + "timestamp": timestamp, + "expiration": expiration, + "matcherFee": matcherFee, + "signature": signature, + "version": 3 + }) req = self.pycwaves.wrapper('/matcher/orderbook', data, host=self.pycwaves.MATCHER) id = -1 if 'status' in req: