Client library for Signal Fabric
Project description
Signal Fabric Client
Official Python client library for Signal Fabric - a lightweight handler-based framework for generating market signals on demand.
Installation
pip install signal-fabric-client
Quick Start
Live Signal Request
from signal_fabric import GrpcClient
with GrpcClient(host='localhost', port=9090, use_tls=False) as client:
outcome = client.process_signal(
target='BTCUSDT',
signal_name='rsi_binance_spot',
signal_op='compute_rsi',
handler_request={'period': 14, 'timeframe': '1h'}
)
if outcome.has_errors():
print(f"Error: {outcome.errors}")
else:
print(f"RSI: {outcome.result['latest_rsi']}, Regime: {outcome.result['regime']}")
Backtest Replay Mode
from signal_fabric import GrpcClient
with GrpcClient(host='localhost', port=9090, use_tls=False) as client:
# Get dataset metadata
metadata = client.get_backtest_metadata(
signal_name='rsi_binance_mf',
target='BTCUSDT',
timeframe='1h'
)
if metadata.has_errors():
print(f"Error: {metadata.errors}")
else:
print(f"Total positions: {metadata.total_positions}")
print(f"Start position: {metadata.start_position} (after {metadata.required_lookback} lookback)")
# Iterate through positions for walk-forward backtest
for position, timestamp in metadata.iter_positions():
outcome = client.process_signal(
target='BTCUSDT',
signal_name='rsi_binance_mf',
signal_op='compute_rsi',
handler_request={
'_position': position,
'timeframe': '1h',
'period': 14
}
)
# Response includes both signal and candle data
if outcome._backtest_candle:
candle = outcome._backtest_candle
print(f"Position {position}: RSI={outcome.result['latest_rsi']}, "
f"Close={candle.close}, Volume={candle.volume}")
# Evaluate outcome against known historical data...
API Reference
GrpcClient
Constructor
GrpcClient(host: str = 'localhost', port: int = 50051, timeout: int = 30, ca_cert_path: str = None)
Parameters:
host(str): Server hostname or IP address (default: 'localhost')port(int): Server port number (default: 50051)timeout(int): Request timeout in seconds (default: 30)ca_cert_path(str): Path to CA certificate for server verification (PEM format)
Methods
connect()
Establish connection to the server.
disconnect()
Close the connection to the server.
is_connected() -> bool
Check if client is currently connected.
process_signal(target, signal_name, signal_op, handler_request=None) -> SignalOutcome
Process a signal request.
Parameters:
target(str): Target for signal computation (e.g., 'BTC', 'ETH', 'AAPL')signal_name(str): Signal handler name or profile namesignal_op(str): Operation to perform (e.g., 'analyze', 'greet')handler_request(dict, optional): Request parameters as dictionary
Returns: SignalOutcome object
get_backtest_metadata(signal_name, target, timeframe) -> BacktestMetadata
Get metadata for backtest dataset (positions, timestamps, lookback).
Parameters:
signal_name(str): Signal profile name (e.g., 'rsi_binance_mf')target(str): Target symbol (e.g., 'BTCUSDT')timeframe(str): Timeframe string (e.g., '1h', '5m')
Returns: BacktestMetadata object
SignalOutcome
Result object containing the signal computation outcome.
Attributes
result(str): Signal result valuecomputation(str): Description of computation performedcomputed_at(float): Unix timestamp when computederrors(Dict[str, str]): Error codes and messages (or empty)details(Dict[str, str]): Additional computation details (or empty)_backtest_candle(BacktestCandle, optional): OHLCV candle at_position(only present when_positionin request)
Methods
has_errors() -> bool
Returns True if the outcome contains errors.
is_detailed() -> bool
Returns True if the outcome has errors or additional details.
BacktestCandle
OHLCV candle data returned in backtest replay mode.
Attributes
timestamp(int): Unix timestamp in millisecondsopen(float): Opening pricehigh(float): Highest pricelow(float): Lowest priceclose(float): Closing pricevolume(float): Trading volume
BacktestMetadata
Metadata for backtest dataset, used for walk-forward backtesting.
Attributes
total_positions(int): Total number of candles in datasetstart_position(int): First valid position (after handler lookback)required_lookback(int): Handler's required lookback periodtimeframe_ms(int): Timeframe interval in millisecondsfirst_timestamp(int): First candle timestamp (ms since epoch)last_timestamp(int): Last candle timestamp (ms since epoch)symbol(str): Confirmed symbol from datasettimeframe_str(str): Confirmed timeframe stringerrors(Dict[str, str]): Error messages (or empty)
Methods
has_errors() -> bool
Returns True if metadata request returned errors.
get_timestamp(position: int) -> int
Calculate timestamp for a given position using formula: first_timestamp + (position * timeframe_ms)
iter_positions() -> Iterator[Tuple[int, int]]
Iterate through valid backtest positions. Yields (position, timestamp) tuples.
Requirements
- Python 3.8+
- grpcio >= 1.76.0
- protobuf >= 4.0.0
Server Setup
This client requires a running Signal Fabric server. To set up the server:
-
Clone the Signal Fabric repository:
git clone https://github.com/phasequant/signal-fabric.git cd signal-fabric
-
Install dependencies:
pip install -r requirements.txt
-
Start the server:
python src/server/main.py --config config.yaml
Version
Current version: 0.1.29
License
See LICENSE file for details.
Links
Support
For questions, issues, or contributions, please visit the GitHub repository.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file signal_fabric_client-0.1.29.tar.gz.
File metadata
- Download URL: signal_fabric_client-0.1.29.tar.gz
- Upload date:
- Size: 14.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e76ee6c0ae4d656d527dc54d9f3b3e156a2f69d6cdefe69b3e8a4aabfc3828b6
|
|
| MD5 |
f65248f53e2fb5b995d5739e6e5b85c7
|
|
| BLAKE2b-256 |
7742252ddfc76b103c22327b4d329f67277412299235363433708e32b30779a6
|
File details
Details for the file signal_fabric_client-0.1.29-py3-none-any.whl.
File metadata
- Download URL: signal_fabric_client-0.1.29-py3-none-any.whl
- Upload date:
- Size: 15.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e1fb9de8ada68aad4207e2923a05a7943a837183677454813724511e99c8633a
|
|
| MD5 |
1ce82c551982f46372ade0ea89618f16
|
|
| BLAKE2b-256 |
c1f6bdbb3527e4bb27ac6da10b6100762793bb87cbd8cb832576bbd00e3233fa
|