Mizar
Search…
API Trading SDK
Here we describe how to create a new self-hosted strategy, open and close positions using the Mizar python SDK
Self-hosted strategies are strategies hosted by quants/trading firms on their own servers.

Creating a new self-hosted strategy

Install the Mizar client and follow the instruction below.
1
from mizar import Mizar
2
3
mizar_client = Mizar()
4
5
mizar_client.create_self_hosted_strategy(
6
name="My Strategy",
7
description="My Strategy works this way",
8
exchanges=["binance"],
9
symbols=["BTCUSDT"],
10
market="SPOT"
11
)
12
Copied!
The strategy creation returns a dictionary with the following format
1
{
2
'creation_timestamp': 1625571350830,
3
'exchange': 'binance',
4
'market': 'SPOT',
5
'name': 'My Strategy',
6
'strategy_id': 1,
7
'symbols': [
8
{
9
'base_asset': 'BTC',
10
'quote_asset': 'USDT',
11
'symbol': 'BTCUSDT'
12
}
13
]
14
}
15
Copied!
strategy_id is a unique identifier for your strategy which is used to open and close positions.

Open a position

Open a new position using the open_position method
1
mizar_client.open_position(
2
strategy_id=1,
3
base_asset="BTC",
4
quote_asset="USDT",
5
size=0.3,
6
is_long=True
7
)
Copied!
size indicates the relative size of the position. If you are sure that the position will bring profit use 1, otherwise scale down the size to reduce risks.
If the position opening is successful it will return a dictionary with the following format
1
{
2
'base_asset': 'BTC',
3
'is_long': True,
4
'open_price': '34209.480000000000',
5
'open_timestamp': 1625572116854,
6
'position_id': '1',
7
'quote_asset': 'USDT',
8
'size': 0.3,
9
'strategy_id': '1'
10
}
Copied!

Close a position

Close an existing open position using the close_position method
1
mizar_client.close_position(
2
position_id=1
3
)
Copied!
If the position is closed successfully you will receive
1
{
2
'base_asset': 'BTC',
3
'close_price': '33914.640000000000',
4
'close_timestamp': 1625572999043,
5
'is_long': True,
6
'open_price': '33914.640000000000',
7
'open_timestamp': 1625572973963,
8
'position_id': '1',
9
'quote_asset': 'USDT',
10
'size': 0.3,
11
'strategy_id': '1'
12
}
Copied!

List all open positions

Get all the open positions using get_all_open_positions method
1
mizar_client.get_all_open_positions(
2
strategy_id=1
3
)
Copied!
Will return
1
{'open_positions': [
2
{
3
'base_asset': 'BTC',
4
'is_long': True,
5
'open_price': '33871.070000000000',
6
'open_timestamp': 1625573293041,
7
'position_id': '1',
8
'quote_asset': 'USDT',
9
'size': 1.0,
10
'strategy_id': '1'
11
},
12
{
13
'base_asset': 'BTC',
14
'is_long': True,
15
'open_price': '33871.070000000000',
16
'open_timestamp': 1625573294312,
17
'position_id': '2',
18
'quote_asset': 'USDT',
19
'size': 1.0,
20
'strategy_id': '1'
21
},
22
{
23
'base_asset': 'BTC',
24
'is_long': True,
25
'open_price': '33871.070000000000',
26
'open_timestamp': 1625573295016,
27
'position_id': '3',
28
'quote_asset': 'USDT',
29
'size': 1.0,
30
'strategy_id': '1'
31
}
32
]
33
}
34
Copied!

Close all open positions

Close all the positions using close_all_positions method
1
mizar_client.get_all_open_positions(
2
strategy_id=1
3
)
Copied!
Will return
1
{'closed_positions': [
2
{
3
'base_asset': 'BTC',
4
'close_price': '34146.340000000000',
5
'close_timestamp': 1625574840982,
6
'is_long': True,
7
'open_price': '33871.070000000000',
8
'open_timestamp': 1625573293041,
9
'position_id': '1',
10
'quote_asset': 'USDT',
11
'size': 1.0,
12
'strategy_id': '`'
13
},
14
{
15
'base_asset': 'BTC',
16
'close_price': '34146.340000000000',
17
'close_timestamp': 1625574841018,
18
'is_long': True,
19
'open_price': '33871.070000000000',
20
'open_timestamp': 1625573294312,
21
'position_id': '2',
22
'quote_asset': 'USDT',
23
'size': 1.0,
24
'strategy_id': '1'
25
},
26
{'base_asset': 'BTC',
27
'close_price': '34146.340000000000',
28
'close_timestamp': 1625574841045,
29
'is_long': True,
30
'open_price': '33871.070000000000',
31
'open_timestamp': 1625573295016,
32
'position_id': '3',
33
'quote_asset': 'USDT',
34
'size': 1.0,
35
'strategy_id': '1'
36
}
37
]
38
}
Copied!
Last modified 1mo ago