Beispiel #1
0
 def parse_trade(self, trade, market=None):
     #
     # fetchTrades
     #     {
     #       "pair": "BTCUSDT",
     #       "pairNormalized": "BTC_USDT",
     #       "numerator": "BTC",
     #       "denominator": "USDT",
     #       "date": "1618916879083",
     #       "tid": "637545136790672520",
     #       "price": "55774",
     #       "amount": "0.27917100",
     #       "side": "buy"
     #     }
     #
     # fetchMyTrades
     #     {
     #       "price": "56000",
     #       "numeratorSymbol": "BTC",
     #       "denominatorSymbol": "USDT",
     #       "orderType": "buy",
     #       "orderId": "2606935102",
     #       "id": "320874372",
     #       "timestamp": "1618916479593",
     #       "amount": "0.00020000",
     #       "fee": "0",
     #       "tax": "0"
     #     }
     #
     timestamp = self.safe_integer_2(trade, 'date', 'timestamp')
     id = self.safe_string_2(trade, 'tid', 'id')
     order = self.safe_string(trade, 'orderId')
     priceString = self.safe_string(trade, 'price')
     amountString = Precise.string_abs(self.safe_string(trade, 'amount'))
     marketId = self.safe_string(trade, 'pair')
     symbol = self.safe_symbol(marketId, market)
     side = self.safe_string_2(trade, 'side', 'orderType')
     fee = None
     feeAmountString = self.safe_string(trade, 'fee')
     if feeAmountString is not None:
         feeCurrency = self.safe_string(trade, 'denominatorSymbol')
         fee = {
             'cost': Precise.string_abs(feeAmountString),
             'currency': self.safe_currency_code(feeCurrency),
         }
     return self.safe_trade({
         'info': trade,
         'id': id,
         'order': order,
         'timestamp': timestamp,
         'datetime': self.iso8601(timestamp),
         'symbol': symbol,
         'type': None,
         'side': side,
         'takerOrMaker': None,
         'price': priceString,
         'amount': amountString,
         'cost': None,
         'fee': fee,
     }, market)
Beispiel #2
0
 def parse_trade(self, trade, market=None):
     #
     # fetchTrades(public)
     #
     #     {
     #         "timestamp": "1416893212",
     #         "price": "420000.0",
     #         "qty": "0.1",
     #         "is_ask": "1"
     #     }
     #
     # fetchMyTrades(private)
     #
     #     {
     #         "timestamp": "1416561032",
     #         "price": "419000.0",
     #         "type": "bid",
     #         "qty": "0.001",
     #         "feeRate": "-0.0015",
     #         "fee": "-0.0000015",
     #         "orderId": "E84A1AC2-8088-4FA0-B093-A3BCDB9B3C85"
     #     }
     #
     timestamp = self.safe_timestamp(trade, 'timestamp')
     market = self.safe_market(None, market)
     is_ask = self.safe_string(trade, 'is_ask')
     side = self.safe_string(trade, 'type')
     if is_ask is not None:
         if is_ask == '1':
             side = 'sell'
         elif is_ask == '0':
             side = 'buy'
     else:
         if side == 'ask':
             side = 'sell'
         elif side == 'bid':
             side = 'buy'
     priceString = self.safe_string(trade, 'price')
     amountString = self.safe_string(trade, 'qty')
     orderId = self.safe_string(trade, 'orderId')
     feeCostString = self.safe_string(trade, 'fee')
     fee = None
     if feeCostString is not None:
         feeCostString = Precise.string_abs(feeCostString)
         feeRateString = self.safe_string(trade, 'feeRate')
         feeRateString = Precise.string_abs(feeRateString)
         feeCurrencyCode = market['quote'] if (
             side == 'sell') else market['base']
         fee = {
             'cost': feeCostString,
             'currency': feeCurrencyCode,
             'rate': feeRateString,
         }
     return self.safe_trade(
         {
             'id': self.safe_string(trade, 'id'),
             'info': trade,
             'timestamp': timestamp,
             'datetime': self.iso8601(timestamp),
             'order': orderId,
             'symbol': market['symbol'],
             'type': None,
             'side': side,
             'takerOrMaker': None,
             'price': priceString,
             'amount': amountString,
             'cost': None,
             'fee': fee,
         }, market)
Beispiel #3
0
 def parse_trade(self, trade, market=None):
     #
     # fetchTrades(public)
     #
     #      {
     #          "book": "btc_usdt",
     #          "created_at": "2021-11-24T12:14:53+0000",
     #          "amount": "0.00026562",
     #          "maker_side": "sell",
     #          "price": "56471.55",
     #          "tid": "52557338"
     #      }
     #
     # fetchMyTrades(private)
     #
     #      {
     #          "book": "btc_usdt",
     #          "created_at": "2021-11-24T12:31:03+0000",
     #          "minor": "11.30356000",
     #          "major": "-0.00020000",
     #          "fees_amount": "0.01119052",
     #          "fees_currency": "usdt",
     #          "minor_currency": "usdt",
     #          "major_currency": "btc",
     #          "oid": "djTzMIWx2Vi3iMjl",
     #          "tid": "52559051",
     #          "price": "56517.80",
     #          "side": "sell",
     #          "maker_side": "buy"
     #      }
     #
     # fetchOrderTrades(private)
     #
     #      {
     #          "book": "btc_usdt",
     #          "created_at": "2021-11-24T12:30:52+0000",
     #          "minor": "-11.33047916",
     #          "major": "0.00020020",
     #          "fees_amount": "0.00000020",
     #          "fees_currency": "btc",
     #          "minor_currency": "usdt",
     #          "major_currency": "btc",
     #          "oid": "O0D2zcljjjQF5xlG",
     #          "tid": "52559030",
     #          "price": "56595.80",
     #          "side": "buy",
     #          "maker_side": "sell"
     #      }
     #
     timestamp = self.parse8601(self.safe_string(trade, 'created_at'))
     marketId = self.safe_string(trade, 'book')
     symbol = self.safe_symbol(marketId, market, '_')
     side = self.safe_string_2(trade, 'side', 'maker_side')
     makerSide = self.safe_string(trade, 'maker_side')
     takerOrMaker = None
     if side == makerSide:
         takerOrMaker = 'maker'
     else:
         takerOrMaker = 'taker'
     amount = self.safe_string_2(trade, 'amount', 'major')
     if amount is not None:
         amount = Precise.string_abs(amount)
     fee = None
     feeCost = self.safe_string(trade, 'fees_amount')
     if feeCost is not None:
         feeCurrencyId = self.safe_string(trade, 'fees_currency')
         feeCurrency = self.safe_currency_code(feeCurrencyId)
         fee = {
             'cost': feeCost,
             'currency': feeCurrency,
         }
     cost = self.safe_string(trade, 'minor')
     if cost is not None:
         cost = Precise.string_abs(cost)
     price = self.safe_string(trade, 'price')
     orderId = self.safe_string(trade, 'oid')
     id = self.safe_string(trade, 'tid')
     return self.safe_trade({
         'id': id,
         'info': trade,
         'timestamp': timestamp,
         'datetime': self.iso8601(timestamp),
         'symbol': symbol,
         'order': orderId,
         'type': None,
         'side': side,
         'takerOrMaker': takerOrMaker,
         'price': price,
         'amount': amount,
         'cost': cost,
         'fee': fee,
     }, market)
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)
Beispiel #5
0
 def parse_trade(self, trade, market):
     #
     #  public fetchTrades
     #
     #   {
     #     "id": "d5983ab8-e9ec-48c9-bdd0-1b18f8e80a71",
     #     "assetPairId": "BTCUSD",
     #     "dateTime": "2019-05-15T06:52:02.147Z",
     #     "volume": 0.00019681,
     #     "index": 0,
     #     "price": 8023.333,
     #     "action": "Buy"
     #   }
     #
     #  private fetchMyTrades
     #     {
     #         Id: '3500b83c-9963-4349-b3ee-b3e503073cea',
     #         OrderId: '83b50feb-8615-4dc6-b606-8a4168ecd708',
     #         DateTime: '2020-05-19T11:17:39.31+00:00',
     #         Timestamp: '2020-05-19T11:17:39.31+00:00',
     #         State: null,
     #         Amount: -0.004,
     #         BaseVolume: -0.004,
     #         QuotingVolume: 39.3898,
     #         Asset: 'BTC',
     #         BaseAssetId: 'BTC',
     #         QuotingAssetId: 'USD',
     #         AssetPair: 'BTCUSD',
     #         AssetPairId: 'BTCUSD',
     #         Price: 9847.427,
     #         Fee: {Amount: null, Type: 'Unknown', FeeAssetId: null}
     #     },
     marketId = self.safe_string(trade, 'AssetPairId')
     symbol = self.safe_symbol(marketId, market)
     id = self.safe_string_2(trade, 'id', 'Id')
     orderId = self.safe_string(trade, 'OrderId')
     timestamp = self.parse8601(self.safe_string_2(trade, 'dateTime', 'DateTime'))
     priceString = self.safe_string_2(trade, 'price', 'Price')
     amountString = self.safe_string_2(trade, 'volume', 'Amount')
     side = self.safe_string_lower(trade, 'action')
     if side is None:
         side = 'sell' if (amountString[0] == '-') else 'buy'
     amountString = Precise.string_abs(amountString)
     price = self.parse_number(priceString)
     amount = self.parse_number(amountString)
     cost = self.parse_number(Precise.string_mul(priceString, amountString))
     fee = {
         'cost': 0,  # There are no fees for trading. https://www.lykke.com/wallet-fees-and-limits/
         'currency': market['quote'],
     }
     return {
         'id': id,
         'info': trade,
         'timestamp': timestamp,
         'datetime': self.iso8601(timestamp),
         'symbol': symbol,
         'type': None,
         'order': orderId,
         'side': side,
         'takerOrMaker': None,
         'price': price,
         'amount': amount,
         'cost': cost,
         'fee': fee,
     }
Beispiel #6
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,
     })
Beispiel #7
0
 def parse_bid_ask(self, bidask, priceKey=0, amountKey=1):
     price = self.safe_string(bidask, priceKey)
     amount = Precise.string_abs(self.safe_string(bidask, amountKey))
     return [self.parse_number(price), self.parse_number(amount)]
Beispiel #8
0
assert Precise.string_add(w, z) == '-0.000001123'
assert Precise.string_add(x, z) == '0.00000002'
assert Precise.string_add(y, z) == '69696900000'

assert Precise.string_mul(x, a) == '2'
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'
Beispiel #9
0
 def parse_order(self, order, market=None):
     #
     #     {
     #         "symbol": "BTC/USD",
     #         "orderId": "00000000-0000-0000-0000-0000000c0263",
     #         "clientOrderId": "00000000-0000-0000-0000-0000000c0263",
     #         "transactTime": 1589878206426,
     #         "price": "9825.66210000",
     #         "origQty": "0.01",
     #         "executedQty": "0.01",
     #         "status": "FILLED",
     #         "timeInForce": "FOK",
     #         "type": "MARKET",
     #         "side": "BUY",
     #         "fills": [
     #             {
     #                 "price": "9807.05",
     #                 "qty": "0.01",
     #                 "commission": "0",
     #                 "commissionAsset": "dUSD"
     #             }
     #         ]
     #     }
     #
     status = self.parse_order_status(self.safe_string(order, 'status'))
     marketId = self.safe_string(order, 'symbol')
     symbol = self.safe_symbol(marketId, market, '/')
     timestamp = None
     if 'time' in order:
         timestamp = self.safe_integer(order, 'time')
     elif 'transactTime' in order:
         timestamp = self.safe_integer(order, 'transactTime')
     price = self.safe_string(order, 'price')
     amount = self.safe_string(order, 'origQty')
     filled = Precise.string_abs(self.safe_string(order, 'executedQty'))
     cost = self.safe_string(order, 'cummulativeQuoteQty')
     id = self.safe_string(order, 'orderId')
     type = self.safe_string_lower(order, 'type')
     side = self.safe_string_lower(order, 'side')
     fills = self.safe_value(order, 'fills')
     timeInForce = self.safe_string(order, 'timeInForce')
     return self.safe_order(
         {
             'info': order,
             'id': id,
             'timestamp': timestamp,
             'datetime': self.iso8601(timestamp),
             'lastTradeTimestamp': None,
             'symbol': symbol,
             'type': type,
             'timeInForce': timeInForce,
             'side': side,
             'price': price,
             'stopPrice': None,
             'amount': amount,
             'cost': cost,
             'average': None,
             'filled': filled,
             'remaining': None,
             'status': status,
             'fee': None,
             'trades': fills,
         }, market)
Beispiel #10
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,
     }