0bps

Strategy vault / Tools & templates

Place Orders on Time and Ready Basis Public

A plugin used for spot-futures paired trading, can be used in the trading terminal. Self-use tool, the default support is Deribit's futures order opening. Just fill in the contract name and expected price difference…

Author
daniaoren
Complexity
Starter · 42 lines
Parameters
5

A plugin used for spot-futures paired trading, can be used in the trading terminal.

Self-use tool, the default support is Deribit's futures order opening. Just fill in the contract name and expected price difference in the contract according to the default value format.

If you want to support other exchanges, you may need to slightly modify it yourself.

Parameters

NameDefaultWhat it controls
ContractSwapswapPerpetual Contract
ContractFuturequarterFutures Contract
AmounttrueOrder Quantity
DiffMin6Minimum orderable spread
RealTradefalseWhether to place real orders

Source Python

def main():
	exchange.SetContractType(ContractSwap)
	TickerSwap = exchange.GetTicker()
	TickerSwap['BuyAmount'] = TickerSwap['Info']['result']['best_bid_amount']
	TickerSwap['SellAmount'] = TickerSwap['Info']['result']['best_ask_amount']
	exchange.SetContractType(ContractFuture)
	TickerFuture = exchange.GetTicker()
	TickerFuture['BuyAmount'] = TickerFuture['Info']['result']['best_bid_amount']
	TickerFuture['SellAmount'] = TickerFuture['Info']['result']['best_ask_amount']

	Diff = _N(TickerFuture['Buy'] - TickerSwap['Sell'],2)

	Msg = ''
	Msg += str(ContractSwap) +' '+ str(TickerSwap['Sell']) +' '+ str(TickerSwap['SellAmount'])+ '\n'
	Msg += str(ContractFuture) +' '+ str(TickerFuture['Buy']) +' '+ str(TickerFuture['BuyAmount']) + '\n'
	Msg += 'Spread: ' + str(Diff) + '\n'

	if Diff <= DiffMin:
		return 'Price difference ' + str(_N(Diff,2)) + ' Less than the set price difference '+str(DiffMin)+',Do not place an order' + '\n\nAdditional information\n' +Msg

	if TickerFuture['BuyAmount'] < Amount or TickerFuture['SellAmount'] < Amount:
		return 'The order quantity in a certain direction is less than the set order quantity '+str(Amount)+',Do not place an order' + '\n\nAdditional information\n' +Msg

	if not RealTrade:
		return 'Non-real Trading' + '\n' + Msg

	exchange.SetContractType(ContractSwap)
	exchange.SetDirection("buy")
	BuyOrderId = exchange.Buy(TickerSwap['Sell'] + 0.2, Amount)

	exchange.SetContractType(ContractFuture)
	exchange.SetDirection("sell")
	SellOrderId = exchange.Sell(TickerFuture['Buy'] - 0.2, Amount)

	BuyOrder = exchange.GetOrder(BuyOrderId)
	SellOrder = exchange.GetOrder(SellOrderId)

	TradeMsg = 'Transaction completed\n'
	TradeMsg += 'Buy Order ' + str(BuyOrder['ContractType']) + ' ' + str(BuyOrder['Price']) + ' ' + str(BuyOrder['DealAmount']) + '/' + str(BuyOrder['Amount']) + '\n'
	TradeMsg += 'Sell Order ' + str(SellOrder['ContractType']) + ' ' + str(SellOrder['Price']) + ' ' + str(SellOrder['DealAmount']) + '/' + str(SellOrder['Amount']) + '\n'
	TradeMsg += '\n\nAdditional information\n' +Msg
	return TradeMsg

Published by daniaoren on the FMZ strategy square · last modified 2021-02-24. Collected in the Quant Trading Vault. Unvalidated research: re-test with your own data and costs before trusting it.

Build this with AgenKit

A spec is not a trading system. Paste this into your coding agent and AgenKit runs a specialist team — architecture, test-first build, risk gates, review — with paper trading on by default.

in Claude Code, Cursor, Codex & 4 more
/agenkit build a tested, production-ready module from strategies/Place-Orders-on-Time-and-Ready-Basis-Public.md
  1. npx agenkit install engineering-kit in your project
  2. Paste the command into your agent and approve each phase
  3. Get tests, backtest, risk controls and a paper-trading switch

Understand it first

Before you run this, read the lesson behind the idea and how to backtest it honestly. Specs like this one are the survivors of an unknown number of trials; deflate their results accordingly.

Related specs

esc

Try , , or .

↑↓ move↵ open