Type/to search
Built-in Functions
Global
Log
Market
Trade
Account
Futures
Exchange
IO
Network
Storage
Threads
TA
Talib
OS
os
os.open
os.fgets
os.fputs
os.mmap
os.getRootDir
os.listFiles
os.exists
os.remove
os.mkdir
os.rmdir
os.rename
os.stat
os.exit
File
ListFilesResult
FileStat
Structures
Built-in Variables and Constants
Conventions
Exchanges

Write content to a file.

fputs(filename, content)
fputs(filename, content, append)

Examples

Save strategy configuration to file.

javascript
function main() { let config = '{"strategy": "MA", "period": 20}' let bytesWritten = os.fputs("strategy_config.json", config) Log("Bytes written:", bytesWritten) // Output: Bytes written: 32 Log(`os.fgets("strategy_config.json"):`, os.fgets("strategy_config.json")) // Output: os.fgets("strategy_config.json"): {"strategy": "MA", "period": 20} // append a log line let logInfo = "\n[" + new Date().toISOString() + "] Config saved" os.fputs("strategy_config.json", logInfo, true) Log(`os.fgets("strategy_config.json"):`, os.fgets("strategy_config.json")) // Output: os.fgets("strategy_config.json"): {"strategy": "MA", "period": 20} // [2025-09-08T07:20:30.563Z] Config saved }

Returns

TypeDescription

number

Returns the actual number of bytes written.

Arguments

NameTypeRequiredDescription

filename

string

Yes

File path.

content

string

Yes

Content to write.

append

bool

No

Whether to write in append mode, defaults to false (overwrite mode).

See Also

Remarks

Convenient file writing method, overwrites file content by default. Set append to true to append to the end of the file.