@@ -0,0 +1,2780 @@
+import socket%0Aimport json%0A%0A#################### GLOBAL VARIABLES ####################%0Ateam_name = %22CHARLIETHEUNICORN%22%0AORDER_ID = 0%0A%0A# True if testing mode, False if production mode%0Atest_switch = False%0Aport = 25000%0A%0Aif test_switch:%0A    host_name = %22test-exch-%22 + team_name%0Aelse:%0A    host_name = %22production%22%0A%0A%0A#################### EXCHANGE CONNECTION ####################%0Adef connect():%0A    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)%0A    s.connect((host_name, port))%0A    return s.makefile('rw', 1)%0A%0Adef write_exchange(exchange, obj):%0A    json.dump(obj, exchange)%0A    exchange.write(%22%5Cn%22)%0A%0Adef read_exchange(exchange):%0A    data = exchange.readline()%0A    if(data == %22%22):%0A        return None%0A    else:%0A        return json.loads(data)%0A%0A%0A#################### TRADING ALGORITHM ####################%0Adef trade(exchange):%0A    data = read_exchange(exchange)%0A    func_list = %5Bbond_trade, bond_aggressive%5D%0A    while data:%0A        for f in func_list:%0A            buy, sell = f(data)%0A            if buy:%0A                buy_price, buy_size = buy%0A                if buy_size %3E 0:%0A                    make_trade(exchange, 'BUY', 'BOND', buy_price, buy_size)%0A            if sell:%0A                sell_price, sell_size = sell%0A                if sell_size %3E 0:%0A                    make_trade(exchange, 'SELL', 'BOND', sell_price, sell_size)%0A            data = read_exchange(exchange)%0A%0A%0Adef bond_trade(data):%0A    buy = sell = None%0A    if data%5B'type'%5D == 'book' and data%5B'symbol'%5D == 'BOND':%0A        bids = data%5B'buy'%5D%0A        sell = %5B1001, 0%5D%0A        for price, size in bids:%0A            if price %3E 1000:%0A                sell%5B1%5D += size%0A%0A        asks = data%5B'sell'%5D%0A        buy = %5B999, 0%5D%0A        for price, size in asks:%0A            if price %3C 1000:%0A                buy%5B1%5D += size%0A    return buy, sell%0A%0Adef bond_aggressive(data):%0A    buy = sell = None%0A    if data%5B'type'%5D == 'book' and data%5B'symbol'%5D == 'BOND':%0A        bids = data%5B'buy'%5D%0A        sell = %5B1005, 0%5D%0A        for price, size in bids:%0A            if price %3E 1000:%0A                sell%5B1%5D += size%0A%0A        asks = data%5B'sell'%5D%0A        buy = %5B995, 0%5D%0A        for price, size in asks:%0A            if price %3C 1000:%0A                buy%5B1%5D += size%0A    return buy, sell%0A%0Adef make_trade(exchange, buysell, symbol, price, size):%0A    write_exchange(exchange, %7B'type': 'add', 'order_id': ORDER_ID,%0A                              'symbol': symbol, 'dir': buysell, 'price': price,%0A                              'size': size%7D)%0A    global ORDER_ID%0A    ORDER_ID += 1%0A%0A%0A#################### MAIN ####################%0Adef main():%0A    exchange = connect()%0A    write_exchange(exchange, %7B%22type%22: %22hello%22, %22team%22: team_name%7D)%0A    hello_exchange = read_exchange(exchange)%0A    trade(exchange)%0A%0Aif __name__ == '__main__':%0A    while True:%0A        main()%0A

Create bot_test.py