def kutSendBatch(notional, batchSize, batchN, ccyData, kutSide, realizedSlippageBps_all): ccy=ccyData.ccy SHARED_CCY_DICT[ccy] = {'futExch': ['ftx', 'kut']} CT_CONFIGS_DICT['CURRENT_KUT'] = ccyData.chosen apiDict, trade_qty, _, _ = cl.ctInit(ccy, notional, 0) realizedSlippageBps_batch=[] for n in range(batchSize): print(cl.timeTag(termcolor.colored('Batch '+str(batchN) +' Program '+str(n+1)+' / '+ccy,'blue'))) fDict = cl.getFundingDict(apiDict, ccy) sbDict = cl.getSmartBasisDict(apiDict, ccy, fDict, isSkipAdj=True) ftxSide = 'BUY' if kutSide == 'SELL' else 'SELL' isFTXSpot = ccy in AUTO_DICT['FTX_SPOT_UNIVERSE'] api = cl.ctKUTStepper(kutSide, ccy, trade_qty) cl.speak('Go') ##### longFill, shortFill = sendOrders(apiDict, isFTXSpot, ftxSide, 'kut', kutSide, api, ccy, trade_qty) basisBps=getBasisBps(isFTXSpot, ftxSide, 'kut', sbDict) realizedSlippageBps_batch, realizedSlippageBps_all=processFills(longFill, shortFill, basisBps, realizedSlippageBps_batch, realizedSlippageBps_all) print(cl.timeTag('Done')) print() cl.speak('Done') return realizedSlippageBps_all
# Functions ########### def ftxGetPos(unwindExch): if unwindExch == 'spot': return cl.ftxGetWallet(ftx).loc[ccy, 'total'] elif unwindExch == 'ftx': return cl.ftxGetFutPos(ftx, ccy) else: sys.exit(1) ###### # Init ###### cl.printHeader('BBTUnwind') apiDict, qty, _, spot = cl.ctInit(ccy, notional, 0) ftx = apiDict['ftx'] if unwindExch == 'spot': ftxTicker = ccy + '/USD' elif unwindExch == 'ftx': ftxTicker = ccy + '-PERP' else: sys.exit(1) ###### # Main ###### for i in range(SHARED_EXCH_DICT['bbt']): n = i + 1 cl.printHeader('BBT' + str(n)) bb = cl.bbCCXTInit(n)
fillSAvg = (fillS1 * (qty - leavesQtyS) + fillS2 * leavesQtyS) / qty fillBAvg=fillB1 else: # partial fills for both print('bbtCrossOrder abnormal termination!') sys.exit(1) return fillBAvg / fillSAvg - 1 # slippage def move(accountBuy, accountSell, ccy, qty): cl.printHeader('Buying in BBT' + str(accountBuy) + ' / Selling in BBT' + str(accountSell)) if qty <= 0: print('Error! qty=='+str(qty)) sys.exit(1) slippageBps=bbtCrossOrder(accountBuy,accountSell,ccy,qty)*10000 print() print(termcolor.colored('Realized slippage = ' + str(round(slippageBps)) + 'bps', 'red')) ###### # Init ###### CT_CONFIGS_DICT['MAX_NOTIONAL_USD'] = notional cl.printHeader('BBTWash') _,qty,_,_ = cl.ctInit(ccy, notional, 0) ###### # Main ###### move(accountBuy, accountSell, ccy, qty) print() print('BBT Wash completed!') cl.speak('B B T Wash completed')