Esempio n. 1
0
 def parse_order(self, order, market):
     #
     # fetchOrders / fetchOpenOrders
     #     {
     #       "id": 2605984008,
     #       "price": "55000",
     #       "amount": "0.00050000",
     #       "quantity": "0.00050000",
     #       "stopPrice": "0",
     #       "pairSymbol": "BTCUSDT",
     #       "pairSymbolNormalized": "BTC_USDT",
     #       "type": "buy",
     #       "method": "limit",
     #       "orderClientId": "f479bdb6-0965-4f03-95b5-daeb7aa5a3a5",
     #       "time": 0,
     #       "updateTime": 1618913083543,
     #       "status": "Untouched",
     #       "leftAmount": "0.00050000"
     #     }
     #
     # createOrder
     #     {
     #       "id": "2606935102",
     #       "quantity": "0.0002",
     #       "price": "56000",
     #       "stopPrice": null,
     #       "newOrderClientId": "98e5c491-7ed9-462b-9666-93553180fb28",
     #       "type": "buy",
     #       "method": "limit",
     #       "pairSymbol": "BTCUSDT",
     #       "pairSymbolNormalized": "BTC_USDT",
     #       "datetime": "1618916479523"
     #     }
     #
     id = self.safe_string(order, 'id')
     priceString = self.safe_string(order, 'price')
     precisePrice = Precise(priceString)
     price = None
     isZero = str(precisePrice) == '0'
     if not isZero:
         price = self.parse_number(precisePrice)
     amountString = self.safe_string(order, 'quantity')
     amount = self.parse_number(Precise.string_abs(amountString))
     remaining = self.safe_number(order, 'leftAmount')
     marketId = self.safe_number(order, 'pairSymbol')
     symbol = self.safe_symbol(marketId, market)
     side = self.safe_string(order, 'type')
     type = self.safe_string(order, 'method')
     clientOrderId = self.safe_string(order, 'orderClientId')
     timestamp = self.safe_integer_2(order, 'updateTime', 'datetime')
     rawStatus = self.safe_string(order, 'status')
     status = self.parse_order_status(rawStatus)
     return self.safe_order({
         'info': order,
         'id': id,
         'price': price,
         'amount': amount,
         'remaining': remaining,
         'filled': None,
         'cost': None,
         'average': None,
         'status': status,
         'side': side,
         'type': type,
         'clientOrderId': clientOrderId,
         'timestamp': timestamp,
         'datetime': self.iso8601(timestamp),
         'symbol': symbol,
         'fee': None,
     })
Esempio 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,
     }