Skip to content

Commit 1587150

Browse files
authored
Update 02 Trades.php
1 parent 89cbe6b commit 1587150

File tree

1 file changed

+11
-66
lines changed
  • 08 Drafts/05 Historical Data/04 Asset Classes/03 Crypto

1 file changed

+11
-66
lines changed
Lines changed: 11 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,12 @@
11
<?
2+
$symbolC = "AddCrypto(\"BTCUSD\").Symbol";
3+
$symbolPy = "self.add_crypto('BTCUSD').symbol";
4+
$assetClass = "Crypto";
25
$dataTypeLink = "/docs/v2/writing-algorithms/securities/asset-classes/crypto/handling-data#03-Trades";
36
$dataType = "TradeBar";
4-
?>
5-
6-
<p class='csharp'>
7-
To get historical <a href='<?=$dataTypeLink?>'>trade data</a>, call the <code>History&lt;<?=$dataType?>&gt;</code> method with an asset's <code>Symbol</code>.
8-
</p>
9-
10-
<p class='python'>
11-
To get historical <a href='<?=$dataTypeLink?>'>trade data</a>, call the <code>history</code> method with the <code><?=$dataType?></code> type and an asset's <code>Symbol</code>.
12-
This method returns a DataFrame with columns for the open, high, low, close, and volume.
13-
</p>
14-
15-
<div class="section-example-container">
16-
<pre class="csharp">public class CryptoTradeBarHistoryAlgorithm : QCAlgorithm
17-
{
18-
public override void Initialize()
19-
{
20-
SetStartDate(2024, 12, 19);
21-
// Get the Symbol of an asset.
22-
var symbol = AddCrypto("BTCUSD").Symbol;
23-
// Get the 5 trailing daily <?=$dataType?> objects of the asset.
24-
var history = History&lt;<?=$dataType?>&gt;(symbol, 5, Resolution.Daily);
25-
// Iterate through each TradeBar and calculate its dollar volume.
26-
foreach (var bar in history)
27-
{
28-
var t = bar.EndTime;
29-
var dollarVolume = bar.Close * bar.Volume;
30-
}
31-
}
32-
}</pre>
33-
<pre class="python">class CryptoTradeBarHistoryAlgorithm(QCAlgorithm):
34-
35-
def initialize(self) -> None:
36-
self.set_start_date(2024, 12, 19)
37-
# Get the Symbol of an asset.
38-
symbol = self.add_crypto('BTCUSD').symbol
39-
# Get the 5 trailing daily <?=$dataType?> objects of the asset in DataFrame format.
40-
history = self.history(<?=$dataType?>, symbol, 5, Resolution.DAILY)</pre>
41-
</div>
42-
43-
<table border="1" class="dataframe python">
7+
$dataFrame = "<table border='1' class='dataframe python'>
448
<thead>
45-
<tr style="text-align: right;">
9+
<tr style='text-align: right;'>
4610
<th></th>
4711
<th></th>
4812
<th>close</th>
@@ -63,7 +27,7 @@
6327
</thead>
6428
<tbody>
6529
<tr>
66-
<th rowspan="5" valign="top">BTCUSD</th>
30+
<th rowspan='5' valign='top'>BTCUSD</th>
6731
<th>2024-12-15</th>
6832
<td>101399.99</td>
6933
<td>102650.00</td>
@@ -104,33 +68,14 @@
10468
<td>21659.470502</td>
10569
</tr>
10670
</tbody>
107-
</table>
108-
109-
<div class="python section-example-container">
110-
<pre class="python"># Calculate the daily returns.
111-
daily_returns = history.close.pct_change().iloc[1:]</pre>
112-
</div>
71+
</table>";
11372

114-
<div class="python section-example-container">
115-
<pre>symbol time
73+
$series = "symbol time
11674
BTCUSD 2024-12-16 0.029979
11775
2024-12-17 0.015894
11876
2024-12-18 0.000473
11977
2024-12-19 -0.056517
120-
Name: close, dtype: float64</pre>
121-
</div>
122-
78+
Name: close, dtype: float64";
12379

124-
<p class='python'>
125-
If you intend to use the data in the DataFrame to create <code><?=$dataType?></code> objects, request that the history request returns the data type you need.
126-
Otherwise, LEAN consumes unnecessary computational resources populating the DataFrame.
127-
To get a list of <code><?=$dataType?></code> objects instead of a DataFrame, call the <code>history[<?=$dataType?>]</code> method.
128-
</p>
129-
130-
<div class="python section-example-container">
131-
<pre class="python"># Get the 5 trailing daily <?=$dataType?> objects of an asset in <?=$dataType?> format.
132-
history = self.history[<?=$dataType?>](symbol, 5, Resolution.DAILY)
133-
# Iterate through the TradeBar objects and access their volumes.
134-
for trade_bar in history:
135-
volume = trade_bar.volume</pre>
136-
</div>
80+
include(DOCS_RESOURCES."/history/tradebars.php");
81+
?>

0 commit comments

Comments
 (0)