PiXiu - A trading backtesting tool similar to MT4/MT5
Project description
PiXiu
A trading backtesting tool similar to MT4/MT5.
It has a standard set of API definitions, and backtesting code written using these APIs can be run on www.TradePython.com without changes.
Install
pip install pixiu
How to use
Parameters :
-c test config
-n test name (in the test configuration file)
-s script file
-o log file
pixiu -c pixiu_sample.json -n testUSDCHF_TP -s pixiu_sample.py
pixiu -c pixiu_sample.json -n testUSDCHF_TP -s pixiu_sample.py
pixiu -c pixiu_sample.json -n testUSDCHF -s pixiu_sample2.py -o log.txt
Test configuration file format
JSON format:
{
"accounts": {
"default": {
"balance": 10000.0,
"equity": 10000.0,
"margin": 0,
"free_margin": 10000.0,
"credit": 0.0,
"profit": 0.0,
"margin_level": 0,
"leverage": 100,
"currency": "USD",
"free_margin_mode": 0,
"stop_out_level": 0,
"stop_out_mode": 0,
"company": "TradePython.com",
"name": "PXTester",
"number": "000",
"server": "PXTester",
"trade_mode": 0,
"limit_orders": 500,
"margin_so_mode": 0,
"trade_allowed": true,
"trade_expert": 1,
"margin_so_call": 0.0,
"margin_so_so": 0.0,
"commission": 0.0
}
},
"symbols": {
"USDCHF": {
"symbol": "USDCHF",
"spread": 2,
"digits": 5,
"stop_level": 0,
"volume_min": 0.01,
"trade_contract_size": 100000,
"point": 0.00001,
"currency_profit": "CHF",
"currency_base": "USD",
"currency_margin": "USD"
}
},
"tests": {
"testUSDCHF": {
"symbol": "USDCHF",
"tick_data": "usdchf_m1_20210315-0415.csv",
"start_time": "2021-03-15",
"end_time": "2021-04-16",
"max_tick": 100,
"balance": 10000,
"leverage": 100,
"currency": "USD",
"account": "default",
"spread_point": 15
},
"testUSDCHF_TP": {
"symbol": "USDCHF",
"tick_data": {
"channel": "tradepython.com",
"api_token": "YOUR-API-TOKEN",
"source": "12345678@PixiuServer01",
"format": "json",
"period": 30,
"timeframe": "m1"
},
"max_tick": 100,
"balance": 10000,
"leverage": 100,
"currency": "USD",
"account": "default",
"spread_point": 15
},
"testUSDCHF_TP2": {
"symbol": "USDCHF",
"tick_data": {
"channel": "tradepython.com",
"api_token": "YOUR-API-TOKEN",
"source": {"type": "public", "name": "Demo1"},
"format": "json",
"period": 30,
"start_time": "2021-03-15",
"end_time": "2021-04-16",
"timeframe": "m1"
},
"start_time": "2021-03-15",
"end_time": "2021-04-16",
"max_tick": 100,
"balance": 10000,
"leverage": 100,
"currency": "USD",
"account": "default",
"spread_point": 15
}
}
}
Testing with csv files:
symbol: product
tick_data: tick data data file
start_time: start time
end_time: end time
max_tick: the maximum number of ticks to test, which can reduce the test time
balance: initial capital of the test account
leverage: leverage of the test account
account: the name of the test account (in the test profile accounts)
spread_point: spread
"testUSDCHF": {
"symbol": "USDCHF",
"tick_data": "usdchf_m1_20210315-0415.csv",
"start_time": "2021-03-15",
"end_time": "2021-04-16",
"max_tick": 100,
"balance": 10000,
"leverage": 100,
"currency": "USD",
"account": "default",
"spread_point": 15
}
Test with tradepython data test
source: Data account
account@account-server
Example:
12345678@PixiuServer01
or: {"type": "public", "name": "Demo1"}
type: public or private
name: Account name
period: data period (days)
Example:
30 - the last 30 days of data
timeframe: time frame, the following values
s1 - 1 second
m1 - 1 minute
m5 - 1 minute
m15 - 15 minutes
m30 - 30 minutes
h1 - 1 hour
h4 - 1 hour
d1 - 1 day
w1 - 1 week
mn1 - 1 month
"testUSDCHF_TP": {
...
"tick_data": {
"channel": "tradepython.com",
"api_token": "YOUR-API-TOKEN",
"source": "account@account-server",
"format": "json",
"period": 30,
"timeframe": "m1"
},
...
}
Script Samples
-
Buy or sell a product
errid, order_uid = Buy(volume=volume, price=Ask()) errid, order_uid = Sell(volume=0.01, price=Bid())
-
Modify an order
errid, order_uid = ModifyOrder(order_uid, stop_loss=stop_loss, take_profit=take_profit)
-
Close an order
errid, order_uid = CloseOrder(order_uid, price=Ask(), volume=volume)
-
Get the current open order UIDs
uids = GetOpenedOrderUIDs() for uid in uids: o = GetOrder(uid)
API
=======
```python
AccountEquity(self)
Returns the equity.
Returns:
The account equity.
AccountFreeMargin(self)
Returns the free margin.
Returns:
The free margin.
Ask(self, shift=0) -> float
Returns Ask price value for the default symbol with default timeframe and shift.
Parameters:
shift (int): Index of the value taken from the buffer
(shift relative to the current the given amount of periods ago).
Returns:
Ask price.
Bid(self, shift=0) -> float
Returns Bid price value for the default symbol with default timeframe and shift.
Parameters:
shift (int): Index of the value taken from the buffer
(shift relative to the current the given amount of periods ago).
Returns:
Bid price.
Buy(self, volume: float, type=0, price=None, stop_loss=None, take_profit=None, magic_number=None, symbol=None, slippage=None, arrow_color=None, expiration=None) -> (<function NewType.<locals>.new_type at 0x7fe120629dc0>, <function NewType.<locals>.new_type at 0x7fe122ed0940>)
Open a buy order.
Parameters:
volume (float): Number of lots.
type (OrderType): Order type.
price (float): Order price. If price is None, price = Ask().
stop_loss (float): Stop loss price.
take_profit (float): Take profit price.
magic_number (float): Order magic number.
symbol (float): Symbol for trading.
slippage (float): Maximum price slippage for trading.
arrow_color (float): Color of the opening arrow on the MT4/5 chart.
expiration (float): Order expiration time (for pending order only)
Returns:
ErrorID: If 0 success.
OrderUID: The order UID.
Close(self, shift=0) -> float
Returns Close price value for the default symbol with default timeframe and shift.
Parameters:
shift (int): Index of the value taken from the buffer
(shift relative to the current the given amount of periods ago).
Returns:
Close price.
CloseOrder(self, uid, price, volume: float, slippage=None, arrow_color=None) -> (<function NewType.<locals>.new_type at 0x7fe120629dc0>, <function NewType.<locals>.new_type at 0x7fe122ed0940>)
Close a order.
Parameters:
uid : The order UID.
price (float): Close price.
volume (float): Number of lots.
slippage (float): Maximum price slippage for trading.
arrow_color (float): New color of the opening arrow on the MT4/5 chart.
Returns:
ErrorID: If 0 success.
OrderUID: The order UID.
DefaultTimeFrame(self)
Returns the default time frame.
GetAccount(self)
Returns the account data.
Returns:
The account data.
GetClosedOrderUIDs(self, symbol: str = None)
Returns the UIDs of current closed orders.
Parameters:
The symbol name.
Returns:
The uid list.
GetOpenedOrderUIDs(self, symbol: str = None)
Returns the UIDs of current opened orders.
Parameters:
The symbol name.
Returns:
The uid list.
GetOrder(self, order_uid: <function NewType.<locals>.new_type at 0x7fe122ed0940>)
Returns the order object.
Parameters:
order_uid (): The order uid.
Returns:
The order object.
GetParam(self, name, default=None)
Returns the EA parameter value.
Parameters:
name (): The EA parameter name.
default (int): The EA parameter default value.
Returns:
The EA parameter value.
GetPendingOrderUIDs(self, symbol: str = None)
Returns the UIDs of current pending orders.
Parameters:
The symbol name.
Returns:
The uid list.
GetSymbol(self, symbol=None)
Returns the symbol properties.
Parameters:
symbol (int): The symbol name.
Returns:
The symbol properties
GetSymbolData(self, symbol: str, timeframe: str, size: int)
Get a symbol data.
Parameters:
symbol (str): Symbol name.
timeframe (str): Timeframe. See the TimeFrame defining.
size (int): Maximum size.
Returns:
Symbol data
High(self, shift=0) -> float
Returns High price value for the default symbol with default timeframe and shift.
Parameters:
shift (int): Index of the value taken from the buffer
(shift relative to the current the given amount of periods ago).
Returns:
High price.
Low(self, shift=0) -> float
Returns Low price value for the default symbol with default timeframe and shift.
Parameters:
shift (int): Index of the value taken from the buffer
(shift relative to the current the given amount of periods ago).
Returns:
Low price.
ModifyOrder(self, uid, price=None, stop_loss=None, take_profit=None, arrow_color=None, expiration=None) -> (<function NewType.<locals>.new_type at 0x7fe120629dc0>, <function NewType.<locals>.new_type at 0x7fe122ed0940>)
Modify a order.
Parameters:
uid : The order UID.
price (float): New open price. (for pending order only)
stop_loss (float): New stop loss price.
take_profit (float): New take profit price.
arrow_color (float): New color of the opening arrow on the MT4/5 chart.
expiration (float): New order expiration time (for pending order only)
Returns:
ErrorID: If 0 success.
OrderUID: The order UID.
Open(self, shift=0) -> float
Returns Open price value for the default symbol with default timeframe and shift.
Parameters:
shift (int): Index of the value taken from the buffer
(shift relative to the current the given amount of periods ago).
Returns:
Open price.
OrderStats(self, order_uids)
Returns the order statistics.
Parameters:
order_uids : the list of order uids.
Returns:
The order statistics.
Sell(self, volume: float, type=0, price=None, stop_loss=None, take_profit=None, magic_number=None, symbol=None, slippage=None, arrow_color=None, expiration=None) -> (<function NewType.<locals>.new_type at 0x7fe120629dc0>, <function NewType.<locals>.new_type at 0x7fe122ed0940>)
Open a sell order.
Parameters:
volume (float): Number of lots.
type (OrderType): Order type.
price (float): Order price. If price is None, price = Bid().
stop_loss (float): Stop loss price.
take_profit (float): Take profit price.
magic_number (float): Order magic number.
symbol (float): Symbol for trading.
slippage (float): Maximum price slippage for trading.
arrow_color (float): Color of the opening arrow on the MT4/5 chart.
expiration (float): Order expiration time (for pending order only)
Returns:
ErrorID: If 0 success.
OrderUID: The order UID.
StopTester(self, code: int = 0, message: str = None)
Stop the EA tester. (For tester only.)
Parameters:
code (int): Error code.
message (str): Error message.
Returns:
None
Symbol(self) -> str
Returns the current symbol name.
Returns:
The symbol name.
SymbolInfo(self, item, symbol=None, default=None)
Returns the symbol information.
Parameters:
item (str): The symbol item name.
symbol (str): The symbol name.
default (): The default value.
Returns:
The symbol information.
Time(self, shift=0) -> datetime.datetime
Returns time value for the default symbol with default timeframe and shift.
Parameters:
shift (int): Index of the value taken from the buffer
(shift relative to the current the given amount of periods ago).
Returns:
Time.
Volume(self, shift=0) -> float
Returns volume value for the default symbol with default timeframe and shift.
Parameters:
shift (int): Index of the value taken from the buffer
(shift relative to the current the given amount of periods ago).
Returns:
Volume price.
__init__(self)
Initialize self. See help(type(self)) for accurate signature.
iAD(self, symbol_data, shift=0)
Chaikin A/D Line (Volume Indicators)
Parameters:
symbol_data (object): The symbol data.
shift: Index of the value taken from the buffer
(shift relative to the current the given amount of periods ago).
Returns:
Chaikin A/D Line
iADX(self, symbol_data, timeperiod, shift=0)
Average Directional Movement Index (Momentum Indicators)
Parameters:
symbol_data (object): The symbol data.
timeperiod (int): The time period.
shift: Index of the value taken from the buffer
(shift relative to the current the given amount of periods ago).
Returns:
Average Directional Movement Index
iATR(self, symbol_data, timeperiod, shift=0)
Average True Range (Volatility Indicators)
Parameters:
symbol_data (object): The symbol data.
timeperiod (int): The time period.
shift: Index of the value taken from the buffer
(shift relative to the current the given amount of periods ago).
Returns:
Average True Range
iBands(self, symbol_data, timeperiod, nbdevup, nbdevdn, matype, shift=0)
Bollinger Bands (Overlap Studies)
Parameters:
symbol_data (object): The symbol data.
timeperiod (int): The time period.
nbdevup (int): 2
nbdevdn (int): 2
ma_type: 0 (Simple Moving Average) ,For details see the TA-LIB
shift: Index of the value taken from the buffer
(shift relative to the current the given amount of periods ago).
Returns:
Bollinger Bands
iCCI(self, symbol_data, timeperiod, shift=0)
Commodity Channel Index (Momentum Indicators)
Parameters:
symbol_data (object): The symbol data.
timeperiod (int): The time period.
shift: Index of the value taken from the buffer
(shift relative to the current the given amount of periods ago).
Returns:
Commodity Channel Index
iChaikin(self, symbol_data, fastperiod, slowperiod, shift=0)
Chaikin A/D Oscillator (Volume Indicators)
Parameters:
symbol_data (object): The symbol data.
fastperiod (int): The fast period.
slowperiod (int): The low period.
shift: Index of the value taken from the buffer
(shift relative to the current the given amount of periods ago).
Returns:
Chaikin A/D Oscillator
iDEMA(self, symbol_data, timeperiod, shift=0)
Double Exponential Moving Average (Overlap Studies)
Parameters:
symbol_data (object): The symbol data.
timeperiod (int): The time period.
shift: Index of the value taken from the buffer
(shift relative to the current the given amount of periods ago).
Returns:
Double Exponential Moving Average
iMA(self, price_data, period, ma_type, shift=0)
Calculates the Moving Average indicator and returns its value.
Parameters:
price_data (object): The price data. (Close, Open, Low, etc...)
period (int): Averaging period for calculation.
ma_type: 0 (Simple Moving Average) ,For details see the TA-LIB
shift: Index of the value taken from the buffer
(shift relative to the current the given amount of periods ago).
Returns:
Moving average value.
iMACD(self, symbol_data, fastperiod, slowperiod, signalperiod, shift=0)
Moving Average Convergence/Divergence (Momentum Indicators)
Parameters:
symbol_data (object): The symbol data.
fastperiod (int): The fast period.
slowperiod (int): The slow period.
signalperiod (int): The signal period.
shift: Index of the value taken from the buffer
(shift relative to the current the given amount of periods ago).
Returns:
Moving Average Convergence/Divergence
iMFI(self, symbol_data, timeperiod, shift=0)
Money Flow Index (Momentum Indicators)
Parameters:
symbol_data (object): The symbol data.
timeperiod (int): The time period.
shift: Index of the value taken from the buffer
(shift relative to the current the given amount of periods ago).
Returns:
Money Flow Index
iMomentum(self, symbol_data, timeperiod, shift=0)
Momentum (Momentum Indicators)
Parameters:
symbol_data (object): The symbol data.
timeperiod (int): The time period.
shift: Index of the value taken from the buffer
(shift relative to the current the given amount of periods ago).
Returns:
Momentum
iOBV(self, symbol_data, shift=0)
On Balance Volume (Volume Indicators)
Parameters:
symbol_data (object): The symbol data.
shift: Index of the value taken from the buffer
(shift relative to the current the given amount of periods ago).
Returns:
On Balance Volume
iRSI(self, symbol_data, timeperiod, shift=0)
Relative Strength Index (Momentum Indicators)
Parameters:
symbol_data (object): The symbol data.
timeperiod (int): The time period.
shift: Index of the value taken from the buffer
(shift relative to the current the given amount of periods ago).
Returns:
Relative Strength Index
iSAR(self, symbol_data, acceleration, maximum, shift=0)
Parabolic SAR (Overlap Studies)
Parameters:
symbol_data (object): The symbol data.
acceleration (int): 0.02
maximum (int): 0.2
shift: Index of the value taken from the buffer
(shift relative to the current the given amount of periods ago).
Returns:
Parabolic SAR
iStdDev(self, symbol_data, timeperiod, nbdev, shift=0)
Standard Deviation (Statistic Functions)
Parameters:
symbol_data (object): The symbol data.
timeperiod (int): The time period.
nbdev (int): 1
shift: Index of the value taken from the buffer
(shift relative to the current the given amount of periods ago).
Returns:
Standard Deviation
iStochastic(self, symbol_data, fastk_period, slowk_period, slowk_matype, slowd_period, slowd_matype, shift=0)
Stochastic (Momentum Indicators)
Parameters:
symbol_data (object): The symbol data.
fastk_period (int): 5
slowk_period (int): 3
slowk_matype (int): 0
slowd_period (int): 3
slowd_matype (int): 0
shift: Index of the value taken from the buffer
(shift relative to the current the given amount of periods ago).
Returns:
Stochastic
iTEMA(self, symbol_data, timeperiod, shift=0)
Triple Exponential Moving Average (Overlap Studies)
Parameters:
symbol_data (object): The symbol data.
timeperiod (int): The time period.
shift: Index of the value taken from the buffer
(shift relative to the current the given amount of periods ago).
Returns:
Triple Exponential Moving Average
iWPR(self, symbol_data, timeperiod, shift=0)
Williams' %R (Momentum Indicators)
Parameters:
symbol_data (object): The symbol data.
timeperiod (int): The time period.
shift: Index of the value taken from the buffer
(shift relative to the current the given amount of periods ago).
Returns:
Williams' %R
[2021-05-29]
Version:
Package:
pixiu: 0.30.0.20210529
Descriptions:
1.Add output
[2021-05-28]
Version:
Package:
pixiu: 0.29.0.20210528
Descriptions:
1.Struct project directories
2.Complete README.txt
[2021-05-27]
Version:
Package:
pixiu: 0.28.0.20210527
Descriptions:
1.Add load channel
[2021-05-26]
Version:
Package:
pixiu: 0.27.0.20210526
Descriptions:
1.Add PXTester, main
[2021-05-24]
Version:
Package:
pixiu: 0.26.0.20210524
Descriptions:
1. api add help doc string
[2021-05-22]
Version:
Package:
pixiu: 0.25.0.20210522
Descriptions:
1.add language
2.fix sl/tp error:
ds[((ds['sl'] > 0) & (ds['sl_p'] <= 0)) | ((ds['tp'] > 0) & (ds['tp_p'] >= 0))]
3.api:
Dict - > UIDs
def GetOpenedOrderUIDs(self, symbol: str = None)
def GetPendingOrderUIDs(self, symbol: str = None)
def GetClosedOrderUIDs(self, symbol: str = None)
[2021-05-19]
Version:
Package:
pixiu: 0.24.0.20210519
Descriptions:
1.add test_pixiu set_test_result
[2021-05-18]
Version:
Package:
pixiu: 0.23.0.20210518
Descriptions:
[2021-05-17]
Version:
Package:
pixiu: 0.22.0.20210517
Descriptions:
1.SymbolIndicator, SymbolPrice, SymbolTime, SymbolData arguments.
[2021-05-15]
Version:
Package:
pixiu: 0.21.0.20210515
Descriptions:
[2021-05-13]
Version:
Package:
pixiu: 0.20.0.20210513
Descriptions:
[2021-05-11]
Version:
Package:
pixiu: 0.19.0.20210511
Descriptions:
1.fix ea_tester some bugs
[2021-05-10]
Version:
Package:
pixiu: 0.18.0.20210510
Descriptions:
[2021-05-09]
Version:
Package:
pixiu: 0.17.0.20210509
Descriptions:
1. Buy, Sell, ModifyOrder remove arguments comment
[2021-05-08]
Version:
Package:
pixiu: 0.16.0.20210508
Descriptions:
1.
[2021-05-07]
Version:
Package:
pixiu: 0.15.0.20210507
Descriptions:
1. def GetSymbolData(self, symbol: str, timeframe: str, count: int)
[2021-05-06]
Version:
Package:
pixiu: 0.14.0.20210506
Descriptions:
1. some fixs
[2021-05-01]
Version:
Package:
pixiu: 0.13.0.20210501
Descriptions:
1.Add test open, modify, close in the EAT testing.
[2021-04-30]
Version:
Package:
pixiu: 0.12.0.20210430
Descriptions:
1.Finish EAT's 7 tests.
[2021-04-29]
Version:
Package:
pixiu: 0.11.0.20210429
Descriptions:
1.Add Account, Symbol Classes
2.Add ts_order, ts_base
[2021-04-28]
Version:
Package:
pixiu: 0.10.0.20210428
Descriptions:
1.Add some methods
[2021-04-27]
Version:
Package:
pixiu: 0.9.0.20210427
Descriptions:
[2021-04-26]
Version:
Package:
pixiu: 0.8.0.20210426
Descriptions:
1. Add test_ea_tester_func_indicators
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 pixiu-0.30.1.tar.gz.
File metadata
- Download URL: pixiu-0.30.1.tar.gz
- Upload date:
- Size: 662.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.3.1 pkginfo/1.7.0 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.8.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e585eaee1839ff7218ee8eee609e28d216e2f053214657bcf9fb72e58cf852b7
|
|
| MD5 |
e700a4149c6563d5c18d273b099f330b
|
|
| BLAKE2b-256 |
ecd0552e1e78b4348c746c334aad6d805e691e4ec44596115957da05d92c517b
|
File details
Details for the file pixiu-0.30.1-py3-none-any.whl.
File metadata
- Download URL: pixiu-0.30.1-py3-none-any.whl
- Upload date:
- Size: 37.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.3.1 pkginfo/1.7.0 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.8.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eb6f6e1a8fdc9b4a0ba671c4c047caa02f8a1e2bf9085071a01357e77cccc720
|
|
| MD5 |
3b53cd9c56f9706ce8c52c61d456d9d7
|
|
| BLAKE2b-256 |
76c2bb9fd0ab607af4822f3ac9e13f04f2a2e806f1b1e6eda2ad1b8081009fcf
|