示例#1
0
def search():
    instrument, chord = request.query.get('instrument'), request.query.get(
        'chord').strip()
    max_fingers = request.query.get('max_fingers', None)

    nchord = normalize_chord(chord.lower())

    STRINGS, CHORDS = get_instrument(instrument)
    by_diff = build_diff_dict(CHORDS)

    matches = [(n, p) for n, p in CHORDS if any(
        [n.lower() == nchord, n[:len(chord) + 1].lower() == nchord + '/'])]
    if max_fingers:
        matches = [
            (n, p) for n, p in matches
            if len(tuple(filter(lambda x: x > 0, p))) <= int(max_fingers)
        ]

    matches = [(n, p, with_same_pattern(p, by_diff)) for n, p in matches]

    return template('sresults.html',
                    title='Chord search',
                    instrument=instrument,
                    instruments=INSTRUMENT_CHOICES,
                    query=chord,
                    max_fingers=max_fingers,
                    matches_json=json.dumps(matches),
                    matches=matches,
                    strings_json=json.dumps(STRINGS))
示例#2
0
def rsearch():
    instrument, pattern = request.query.get('instrument'), request.query.get('pattern', '').strip()

    STRINGS, CHORDS = get_instrument(instrument)
    by_diff = build_diff_dict(CHORDS)

    notes = tuple(map(lambda x: int(x) if x not in 'xX' else -1, pattern.split()))

    matches = []
    if len(notes) == len(STRINGS):
        matches = [(name, patt) for name, patt in CHORDS if notes == patt]
        matches = [(n, p, with_same_pattern(p, by_diff)) for n, p in matches]

    return template(
        'rresults.html', title='Reverse search',
        instrument=instrument, instruments=INSTRUMENT_CHOICES,
        query=pattern,
        matches_json=json.dumps(matches), matches=matches,
        strings_json=json.dumps(STRINGS)
    )
示例#3
0
def search():
    instrument, chord = request.query.get('instrument'), request.query.get('chord').strip()
    max_fingers = request.query.get('max_fingers', None)

    nchord = normalize_chord(chord.lower())

    STRINGS, CHORDS = get_instrument(instrument)
    by_diff = build_diff_dict(CHORDS)

    matches = [(n, p) for n, p in CHORDS if any([n.lower() == nchord, n[:len(chord)+1].lower() == nchord+'/'])]
    if max_fingers:
        matches = [(n, p) for n, p in matches if len(tuple(filter(lambda x: x > 0, p))) <= int(max_fingers)]

    matches = [(n, p, with_same_pattern(p, by_diff)) for n, p in matches]

    return template(
        'sresults.html', title='Chord search',
        instrument=instrument, instruments=INSTRUMENT_CHOICES,
        query=chord, max_fingers=max_fingers,
        matches_json=json.dumps(matches), matches=matches,
        strings_json=json.dumps(STRINGS)
    )
示例#4
0
def rsearch():
    instrument, pattern = request.query.get('instrument'), request.query.get(
        'pattern', '').strip()

    STRINGS, CHORDS = get_instrument(instrument)
    by_diff = build_diff_dict(CHORDS)

    notes = tuple(
        map(lambda x: int(x) if x not in 'xX' else -1, pattern.split()))

    matches = []
    if len(notes) == len(STRINGS):
        matches = [(name, patt) for name, patt in CHORDS if notes == patt]
        matches = [(n, p, with_same_pattern(p, by_diff)) for n, p in matches]

    return template('rresults.html',
                    title='Reverse search',
                    instrument=instrument,
                    instruments=INSTRUMENT_CHOICES,
                    query=pattern,
                    matches_json=json.dumps(matches),
                    matches=matches,
                    strings_json=json.dumps(STRINGS))
示例#5
0
# coding=utf-8

from __future__ import print_function
import argparse

from utils import render, build_diff_dict, get_instrument, INSTRUMENT_CHOICES

if __name__ == '__main__':
    parser = argparse.ArgumentParser(description='Find chords by giving me notes')
    parser.add_argument('notes', nargs='+',
                        help='space separated notes: start from 1st string (E on guitar). '
                             'Use "0" for open string and "x" for not played string.')
    parser.add_argument('-i', '--instrument', dest='instrument',
                        choices=INSTRUMENT_CHOICES.keys(), default='mando',
                        help='instrument/tuning to search')
    args = parser.parse_args()

    STRINGS, CHORDS = get_instrument(args.instrument)
    by_diff = build_diff_dict(CHORDS)

    if len(args.notes) != len(STRINGS):
        raise ValueError('You have provided less or more notes. %s has %d strings.' %
                         (args.instrument.capitalize(), len(STRINGS)))

    notes = tuple(map(lambda x: int(x) if x != 'x' else -1, args.notes))
    matches = [name for name, patt in CHORDS if notes == patt]

    if matches:
        render(notes, STRINGS)
        print('\nIs known as: %s\n' % ', '.join(matches))
示例#6
0
                POS_TABLE[symbol]['updateOrderQty'] = True  # toggle updateOrder boolean, need to modify stop_loss order quantity
                print('Position Update: {} {} Realised PnL: {real_pnl:.8f}'.format(symbol, POS_TABLE[symbol]['remain_qty'], real_pnl=real_pnl*0.00000001))
                if isOrderInTransit: isOrderInTransit = False


    
if __name__ == "__main__":
    symbol = 'XBTUSD'   # default symbol XBTUSD
    if len(sys.argv) >= 2: symbol = sys.argv[1]                # >>> python app.py ETHUSD
    if len(sys.argv) >= 3: PCT_RISK_PER_TRADE = float(sys.argv[2])    # >>> python app.py ETHUSD 0.015

    client = bitmex.bitmex(test=False, api_key=api_key, api_secret=api_secret)
    ref_price = client.Instrument.Instrument_get(symbol=symbol).result()[0][0]['vwap']
    MARGIN_BALANCE = client.User.User_getMargin().result()[0]['marginBalance'] * 0.00000001
    RISK_BTC = MARGIN_BALANCE * PCT_RISK_PER_TRADE     # risk (i.e. stop loss) btc amount: btc_amount x percentage
    TICK_SIZE = get_instrument(symbol)['tickSize']
    print('balance in btc:', MARGIN_BALANCE)
    print('RISK_BTC:', RISK_BTC)

    TRADE_SIZING = {'ref_price':ref_price, 'MARGIN_BALANCE':MARGIN_BALANCE, 'RISK_BTC':RISK_BTC, 'TICK_SIZE':TICK_SIZE}

    data_df = None
    i = -1      # counter purposely starts from -1
    ORDER_QUEUE = Queue()   # order queue for multiprocessing
    POS_TABLE = dict()      # symbol as key, include 'timestamp', 'side', 'entry_price' and 'stop_loss'
    isOrderInTransit = False   # IMPORTANT - prevent sending same order multiple times!!!


    logger = setup_logger()

    # Instantiating the WS will make it connect. Be sure to add your api_key/api_secret.
示例#7
0
if __name__ == '__main__':
    parser = argparse.ArgumentParser(
        description='Find chords by giving me notes')
    parser.add_argument(
        'notes',
        nargs='+',
        help='space separated notes: start from 1st string (E on guitar). '
        'Use "0" for open string and "x" for not played string.')
    parser.add_argument('-i',
                        '--instrument',
                        dest='instrument',
                        choices=INSTRUMENT_CHOICES.keys(),
                        default='mando',
                        help='instrument/tuning to search')
    args = parser.parse_args()

    STRINGS, CHORDS = get_instrument(args.instrument)
    by_diff = build_diff_dict(CHORDS)

    if len(args.notes) != len(STRINGS):
        raise ValueError(
            'You have provided less or more notes. %s has %d strings.' %
            (args.instrument.capitalize(), len(STRINGS)))

    notes = tuple(map(lambda x: int(x) if x != 'x' else -1, args.notes))
    matches = [name for name, patt in CHORDS if notes == patt]

    if matches:
        render(notes, STRINGS)
        print('\nIs known as: %s\n' % ', '.join(matches))