def execute_randomly_forever(verbose = False):

    INFO = sf.Order()

    INFO.account = ACCOUNT
    INFO.venue = VENUE
    INFO.symbol = SYMBOL

    while 1:
        INFO.price = random.randint(4000, 6000)
        INFO.qty = random.randint(1, 100)
        INFO.orderType = random.choice(["limit", "limit", "limit", "limit", "market", "immediate-or-cancel", "fill-or-kill"])
        INFO.direction = random.choice(["buy", "sell"])
        
        result = sf.execute(INFO, verbose = verbose)
def clear_the_books():
    global INFO
    
    INFO.qty = 999999
    INFO.orderType = "market"
    INFO.direction = "buy"
    INFO.price = 1

    set_from_account_1(INFO)
    sf.execute(INFO)
    set_from_account_2(INFO)
    sf.execute(INFO)

    INFO.direction = "sell"

    set_from_account_1(INFO)
    sf.execute(INFO)
    set_from_account_2(INFO)
    sf.execute(INFO)

    # Set the last price and size...

    INFO.orderType = "limit"
    INFO.price = 5000
    INFO.qty = 50
    INFO.direction = "sell"

    set_from_account_1(INFO)
    sf.execute(INFO)
    set_from_account_2(INFO)
    sf.execute(INFO)

    INFO.direction = "buy"

    set_from_account_1(INFO)
    sf.execute(INFO)
    set_from_account_2(INFO)
    sf.execute(INFO)
    set_from_account_2(INFO)
    sf.execute(INFO)



clear_the_books()


for n in range(TEST_SIZE):
    INFO.price = random.randint(1, 20)
    INFO.qty = random.randint(1, 20)
    INFO.direction = random.choice(["buy", "sell"])
    INFO.orderType = random.choice(["limit", "limit", "limit", "limit", "market", "immediate-or-cancel", "fill-or-kill"])
    
    set_from_account_1(INFO)
    res1 = sf.execute(INFO)
    id1 = res1["id"]
    if n == 0:
        first_id_1 = id1
    if n == TEST_SIZE - 1:
        last_id_1 = id1
    q1 = sf.quote(INFO.venue, INFO.symbol)
    o1 = sf.orderbook(INFO.venue, INFO.symbol)
        
    set_from_account_2(INFO)
    res2 = sf.execute(INFO)
    id2 = res2["id"]
    if n == 0:
        first_id_2 = id2
    if n == TEST_SIZE - 1:
        last_id_2 = id2
order.venue = "TESTEX"
order.symbol = "FOOBAR"

print("Reported last trade: (should be 96 @ 360, but sometimes is 5 @ 237)")

while 1:

	# Clear the book.......................

	order.orderType = "market"

	order.direction = "sell"
	order.qty = 999999
	order.price = 1

	sf.execute(order)

	order.direction = "buy"
	order.qty = 999999
	order.price = 1

	sf.execute(order)

	# -------------------------------------

	order.orderType = "limit"

	order.direction = "sell"
	order.qty = 5
	order.price = 237
Exemple #5
0

INFO = sf.Order()

INFO.account = ACCOUNT
INFO.venue = VENUE
INFO.symbol = SYMBOL

# Clear the book...

INFO.qty = 9999999
INFO.orderType = "market"
INFO.direction = "buy"
INFO.price = 0

sf.execute(INFO)

INFO.direction = "sell"
sf.execute(INFO)

starttime = time.clock()
n = 0

print("Running for {} seconds...".format(TEST_TIME))

while 1:
	INFO.price = random.randint(1, 5000)
	INFO.qty = random.randint(1, 100)
	INFO.direction = random.choice(["buy", "sell"])
	INFO.orderType = random.choice(["limit", "limit", "limit", "limit", "market", "immediate-or-cancel", "fill-or-kill"])
	res = sf.execute(INFO)