Example #1
0
 def parse_trade(self, trade, market=None):
     timestamp = self.safe_integer_2(trade, 'time', 'createdAt')
     side = self.safe_integer_2(trade, 'side', 'order_side')
     side = 'buy' if (side == 1) else 'sell'
     symbol = None
     if market is None:
         marketId = self.safe_string(trade, 'pair')
         if marketId is None:
             baseId = self.safe_string(trade, 'coin_symbol')
             quoteId = self.safe_string(trade, 'currency_symbol')
             if (baseId is not None) and (quoteId is not None):
                 marketId = baseId + '_' + quoteId
         if marketId in self.markets_by_id:
             market = self.markets_by_id[marketId]
     if market is not None:
         symbol = market['symbol']
     fee = None
     feeCostString = self.safe_string(trade, 'fee')
     feeCurrency = self.safe_string(trade, 'fee_symbol')
     if feeCurrency is not None:
         if feeCurrency in self.currencies_by_id:
             feeCurrency = self.currencies_by_id[feeCurrency]['code']
         else:
             feeCurrency = self.safe_currency_code(feeCurrency)
     feeRate = None  # todo: deduce from market if market is defined
     priceString = self.safe_string(trade, 'price')
     amountString = self.safe_string(trade, 'amount')
     price = self.parse_number(priceString)
     amount = self.parse_number(amountString)
     cost = self.parse_number(Precise.string_mul(priceString, amountString))
     if feeCostString is not None:
         fee = {
             'cost': self.parse_number(Precise.string_neg(feeCostString)),
             'currency': feeCurrency,
             'rate': feeRate,
         }
     id = self.safe_string(trade, 'id')
     return {
         'info': trade,
         'id': id,
         'order': None,  # Bibox does not have it(documented) yet
         'timestamp': timestamp,
         'datetime': self.iso8601(timestamp),
         'symbol': symbol,
         'type': 'limit',
         'takerOrMaker': None,
         'side': side,
         'price': price,
         'amount': amount,
         'cost': cost,
         'fee': fee,
     }
Example #2
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'
Example #3
0
 def parse_order(self, order, market=None):
     # createOrder
     #     {
     #       "id": "62364648575",
     #       "text": "apiv4",
     #       "create_time": "1626354834",
     #       "update_time": "1626354834",
     #       "create_time_ms": "1626354833544",
     #       "update_time_ms": "1626354833544",
     #       "status": "open",
     #       "currency_pair": "BTC_USDT",
     #       "type": "limit",
     #       "account": "spot",
     #       "side": "buy",
     #       "amount": "0.0001",
     #       "price": "30000",
     #       "time_in_force": "gtc",
     #       "iceberg": "0",
     #       "left": "0.0001",
     #       "fill_price": "0",
     #       "filled_total": "0",
     #       "fee": "0",
     #       "fee_currency": "BTC",
     #       "point_fee": "0",
     #       "gt_fee": "0",
     #       "gt_discount": True,
     #       "rebated_fee": "0",
     #       "rebated_fee_currency": "USDT"
     #     }
     #
     id = self.safe_string(order, 'id')
     marketId = self.safe_string(order, 'currency_pair')
     symbol = self.safe_symbol(marketId, market)
     timestamp = self.safe_integer(order, 'create_time_ms')
     lastTradeTimestamp = self.safe_integer(order, 'update_time_ms')
     amount = self.safe_number(order, 'amount')
     price = self.safe_number(order, 'price')
     remaining = self.safe_number(order, 'left')
     cost = self.safe_number(order, 'filled_total')  # same as filled_price
     side = self.safe_string(order, 'side')
     type = self.safe_string(order, 'type')
     # open, closed, cancelled - almost already ccxt unified!
     status = self.safe_string(order, 'status')
     if status == 'cancelled':
         status = 'canceled'
     timeInForce = self.safe_string_upper(order, 'time_in_force')
     fees = []
     fees.append({
         'currency': 'GT',
         'cost': self.safe_number(order, 'gt_fee'),
     })
     fees.append({
         'currency':
         self.safe_currency_code(self.safe_string(order, 'fee_currency')),
         'cost':
         self.safe_number(order, 'fee'),
     })
     rebate = self.safe_string(order, 'rebated_fee')
     fees.append({
         'currency':
         self.safe_currency_code(
             self.safe_string(order, 'rebated_fee_currency')),
         'cost':
         self.parse_number(Precise.string_neg(rebate)),
     })
     return self.safe_order({
         'id': id,
         'clientOrderId': id,
         'timestamp': timestamp,
         'datetime': self.iso8601(timestamp),
         'lastTradeTimestamp': lastTradeTimestamp,
         'status': status,
         'symbol': symbol,
         'type': type,
         'timeInForce': timeInForce,
         'postOnly': None,
         'side': side,
         'price': price,
         'stopPrice': None,
         'average': None,
         'amount': amount,
         'cost': cost,
         'filled': None,
         'remaining': remaining,
         'fee': None,
         'fees': fees,
         'trades': None,
         'info': order,
     })