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…
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
| Name | Default | What it controls |
|---|---|---|
| ContractSwap | swap | Perpetual Contract |
| ContractFuture | quarter | Futures Contract |
| Amount | true | Order Quantity |
| DiffMin | 6 | Minimum orderable spread |
| RealTrade | false | Whether 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 TradeMsgPublished 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.
/agenkit build a tested, production-ready module from strategies/Place-Orders-on-Time-and-Ready-Basis-Public.md- npx agenkit install engineering-kit in your project
- Paste the command into your agent and approve each phase
- 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
- 2 3 Python Version Drawing Class Library Compatible 2 3Python · Tools & templates
- Local StoragePython · Tools & templates
- Python Version Dual Thrust OKCoin FuturesPython · Tools & templates
- TBD Python2 3Python · Tools & templates
- FMZ Real Offer Robot Automatically Detects and Restarts Program WeChat PushPython · Tools & templates
- OkEX Websocket Realtime v3Python · Tools & templates