示例#1
0
def get_accounts(level_venue, level_account, level_stock, start, end):
    fighter = Stockfighter(level_venue, level_account)
    global balances, j
    time.sleep(5)
    uncovered = []
    for i in range(start, end):
        a = fighter.cancel(level_stock, i)['error'][-12:-1].replace(" ", "")
        if a not in j:
            if a[0].isupper():
                j.append(a)
                balances[a] = {}
                balances[a]['cash'] = 0
                balances[a]['shares'] = 0
                balances[a]['trades'] = 0
                balances[a]['nav'] = 0
                execution_ws(a)
            else:
                account = a[1:10]
                j.append(account)
                balances[account] = {}
                balances[account]['cash'] = 0
                balances[account]['shares'] = 0
                balances[account]['trades'] = 0
                balances[account]['nav'] = 0
                execution_ws(account)
        else:
            continue
    return uncovered
示例#2
0
def start_level(level):
    resp = Stockfighter.start_level(level)
    li = {}
    li['level_stock'] = str(resp['tickers'][0])
    li['level_account'] = resp['account']
    li['level_venue'] = resp['venues'][0]
    li['level_instructions'] = resp['instructions']
    li['level_id'] = resp['instanceId']
    return li
示例#3
0
文件: s2.py 项目: zz198808/tomb
#!/usr/bin/env python
# coding:utf-8
# Copyright (C) dirlt

from gevent import monkey
monkey.patch_all()
import gevent
from gevent.pool import Pool

from stockfighter import Stockfighter
import time

st = Stockfighter.start_level('chock_a_block')
ACCOUNT = st['account']
VENUE = st['venues'][0]
STOCK = st['tickers'][0]
ft = Stockfighter(VENUE, ACCOUNT)

# put 10 qty market order first manually.

def play():
    global STOCK
    price = int(raw_input('target price > '))
    size = 500
    while True:
        st = ft.order(STOCK, price, size, 'buy', 'limit')
        tid = st['id']
        while True:
            st = ft.order_status(STOCK, tid)
            filled = sum(map(lambda x: x['qty'], st['fills']))
            if filled == size:
示例#4
0
def calculate_nav():
    global a, balances
    fighter = Stockfighter(a['level_venue'], a['level_account'])
    price = fighter.quote(a['level_stock'])['last']
    for balance in balances:
            balances[balance]['nav'] = balances[balance]['cash'] + (balances[balance]['shares'] * price * .01)
示例#5
0
        fills = execution['order']['fills']
        for fill in fills:
            ts = fill['ts']
            price = fill['price']
            q = fill['qty']
            row = map(str, [account, direction, id_curr, ts, price, q])
            f.write(','.join(row) + '\n')
            f.flush()
    except Exception, e:
        print 'Could not parse execution data', str(e)

#Insert your info here
venue = ''
account = ''
stock = ''
fighter = Stockfighter(venue, account)
open_sockets = set()
p = re.compile('[A-Z]{2,}\d+')
i = 1
fname = 'data/amends.csv'
f = open(fname, 'wb')
f.write('account,direction,id,ts,price,qty\n')
f.flush()
while True:
    try:
        fighter.cancel(stock, i)
    except Exception, e:
        msg = str(e)
        matches = p.findall(msg)
        if len(matches) > 0:
            acc_tmp = matches[0]
示例#6
0
def stop_level(level):
    Stockfighter.stop_level(level)
    return
示例#7
0
pd.options.display.expand_frame_repr = False

argopts = docopt(__doc__)

# Get game informations
print ("Init game")
gm = GM()
varsgame = gm.start('first_steps')
account = varsgame['account']
venue = varsgame['venues'][0]
stock = varsgame['tickers'][0]
pause = 1 # varsgame['secondsPerTradingDay']

print ("Init stockfighter")
s = Stockfighter(venue=venue, account=account)

# Compute mini/maxi prices
stockprices = []
aloop = int(argopts['--analyze-loop'])
for i in range(0, aloop):
    # Get stock informations
    print ('.',end = "", flush=True)

    stockinfo = s.quote_for_stock(stock=stock)
    stockprices.append(stockinfo)

    time.sleep(pause)

# Print stocks result
print ('')
示例#8
0
文件: s1.py 项目: EricDoug/tomb
#!/usr/bin/env python
#coding:utf-8
#Copyright (C) dirlt

from stockfighter import Stockfighter

st = Stockfighter.start_level('first_steps')
ACCOUNT = st['account']
VENUE = st['venues'][0]
STOCK = st['tickers'][0]

ft = Stockfighter(VENUE, ACCOUNT)
st = ft.order(STOCK, 100, 100, 'buy', 'market')
print(st)
示例#9
0
from stockfighter import Stockfighter
fighter = Stockfighter('TESTEX', 'EXB123456')stock = 'FOOBAR'
if fighter.heartbeat(): print 'API is up!'
try: print 'Testing venue...',    fighter.check_venue() print '%s venue is up!' % fighter.venueexcept Stockfighter.Exception as e: print e.status_code, e.error
try: print 'Testing stock listing...',    symbols = fighter.list_stocks() print 'Stocks available at %s:' % fighter.venue,symbolsexcept Stockfighter.Exception as e: print e.status_code, e.error
try: print 'Testing orderbook...',    orderbook = fighter.orderbook(stock) print '\n\t Orderbook bids:',orderbook['bids'],'\n\t Orderbook asks:',orderbook['asks']except Stockfighter.Exception as e: print e.status_code, e.error
try: print 'Testing websocket tickers'
 def quote_ticker(quote): if quote is None:            fighter.quote_stock_ticker(quote_ticker, stock) # This will auto-restart the ticker if it dies return
 print '\t --- Quote from ticker: %s... ---\n' % str(quote)[:40],
 def execution_ticker(execution): if execution is None:            fighter.execution_stock_ticker(execution_ticker, stock) # This will auto-restart the ticker if it dies return
 print '\t --- Execution from ticker: %s... ---\n' % str(execution)[:40],
    fighter.quote_stock_ticker(quote_ticker, stock)    fighter.execution_stock_ticker(execution_ticker, stock)
except Stockfighter.Exception as e: print e.status_code, e.error
try: print 'Placing ask order...\n',    order = fighter.order(stock, 5100, 100, 'sell', 'limit') print '\t %s...\n' % str(order)[:40], print 'Placing bid order...\n',    order = fighter.order(stock, 5100, 150, 'buy', 'limit') print '\t %s...\n' % str(order)[:40],    _id = order['id']except Stockfighter.Exception as e: print e.status_code, e.error
try: print 'Testing quote...\n',    quote = fighter.quote(stock) print '\t %s...\n' % str(quote)[:40],except Stockfighter.Exception as e: print e.status_code, e.error
try: print 'Testing order status...\n',    status = fighter.order_status(stock, _id) print '\t %s...\n' % str(status)[:40]except Stockfighter.Exception as e: print e.status_code, e.error
try: print 'Testing order cancel...\n',    order = fighter.cancel(stock, _id) print '\t %s...\n' % str(order)[:40],except Stockfighter.Exception as e: print e.status_code, e.error
try: print 'Testing list all orders...\n',    orders = fighter.my_orders() print '\t %s...\n' % str(orders)[:40]except Stockfighter.Exception as e: print e.status_code, e.error
try: import time print 'Waiting for keyboard interrupt' while True:        time.sleep(1)except KeyboardInterrupt: pass
示例#10
0
文件: s3.py 项目: zz198808/tomb
#!/usr/bin/env python
# coding:utf-8
# Copyright (C) dirlt

from gevent import monkey
monkey.patch_all()
import gevent
from gevent.pool import Pool

from stockfighter import Stockfighter
import time

st = Stockfighter.start_level('sell_side')
ACCOUNT = st['account']
VENUE = st['venues'][0]
STOCK = st['tickers'][0]
ft = Stockfighter(VENUE, ACCOUNT)
示例#11
0
文件: test.py 项目: EricDoug/tomb
from stockfighter import Stockfighter

fighter = Stockfighter('TESTEX', 'EXB123456')
stock = 'FOOBAR'

if fighter.heartbeat(): print 'API is up!'

try:
    print 'Testing venue...',
    fighter.check_venue()
    print '%s venue is up!' % fighter.venue
except Stockfighter.Exception as e:
    print e.status_code, e.error

try:
    print 'Testing stock listing...',
    symbols = fighter.list_stocks()
    print 'Stocks available at %s:' % fighter.venue,symbols
except Stockfighter.Exception as e:
    print e.status_code, e.error

try:
    print 'Testing orderbook...',
    orderbook = fighter.orderbook(stock)
    print '\n\t Orderbook bids:',orderbook['bids'],'\n\t Orderbook asks:',orderbook['asks']
except Stockfighter.Exception as e:
    print e.status_code, e.error

try:
    print 'Testing websocket tickers'