Ejemplo n.º 1
0
assert Precise.string_mul(a, x) == '2'
assert Precise.string_mul(y, a) == '6969690000000000000'
assert Precise.string_mul(a, y) == '6969690000000000000'
assert Precise.string_div(y, a) == '696.969'
assert Precise.string_div(y, a, -1) == '690'
assert Precise.string_div(y, a, 0) == '696'
assert Precise.string_div(y, a, 1) == '696.9'
assert Precise.string_div(y, a, 2) == '696.96'
assert Precise.string_div(a, y) == '0.001434784043479695'

assert Precise.string_abs('0') == '0'
assert Precise.string_abs('-0') == '0'
assert Precise.string_abs('-500.1') == '500.1'
assert Precise.string_abs('213') == '213'

assert Precise.string_neg('0') == '0'
assert Precise.string_neg('-0') == '0'
assert Precise.string_neg('-500.1') == '500.1'
assert Precise.string_neg('213') == '-213'

assert Precise.string_mod('57.123', '10') == '7.123'
assert Precise.string_mod('18', '6') == '0'
assert Precise.string_mod('10.1', '0.5') == '0.1'
assert Precise.string_mod('10000000', '5555') == '1000'
assert Precise.string_mod('5550', '120') == '30'

assert Precise.string_pow('10', '2') == '100'
assert Precise.string_pow('4', '4') == '256'
assert Precise.string_pow('10000', '3') == '1000000000000'
assert Precise.string_pow('5', '0') == '1'
Ejemplo n.º 2
0
 async def create_order(self,
                        symbol,
                        type,
                        side,
                        amount,
                        price=None,
                        params={}):
     self.check_required_dependencies()
     if self.apiKey is None:
         raise ArgumentsRequired(
             'createOrder() requires self.apiKey or userid in params')
     await self.load_markets()
     market = self.market(symbol)
     sideNum = None
     typeNum = None
     if side == 'sell':
         sideNum = 1
     else:
         sideNum = 2
     if type == 'limit':
         typeNum = 1
     else:
         typeNum = 2
         price = 0
     normalSymbol = market['normalSymbol']
     baseId = market['baseId']
     baseCurrency = self.currency(market['base'])
     amountTruncated = self.amount_to_precision(symbol, amount)
     amountTruncatedPrecise = Precise(amountTruncated)
     amountTruncatedPrecise.reduce()
     amountTruncatedPrecise.decimals -= baseCurrency['precision']
     amountChain = str(amountTruncatedPrecise)
     amountChainString = self.number_to_string(amountChain)
     quoteId = market['quoteId']
     quoteCurrency = self.currency(market['quote'])
     priceRounded = self.price_to_precision(symbol, price)
     priceRoundedPrecise = Precise(priceRounded)
     priceRoundedPrecise.reduce()
     priceRoundedPrecise.decimals -= quoteCurrency['precision']
     priceChain = str(priceRoundedPrecise)
     priceChainString = self.number_to_string(priceChain)
     now = self.milliseconds()
     expiryDelta = self.safe_integer(self.options, 'orderExpiration',
                                     31536000000)
     expiration = self.milliseconds() + expiryDelta
     datetime = self.iso8601(now)
     datetime = datetime.split('.')[0]
     expirationDatetime = self.iso8601(expiration)
     expirationDatetime = expirationDatetime.split('.')[0]
     defaultDappId = 'Sagittarius'
     dappId = self.safe_string(params, 'dappId', defaultDappId)
     defaultFee = self.safe_string(self.options, 'fee', '300000000000000')
     totalFeeRate = self.safe_string(params, 'totalFeeRate', 8)
     chainFeeRate = self.safe_string(params, 'chainFeeRate', 1)
     fee = self.safe_string(params, 'fee', defaultFee)
     eightBytes = '18446744073709551616'  # 2 ** 64
     allByteStringArray = [
         self.number_to_be(1, 32),
         self.number_to_le(int(math.floor(now / 1000)), 4),
         self.number_to_le(1, 1),
         self.number_to_le(int(math.floor(expiration / 1000)), 4),
         self.number_to_le(1, 1),
         self.number_to_le(32, 1),
         self.number_to_le(0, 8),
         self.number_to_le(fee, 8),  # string for 32 bit php
         self.number_to_le(len(self.apiKey), 1),
         self.encode(self.apiKey),
         self.number_to_le(sideNum, 1),
         self.number_to_le(typeNum, 1),
         self.number_to_le(len(normalSymbol), 1),
         self.encode(normalSymbol),
         self.number_to_le(
             Precise.string_div(amountChainString, eightBytes, 0), 8),
         self.number_to_le(
             Precise.string_mod(amountChainString, eightBytes), 8),
         self.number_to_le(
             Precise.string_div(priceChainString, eightBytes, 0), 8),
         self.number_to_le(Precise.string_mod(priceChainString, eightBytes),
                           8),
         self.number_to_le(0, 2),
         self.number_to_le(int(math.floor(now / 1000)), 4),
         self.number_to_le(int(math.floor(expiration / 1000)), 4),
         self.number_to_le(1, 1),
         self.number_to_le(int(chainFeeRate), 2),
         self.number_to_le(1, 1),
         self.number_to_le(int(totalFeeRate), 2),
         self.number_to_le(int(quoteId), 4),
         self.number_to_le(int(baseId), 4),
         self.number_to_le(0, 1),
         self.number_to_le(1, 1),
         self.number_to_le(len(dappId), 1),
         self.encode(dappId),
         self.number_to_le(0, 1),
     ]
     txByteStringArray = [
         self.number_to_le(int(math.floor(now / 1000)), 4),
         self.number_to_le(1, 1),
         self.number_to_le(int(math.floor(expiration / 1000)), 4),
         self.number_to_le(1, 1),
         self.number_to_le(32, 1),
         self.number_to_le(0, 8),
         self.number_to_le(fee, 8),  # string for 32 bit php
         self.number_to_le(len(self.apiKey), 1),
         self.encode(self.apiKey),
         self.number_to_le(sideNum, 1),
         self.number_to_le(typeNum, 1),
         self.number_to_le(len(normalSymbol), 1),
         self.encode(normalSymbol),
         self.number_to_le(
             Precise.string_div(amountChainString, eightBytes, 0), 8),
         self.number_to_le(
             Precise.string_mod(amountChainString, eightBytes), 8),
         self.number_to_le(
             Precise.string_div(priceChainString, eightBytes, 0), 8),
         self.number_to_le(Precise.string_mod(priceChainString, eightBytes),
                           8),
         self.number_to_le(0, 2),
         self.number_to_le(int(math.floor(now / 1000)), 4),
         self.number_to_le(int(math.floor(expiration / 1000)), 4),
         self.number_to_le(1, 1),
         self.number_to_le(int(chainFeeRate), 2),
         self.number_to_le(1, 1),
         self.number_to_le(int(totalFeeRate), 2),
         self.number_to_le(int(quoteId), 4),
         self.number_to_le(int(baseId), 4),
         self.number_to_le(0, 1),
         self.number_to_le(1, 1),
         self.number_to_le(len(dappId), 1),
         self.encode(dappId),
         self.number_to_le(0, 1),
     ]
     txbytestring = self.binary_concat_array(txByteStringArray)
     txidhash = self.hash(txbytestring, 'sha256', 'hex')
     txid = txidhash[0:40]
     orderidByteStringArray = [
         self.number_to_le(len(txid), 1),
         self.encode(txid),
         self.number_to_be(0, 4),
     ]
     orderidbytestring = self.binary_concat_array(orderidByteStringArray)
     orderidhash = self.hash(orderidbytestring, 'sha256', 'hex')
     orderid = orderidhash[0:40]
     bytestring = self.binary_concat_array(allByteStringArray)
     hash = self.hash(bytestring, 'sha256', 'hex')
     signature = self.ecdsa(hash, self.secret, 'secp256k1', None, True)
     recoveryParam = self.binary_to_base16(
         self.number_to_le(self.sum(signature['v'], 31), 1))
     mySignature = recoveryParam + signature['r'] + signature['s']
     operation = {
         'now': datetime,
         'expiration': expirationDatetime,
         'fee': fee,
         'creator': self.apiKey,
         'side': sideNum,
         'order_type': typeNum,
         'market_name': normalSymbol,
         'amount': amountChain,
         'price': priceChain,
         'use_btt_as_fee': False,
         'money_id': int(quoteId),
         'stock_id': int(baseId),
         'custom_no_btt_fee_rate': int(totalFeeRate),
         'custom_btt_fee_rate': int(chainFeeRate),
     }
     fatty = {
         'timestamp': datetime,
         'expiration': expirationDatetime,
         'operations': [
             [
                 32,
                 operation,
             ],
         ],
         'validate_type': 0,
         'dapp': dappId,
         'signatures': [
             mySignature,
         ],
     }
     request = {
         'trObj': self.json(fatty),
     }
     response = await self.publicPostTransactionCreateorder(request)
     timestamp = self.milliseconds()
     statusCode = self.safe_string(response, 'code')
     status = 'open' if (statusCode == '0') else 'failed'
     return {
         'info': response,
         'id': orderid,
         'timestamp': timestamp,
         'datetime': self.iso8601(timestamp),
         'lastTradeTimestamp': None,
         'status': status,
         'symbol': None,
         'type': None,
         'side': None,
         'price': None,
         'amount': None,
         'filled': None,
         'remaining': None,
         'cost': None,
         'trades': None,
         'fee': None,
         'clientOrderId': None,
         'average': None,
     }