Skip to content
All library documents

Reusable Spot-Trading Library for Orders and Moving-Average Crosses

Article FMZ forum · Author: 发明者量化-小小梦

Summary

This tutorial explains how to add reusable template libraries to trading strategies and use a cryptocurrency spot-trading library. It demonstrates calling library buy and sell functions from interactive controls, while the template handles details such as pending-order timeouts and partial fills. The code walkthrough describes canceling orders, checking account balances and frozen funds, sizing trades within limits, and calculating moving-average crossovers.

The examples illustrate an implementation workflow and the library’s mechanisms, rather than establishing a profitable trading strategy. The tutorial also shows a simulated-exchange test, but its results are conveyed through images and are not quantified in the text. The source code excerpt is incomplete, and its behavior depends on platform APIs, settings, and exchange conditions. Users are encouraged to inspect the full template and its parameters before relying on it; waiting for frozen funds can also leave a process waiting indefinitely.

Key ideas

  • Template libraries expose reusable functions that a strategy can call after adding the library to the strategy.
  • The spot-trading example uses interactive buy and sell commands to invoke library functions.
  • The library manages order handling, including cancellation, partial fills, retries, and account checks.
  • Its trade routine constrains order size by configured limits, available balances, and minimum trade size.
  • The crossover helper compares moving averages or supplied indicator arrays to identify recent cross direction.

Tags

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.