exchange
¤
BackTestExchange
¤
BackTestExchange(**kwargs)
Bases: Exchange
Source code in lettrade/exchange/backtest/exchange.py
15 16 17 18 19 |
|
history_orders
instance-attribute
¤
History Order dict by Order.id
key
history_positions
instance-attribute
¤
History Position dict by Position.id
key
positions
instance-attribute
¤
Available Position dict by Position.id
key
init
¤
init(
brain: Brain,
feeder: DataFeeder,
account: Account,
commander: Commander,
) -> None
Init Exchange dependencies.
Set data/datas from feeder.
Set state to ExchangeState.Start
.
Parameters:
-
brain
(Brain
) –description
-
feeder
(DataFeeder
) –description
-
account
(Account
) –description
-
commander
(Commander
) –description
Source code in lettrade/exchange/exchange.py
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
|
new_order
¤
new_order(
size: float,
type: OrderType = OrderType.Market,
limit: float | None = None,
stop: float | None = None,
sl: float | None = None,
tp: float | None = None,
tag: object | None = None,
data: DataFeed | None = None,
expiration: datetime | None = None,
**kwargs
) -> OrderResult
Place new order.
Then send order events to Brain
Parameters:
-
size
(float
) –description
-
type
(OrderType | None
, default:Market
) –description. Defaults to OrderType.Market.
-
limit
(float | None
, default:None
) –description. Defaults to None.
-
stop
(float | None
, default:None
) –description. Defaults to None.
-
sl
(float | None
, default:None
) –description. Defaults to None.
-
tp
(float | None
, default:None
) –description. Defaults to None.
-
tag
(object | None
, default:None
) –description. Defaults to None.
-
data
(DataFeed | None
, default:None
) –description. Defaults to None.
-
**kwargs
(dict | None
, default:{}
) –Extra-parameters
Returns:
-
OrderResult
(OrderResult
) –Result when place new
Order
Source code in lettrade/exchange/backtest/exchange.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
|
next
¤
next()
Execution when new data feeded
Source code in lettrade/exchange/backtest/exchange.py
25 26 27 28 |
|
next_next
¤
next_next()
Call after strategy.next()
Source code in lettrade/exchange/exchange.py
109 110 111 |
|
on_executions
¤
Receive Execution event from exchange then store and notify Brain
Source code in lettrade/exchange/exchange.py
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
|
on_order
¤
Receive order event from exchange then store and notify Brain
Parameters:
-
order
(Order
) –description
-
broadcast
(bool | None
, default:True
) –description. Defaults to True.
Source code in lettrade/exchange/exchange.py
160 161 162 163 164 165 166 167 168 169 170 171 172 |
|
on_orders
¤
Receive orders event from exchange then store and notify Brain
Parameters:
-
orders
(list[Order]
) –description
-
broadcast
(bool | None
, default:True
) –description. Defaults to True.
Raises:
-
RuntimeError
–description
Source code in lettrade/exchange/exchange.py
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
|
on_position
¤
Receive Position event from exchange then store and notify Brain
Parameters:
-
position
(Position
) –new comming
Position
-
broadcast
(bool | None
, default:True
) –Flag notify to Brain. Defaults to True.
Raises:
-
RuntimeError
–validate
Position
instance
Source code in lettrade/exchange/exchange.py
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 |
|
on_positions
¤
Receive Positions event from exchange then store and notify Brain
Parameters:
-
positions
(list[Position]
) –list of new comming
Position
-
broadcast
(bool | None
, default:True
) –Flag notify to Brain. Defaults to True.
Raises:
-
RuntimeError
–validate
Position
instance
Source code in lettrade/exchange/exchange.py
245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 |
|
start
¤
start() -> None
Start of Exchange by:
- Start account.
- Set state to ExchangeState.Run
ready for next().
Source code in lettrade/exchange/exchange.py
97 98 99 100 101 102 103 |
|
stop
¤
stop() -> None
Stop Exchange
Source code in lettrade/exchange/exchange.py
113 114 115 116 |
|