Skip to content

Instantly share code, notes, and snippets.

@vladthelittleone
Created February 7, 2018 10:43
Show Gist options
  • Select an option

  • Save vladthelittleone/a4d77f8e037edea6398ebc1dff195cb5 to your computer and use it in GitHub Desktop.

Select an option

Save vladthelittleone/a4d77f8e037edea6398ebc1dff195cb5 to your computer and use it in GitHub Desktop.

Revisions

  1. vladthelittleone created this gist Feb 7, 2018.
    26 changes: 26 additions & 0 deletions bot-medium-1.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    def create_dictionary(pairs):
    order_book = polo.returnOrderBook(depth=1)
    dictionary = collections.defaultdict(dict)

    for pair in pairs:
    p = pair.upper()
    src, dst = split(p)

    ask_order = order_book[p]['asks'][0]
    src_ask = {
    'pair': src + '_' + dst,
    'price': float(ask_order[0]),
    'amount': float(ask_order[1])
    }

    bid_order = order_book[p]['bids'][0]
    src_bid = {
    'pair': dst + '_' + src,
    'price': 1 / float(bid_order[0]),
    'amount': float(bid_order[1]) * float(bid_order[0])
    }

    dictionary[src][dst] = src_ask
    dictionary[dst][src] = src_bid

    return dictionary