예제 #1
0
def norm_old_order(rows, ctx, opts):
    # OrderUuid,Exchange,Type,Quantity,Limit,CommissionPaid,Price,Opened,Closed
    rid = rows[0]
    dt = parse_datetime(rows[8])

    mo = re.match('^([A-Z]+)-([A-Z]+)$', rows[1])
    if mo is None:
        raise RuntimeError('malformed currency pair: ' + rows[1])
    quote = coinname(mo.group(2))
    base = coinname(mo.group(1))

    r_quote = cctaxjp.Record(dt, 'Bittrex', rid, cctaxjp.RecordType.EXCHANGE,
                             quote, rows[3])
    r_base = cctaxjp.Record(dt,
                            'Bittrex',
                            rid,
                            cctaxjp.RecordType.EXCHANGE,
                            base,
                            rows[6],
                            exfee="-" + rows[5])
    if rows[2] == 'LIMIT_BUY':
        r_base.amount = -r_base.amount
    elif rows[2] == 'LIMIT_SELL':
        r_quote.amount = -r_quote.amount
    else:
        raise RuntimeError('unknown OrderType: ' + rows[2])
    records = [r_quote, r_base] if 0 <= r_quote.amount else [r_base, r_quote]
    return records, ctx
예제 #2
0
def norm_order(rows, ctx, opts):
    # Uuid,Exchange,TimeStamp,OrderType,Limit,Quantity,QuantityRemaining,Commission,Price,PricePerUnit,IsConditional,Condition,ConditionTarget,ImmediateOrCancel,Closed,TimeInForceTypeId,TimeInForce
    # xxxxxxx,BTC-ETH,9/3/2017 1:32:23 PM,LIMIT_BUY,0.08160003,11.55944700,0.00000000,0.00235806,0.94325109,0.08160002,False,,0.00000000,False,8/1/2017 1:33:51 PM,0,

    rid = rows[0]
    dt = parse_datetime(rows[14])

    mo = re.match('^([A-Z]+)-([A-Z]+)$', rows[1])
    if mo is None:
        raise RuntimeError('malformed currency pair: ' + rows[1])
    quote = coinname(mo.group(2))
    base = coinname(mo.group(1))

    r_quote = cctaxjp.Record(dt, 'Bittrex', rid, cctaxjp.RecordType.EXCHANGE,
                             quote,
                             Decimal(rows[5]) - Decimal(rows[6]))
    r_base = cctaxjp.Record(dt,
                            'Bittrex',
                            rid,
                            cctaxjp.RecordType.EXCHANGE,
                            base,
                            rows[8],
                            exfee="-" + rows[7])
    if rows[3] == 'LIMIT_BUY':
        r_base.amount = -r_base.amount
    elif rows[3] == 'LIMIT_SELL':
        r_quote.amount = -r_quote.amount
    else:
        raise RuntimeError('unknown OrderType: ' + rows[3])
    records = [r_quote, r_base] if 0 <= r_quote.amount else [r_base, r_quote]
    return records, ctx
예제 #3
0
def norm_trade(rows, ctx, opts):
    # Date,Market,Category,Type,Price,Amount,Total,Fee,Order Number,Base Total Less Fee,Quote Total Less Fee,Fee Currency,Fee Total
    # 2017-03-09 00:11:22,BTC/USDT,Exchange,Buy,8064.00000000,0.11359561,916.03499904,0.25%,111641538829,-916.03499904,0.11331162,BTC,2.29008749
    dt = parse_datetime(rows[0])
    mo = re.match('^([A-Z]+)\/([A-Z]+)$', rows[1])
    if mo is None:
        raise RuntimeError('unknown currency pair: ' + rows[1])
    quote = coinname(mo.group(1))
    base = coinname(mo.group(2))

    mo = re.match('^([0-9]*(\.[0-9]*)?)\%$', rows[7])
    if mo is None:
        raise RuntimeError('malformed fee value: ' + rows[7])
    fee_rate = Decimal(mo.group(1)) / 100

    r_quote = cctaxjp.Record(dt, 'Poloniex', rows[8], cctaxjp.RecordType.EXCHANGE, quote)
    r_base  = cctaxjp.Record(dt, 'Poloniex', rows[8], cctaxjp.RecordType.EXCHANGE, base)
    if rows[3] == 'Buy':
        r_quote.amount = Decimal(rows[5])
        r_base.amount  = -Decimal(rows[6])
        r_quote.exfee = -(r_quote.amount * fee_rate).quantize(Decimal('1.0E-7'), ROUND_DOWN)
    else:
        r_quote.amount = -Decimal(rows[5])
        r_base.amount  = Decimal(rows[6])
        r_base.exfee   = -(r_base.amount * fee_rate).quantize(Decimal('1.0E-7'), ROUND_DOWN)
    records = [ r_quote, r_base ] if 0 <= r_quote.amount else [ r_base, r_quote ]
    return records, ctx
예제 #4
0
def normalize(rows, ctx, opts):
    # "Txhash","Blockno","UnixTimestamp","DateTime","From","To","ContractAddress","Value_IN(ETH)","Value_OUT(ETH)","CurrentValue @ $592.43/Eth","TxnFee(ETH)","TxnFee(USD)","Historical $Price/Eth","Status","ErrCode"

    dt = parse_datetime(rows[3])

    if rows[13] == '':
        records = []
        r_in = cctaxjp.Record(dt, 'Etherscan', rows[0],
                              cctaxjp.RecordType.DEPOSIT, cctaxjp.CoinName.ETH,
                              rows[7])
        if r_in.amount != 0: records.append(r_in)

        r_ou = cctaxjp.Record(dt,
                              'Etherscan',
                              rows[0],
                              cctaxjp.RecordType.WITHDRAWAL,
                              cctaxjp.CoinName.ETH,
                              "-" + rows[8],
                              exfee="-" + rows[10])
        if r_ou.amount != 0 or r_ou.exfee != 0: records.append(r_ou)
    else:
        r_err = cctaxjp.Record(dt,
                               'Etherscan',
                               rows[0],
                               cctaxjp.RecordType.WITHDRAWAL,
                               cctaxjp.CoinName.ETH,
                               exfee="-" + rows[10])
        records = [r_err]
    return records, ctx
예제 #5
0
def normalize(rows, ctx, opts):
    dt = parse_datetime(rows[0])

    if rows[2] in ['Buy', 'Sell', 'Fee']:
        pairs = [] if ctx is None else ctx
        i = next((i for i, p in enumerate(pairs) if p[rows[2]] is None), None)
        if i is None:
            i = len(pairs)
            pairs.append({
                'datetime': dt,
                'Buy': None,
                'Sell': None,
                'Fee': None
            })
        p = pairs[i]
        p[rows[2]] = (coinname(rows[3]), rows[4])  # (coin, amount(string))
        records = []
        if (i == 0) and (p['Buy'] is not None) and (
                p['Sell'] is not None) and (p['Fee'] is not None):
            pairs.pop(0)
            buy = cctaxjp.Record(dt, 'Binance', '',
                                 cctaxjp.RecordType.EXCHANGE, p['Buy'][0],
                                 d(p['Buy'][1]))
            if p['Fee'] is not None: buy.exfee = d(p['Fee'][1])
            sell = cctaxjp.Record(dt, 'Binance', '',
                                  cctaxjp.RecordType.EXCHANGE, p['Sell'][0],
                                  d(p['Sell'][1]))
            records = [buy, sell]
        return records, pairs

    elif rows[2] == 'Deposit':
        r = cctaxjp.Record(dt, 'Binance', '', cctaxjp.RecordType.DEPOSIT,
                           rows[3], d(rows[4]))
        return [r], ctx
    elif rows[2] == 'Withdraw':
        r = cctaxjp.Record(dt, 'Binance', '', cctaxjp.RecordType.WITHDRAWAL,
                           rows[3], d(rows[4]))
        return [r], ctx
    elif rows[2] == 'Small assets exchange BNB':
        if opts['debug']:
            print("Skip BNB exchange because it maybe merged at line %d" %
                  line)
        return [], ctx
    elif rows[2] == 'Adjust':
        r = cctaxjp.Record(dt, 'Binance', '', cctaxjp.RecordType.ADJUST,
                           rows[3], d(rows[4]))
        return [r], ctx
    else:
        raise RuntimeError("unknown record type %s at %d" % (rows[2], line))
예제 #6
0
def norm_trade(rows, ctx, opts):
    # "transactTime","symbol","execType","side","lastQty","lastPx","execCost","commission","execComm","ordType","orderQty","leavesQty","price","text","orderID"
    rid = rows[14]
    dt = parse_datetime(rows[0])
    quote, base = parse_symbol(rows[1])

    rtype = parse_execType(rows[2])
    r_quote = cctaxjp.Record(dt, 'Bittrex', rid, rtype, quote, rows[6])
    r_base  = cctaxjp.Record(dt, 'Bittrex', rid, rtype, base, rows[6])
    r_fee   = cctaxjp.Record(dt, 'Bittrex', rid, cctaxjp.RecordType.EXFEE, cctaxjp.RecordType.BTC, rows[8] * Decimal('1e-8'))
    if rows[2] == 'LIMIT_BUY':
        r_base.amount = -r_base.amount
    elif rows[2] == 'LIMIT_SELL':
        r_quote.amount = -r_quote.amount
    else:
        raise RuntimeError('unknown OrderType: ' + rows[2])
    records = [ r_quote, r_base ] if 0 <= r_quote.amount else [ r_base, r_quote ]
    return records, ctx
예제 #7
0
def normalize(rows, ctx, opts):
    # "Txhash","Blockno","UnixTimestamp","DateTime","From","To","ContractAddress","Value_IN(ETH)","Value_OUT(ETH)","CurrentValue @ $592.43/Eth","TxnFee(ETH)","TxnFee(USD)","Historical $Price/Eth","Status","ErrCode"

    dt = parse_datetime(rows[3])

    r_in = cctaxjp.Record(dt,
                          'Etherscan',
                          rows[0],
                          cctaxjp.RecordType.TRANSFER,
                          cctaxjp.RecordType.ETH,
                          exfee=rows[10])
    r_ou = cctaxjp.Record(dt, 'Etherscan', rows[0],
                          cctaxjp.RecordType.TRANSFER, cctaxjp.RecordType.ETH)
    if rows[13] == '':
        if rows[7] != '': r_in.amount = Decimal(rows[7])
        if rows[8] != '': r_ou.amount = -Decimal(rows[8])
        records = [r_in, r_ou]
    else:
        records = [r_in]
    return records, ctx
예제 #8
0
def norm_custom(rows, ctx, opts):
    # datetime,currency,amount,infee,exfee,custom comment
    # 2020-02-28,MikuExchange,DEPOSIT,BTC,0.939393939,example data
    dt = datetime.strptime(rows[0], "%Y-%m-%d %H:%M:%S%z")
    rtype = cctaxjp.RecordType.check_value(rows[2])
    coin = cctaxjp.CoinName.check_value(rows[3])
    r = cctaxjp.Record(dt,
                       rows[1],
                       None,
                       rtype,
                       coin,
                       rows[4],
                       infee=rows[5],
                       exfee=rows[6])
    return [r], ctx
예제 #9
0
def normalize(rows, ctx, opts):
    r = cctaxjp.Record(datetime=parse_datetime(rows[5]),
                       source='Bitfinex',
                       rid=rows[0],
                       coin=coinname(rows[2]))
    amount = Decimal(rows[3])
    if re.match('^Trading fees ', rows[1]):
        r.rtype = cctaxjp.RecordType.EXFEE
        r.fee = amount
    elif re.match('^Exchange ', rows[1]):
        r.rtype = cctaxjp.RecordType.EXCHANGE
        r.amount = amount
    elif re.match('^Deposit ', rows[1]):
        r.rtype = cctaxjp.RecordType.DEPOSIT
        r.amount = amount
    elif re.match('^Withdraw ', rows[1]):
        r.rtype = cctaxjp.RecordType.WITHDRAW
        r.amount = amount
    elif re.match('^Settlement ', rows[1]):
        r.rtype = cctaxjp.RecordType.SETTLEMENT
        r.amount = amount
    else:
        raise RuntimeError("unknown record type at line {}".format(line))
    return [r], ctx
예제 #10
0
def norm_withdrawal(rows, ctx, opts):
    # Date,Currency,Amount,Fee Deducted,Amount - Fee,Address,Status
    # 2017-03-09 11:22:33,BTC,0.20000000,0.00050000,0.1995,3FZQ...,COMPLETE: 7092...
    dt = parse_datetime(rows[0])
    r = cctaxjp.Record(dt, 'Poloniex', None, cctaxjp.RecordType.WITHDRAWAL, coinname(rows[1]), "-"+rows[2], infee="-"+rows[3])
    return [r], ctx
예제 #11
0
def norm_deposit(rows, ctx, opts):
    # Date,Currency,Amount,Address,Status
    # 2017-03-09 11:22:33,ZEC,0.00046672,t1ZYy...,COMPLETE
    dt = parse_datetime(rows[0])
    r = cctaxjp.Record(dt, 'Poloniex', None, cctaxjp.RecordType.DEPOSIT, coinname(rows[1]), rows[2])
    return [r], ctx
예제 #12
0
def norm_lending(rows, ctx, opts):
    # Currency,Rate,Amount,Duration,Interest,Fee,Earned,Open,Close
    # BTC,0.00008100,0.00131978,2.00032407,0.00000021,-0.00000003,0.00000018,2020-03-09 05:41:17,2020-03-11 05:41:45
    dt = parse_datetime(rows[8])
    r = cctaxjp.Record(dt, 'Poloniex', None, cctaxjp.RecordType.LENDING, coinname(rows[0]), rows[4], exfee=rows[5])
    return [r], ctx
예제 #13
0
def norm_distribution(rows, ctx, opts):
    # date,currency,amount,wallet
    # 2020-02-28,BTT,500.00000000,exchange
    dt = parse_datetime(rows[0] + ' 00:00:00')
    r = cctaxjp.Record(dt, 'Poloniex', None, cctaxjp.RecordType.AIRDROP, coinname(rows[1]), rows[2])
    return [r], ctx