Beispiel #1
0
 def parse_ticker(self, ticker, market=None):
     #
     # [
     #     [1640789101000, 1292663.0, 1311823.61303, 1295794.252, 1311823.61303, 0.030175],
     #     [1640790902000, 1311823.61303, 1310820.96, 1290000.0, 1290000.0, 0.042533],
     # ],
     #
     symbol = self.safe_symbol(None, market)
     timestamp = self.milliseconds()
     result = {
         'symbol': symbol,
         'timestamp': timestamp,
         'datetime': self.iso8601(timestamp),
         'high': None,
         'low': None,
         'bid': None,
         'bidVolume': None,
         'ask': None,
         'askVolume': None,
         'vwap': None,
         'open': None,
         'close': None,
         'last': None,
         'previousClose': None,
         'change': None,
         'percentage': None,
         'average': None,
         'baseVolume': None,
         'quoteVolume': None,
         'info': ticker,
     }
     tickerLength = len(ticker)
     if tickerLength > 0:
         start = max(tickerLength - 48, 0)
         for i in range(start, len(ticker)):
             candle = ticker[i]
             if result['open'] is None:
                 result['open'] = self.safe_string(candle, 1)
             high = self.safe_string(candle, 2)
             if (result['high'] is None) or (
                 (high is not None)
                     and Precise.string_lt(result['high'], high)):
                 result['high'] = high
             low = self.safe_string(candle, 3)
             if (result['low'] is None) or (
                 (low is not None)
                     and Precise.string_lt(result['low'], low)):
                 result['low'] = low
             baseVolume = self.safe_string(candle, 5)
             if result['baseVolume'] is None:
                 result['baseVolume'] = baseVolume
             else:
                 result['baseVolume'] = Precise.string_add(
                     result['baseVolume'], baseVolume)
         last = tickerLength - 1
         result['last'] = self.safe_string(ticker[last], 4)
         result['close'] = result['last']
     return self.safe_ticker(result, market, False)
Beispiel #2
0
 def parse_order(self, order, market=None):
     #
     # createOrder
     #
     #     {
     #         "result": "success",
     #         "errorCode": "0",
     #         "orderId": "8a82c561-40b4-4cb3-9bc0-9ac9ffc1d63b"
     #     }
     #
     # fetchOrder
     #
     #     {
     #         "status": "live",  # injected in fetchOrder
     #         "orderId": "32FF744B-D501-423A-8BA1-05BB6BE7814A",
     #         "currency": "BTC",
     #         "type": "bid",
     #         "price": "2922000.0",
     #         "qty": "115.4950",
     #         "remainQty": "45.4950",
     #         "feeRate": "0.0003",
     #         "fee": "0",
     #         "timestamp": "1499340941"
     #     }
     #
     # fetchOpenOrders
     #
     #     {
     #         "index": "0",
     #         "orderId": "68665943-1eb5-4e4b-9d76-845fc54f5489",
     #         "timestamp": "1449037367",
     #         "price": "444000.0",
     #         "qty": "0.3456",
     #         "type": "ask",
     #         "feeRate": "-0.0015"
     #     }
     #
     id = self.safe_string(order, 'orderId')
     priceString = self.safe_string(order, 'price')
     timestamp = self.safe_timestamp(order, 'timestamp')
     side = self.safe_string(order, 'type')
     if side == 'ask':
         side = 'sell'
     elif side == 'bid':
         side = 'buy'
     remainingString = self.safe_string(order, 'remainQty')
     amountString = self.safe_string(order, 'qty')
     status = self.safe_string(order, 'status')
     # https://github.com/ccxt/ccxt/pull/7067
     if status == 'live':
         if (remainingString is not None) and (amountString is not None):
             isLessThan = Precise.string_lt(remainingString, amountString)
             if isLessThan:
                 status = 'canceled'
     status = self.parse_order_status(status)
     symbol = None
     base = None
     quote = None
     marketId = self.safe_string_lower(order, 'currency')
     if marketId is not None:
         if marketId in self.markets_by_id:
             market = self.markets_by_id[marketId]
         else:
             base = self.safe_currency_code(marketId)
             quote = 'KRW'
             symbol = base + '/' + quote
     if (symbol is None) and (market is not None):
         symbol = market['symbol']
         base = market['base']
         quote = market['quote']
     fee = None
     feeCostString = self.safe_string(order, 'fee')
     if feeCostString is not None:
         feeCurrencyCode = quote if (side == 'sell') else base
         fee = {
             'cost': feeCostString,
             'rate': self.safe_string(order, 'feeRate'),
             'currency': feeCurrencyCode,
         }
     return self.safe_order(
         {
             'info': order,
             'id': id,
             'clientOrderId': None,
             'timestamp': timestamp,
             'datetime': self.iso8601(timestamp),
             'lastTradeTimestamp': None,
             'symbol': symbol,
             'type': 'limit',
             'timeInForce': None,
             'postOnly': None,
             'side': side,
             'price': priceString,
             'stopPrice': None,
             'cost': None,
             'average': None,
             'amount': amountString,
             'filled': None,
             'remaining': remainingString,
             'status': status,
             'fee': fee,
             'trades': None,
         }, market)
Beispiel #3
0
 def parse_ledger_entry(self, item, currency=None):
     #  {
     #      id: '12087495079',
     #      amount: '-0.0100000000000000',
     #      balance: '0.0645419900000000',
     #      created_at: '2021-10-28T17:14:32.593168Z',
     #      type: 'transfer',
     #      details: {
     #          from: '2f74edf7-1440-4586-86dc-ae58c5693691',
     #          profile_transfer_id: '3ef093ad-2482-40d1-8ede-2f89cff5099e',
     #          to: 'dda99503-4980-4b60-9549-0b770ee51336'
     #      }
     #  },
     #  {
     #     id: '11740725774',
     #     amount: '-1.7565669701255000',
     #     balance: '0.0016490047745000',
     #     created_at: '2021-10-22T03:47:34.764122Z',
     #     type: 'fee',
     #     details: {
     #         order_id: 'ad06abf4-95ab-432a-a1d8-059ef572e296',
     #         product_id: 'ETH-DAI',
     #         trade_id: '1740617'
     #     }
     #  }
     id = self.safe_string(item, 'id')
     amountString = self.safe_string(item, 'amount')
     direction = None
     afterString = self.safe_string(item, 'balance')
     beforeString = Precise.string_sub(afterString, amountString)
     if Precise.string_lt(amountString, '0'):
         direction = 'out'
         amountString = Precise.string_abs(amountString)
     else:
         direction = 'in'
     amount = self.parse_number(amountString)
     after = self.parse_number(afterString)
     before = self.parse_number(beforeString)
     timestamp = self.parse8601(self.safe_value(item, 'created_at'))
     type = self.parse_ledger_entry_type(self.safe_string(item, 'type'))
     code = self.safe_currency_code(None, currency)
     details = self.safe_value(item, 'details', {})
     account = None
     referenceAccount = None
     referenceId = None
     if type == 'transfer':
         account = self.safe_string(details, 'from')
         referenceAccount = self.safe_string(details, 'to')
         referenceId = self.safe_string(details, 'profile_transfer_id')
     else:
         referenceId = self.safe_string(details, 'order_id')
     status = 'ok'
     return {
         'id': id,
         'currency': code,
         'account': account,
         'referenceAccount': referenceAccount,
         'referenceId': referenceId,
         'status': status,
         'amount': amount,
         'before': before,
         'after': after,
         'fee': None,
         'direction': direction,
         'timestamp': timestamp,
         'datetime': self.iso8601(timestamp),
         'type': type,
         'info': item,
     }
Beispiel #4
0
 def parse_order(self, order, market=None):
     #
     #     {
     #         "Id": "string",
     #         "Status": "Unknown",
     #         "AssetPairId": "string",
     #         "Volume": 0,
     #         "Price": 0,
     #         "RemainingVolume": 0,
     #         "LastMatchTime": "2020-03-26T20:58:50.710Z",
     #         "CreatedAt": "2020-03-26T20:58:50.710Z",
     #         "Type": "Unknown",
     #         "LowerLimitPrice": 0,
     #         "LowerPrice": 0,
     #         "UpperLimitPrice": 0,
     #         "UpperPrice": 0
     #     }
     #
     status = self.parse_order_status(self.safe_string(order, 'Status'))
     marketId = self.safe_string(order, 'AssetPairId')
     symbol = self.safe_symbol(marketId, market)
     lastTradeTimestamp = self.parse8601(self.safe_string(order, 'LastMatchTime'))
     timestamp = None
     if ('Registered' in order) and (order['Registered']):
         timestamp = self.parse8601(order['Registered'])
     elif ('CreatedAt' in order) and (order['CreatedAt']):
         timestamp = self.parse8601(order['CreatedAt'])
     price = self.safe_string(order, 'Price')
     side = None
     amount = self.safe_string(order, 'Volume')
     isAmountLessThanZero = Precise.string_lt(amount, '0')
     if isAmountLessThanZero:
         side = 'sell'
         amount = Precise.string_abs(amount)
     else:
         side = 'buy'
     remaining = Precise.string_abs(self.safe_string(order, 'RemainingVolume'))
     id = self.safe_string(order, 'Id')
     return self.safe_order({
         'info': order,
         'id': id,
         'clientOrderId': None,
         'timestamp': timestamp,
         'datetime': self.iso8601(timestamp),
         'lastTradeTimestamp': lastTradeTimestamp,
         'symbol': symbol,
         'type': None,
         'timeInForce': None,
         'postOnly': None,
         'side': side,
         'price': price,
         'stopPrice': None,
         'cost': None,
         'average': None,
         'amount': amount,
         'filled': None,
         'remaining': remaining,
         'status': status,
         'fee': None,
         'trades': None,
     }, market)
assert Precise.string_max('-3.1415', '-2') == '-2'
assert Precise.string_max('0.000', '-0.0') == '0'

assert not Precise.string_gt('1.0000', '2')
assert Precise.string_gt('2', '1.2345')
assert Precise.string_gt('3.1415', '-2')
assert not Precise.string_gt('-3.1415', '-2')
assert not Precise.string_gt('3.1415', '3.1415')
assert Precise.string_gt('3.14150000000000000000001', '3.1415')

assert not Precise.string_ge('1.0000', '2')
assert Precise.string_ge('2', '1.2345')
assert Precise.string_ge('3.1415', '-2')
assert not Precise.string_ge('-3.1415', '-2')
assert Precise.string_ge('3.1415', '3.1415')
assert Precise.string_ge('3.14150000000000000000001', '3.1415')

assert Precise.string_lt('1.0000', '2')
assert not Precise.string_lt('2', '1.2345')
assert not Precise.string_lt('3.1415', '-2')
assert Precise.string_lt('-3.1415', '-2')
assert not Precise.string_lt('3.1415', '3.1415')
assert Precise.string_lt('3.1415', '3.14150000000000000000001')

assert Precise.string_le('1.0000', '2')
assert not Precise.string_le('2', '1.2345')
assert not Precise.string_le('3.1415', '-2')
assert Precise.string_le('-3.1415', '-2')
assert Precise.string_le('3.1415', '3.1415')
assert Precise.string_le('3.1415', '3.14150000000000000000001')