Skip to content

Commit

Permalink
updated postOrder to v3
Browse files Browse the repository at this point in the history
  • Loading branch information
iammortimer committed Aug 27, 2020
1 parent 488a15f commit 92396b6
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 29 deletions.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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_

Expand Down
1 change: 1 addition & 0 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
93 changes: 64 additions & 29 deletions address.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 92396b6

Please sign in to comment.