YouTube2Text

How to set up a remote dev environment for algo-trading with Python in VSCode — Transcript

by Algo-trading with Saleh · 2,975 words · 482 segments · language en · Watch on YouTube

Full transcript

  1. 0:00let's say you have a great idea for a
  2. 0:02trading algorithm you're excited about
  3. 0:04it and you want to try it out but
  4. 0:06unfortunately your development
  5. 0:08environment is just not ready maybe it's
  6. 0:10because you haven't installed all the
  7. 0:11dependencies yet or maybe you are out of
  8. 0:14your office and cannot access your work
  9. 0:16computer or maybe you just want to play
  10. 0:18around with a couple of packages without
  11. 0:20messing up your existing environment if
  12. 0:22any of these describe your current
  13. 0:24situation you can use a remote dev
  14. 0:26environment
  15. 0:27it's really easy to set up at this after
  16. 0:29watching this tutorial and it's super
  17. 0:31affordable in fact you can get started
  18. 0:34for free
  19. 0:35[Music]
  20. 0:38when it comes to choosing a cloud server
  21. 0:40provider what we're looking for is a
  22. 0:42good balance of the quality and the
  23. 0:44price if you are living in the us i
  24. 0:46highly recommend using digitalocean
  25. 0:48there is starting server which is more
  26. 0:49than enough for our use case it starts
  27. 0:52from 5 bucks a month but if you use my
  28. 0:54link you can get it started for free the
  29. 0:56other cloud provider that i personally
  30. 0:58recommend and use is hestner their
  31. 1:01starting plan offers more resources for
  32. 1:03the same price and if you use my link
  33. 1:05you will get 20 euros free credits
  34. 1:08[Music]
  35. 1:11i already have a history account so i'm
  36. 1:13gonna log in
  37. 1:19i will choose the tutorials project
  38. 1:22since i'll be using this server for
  39. 1:24development is actually quite important
  40. 1:26if the location of the server is closest
  41. 1:28to me so that the ping would be lower
  42. 1:30for that reason i choose germany but you
  43. 1:32do whichever is closest to you
  44. 1:35ubuntu 2004 is exactly the image that i
  45. 1:38want so i'm not gonna change that
  46. 1:40i will choose the second server plan
  47. 1:42because for only 60 cents more per month
  48. 1:44i will get two cpu cores which i think
  49. 1:47totally worth it
  50. 1:50and now i have to choose the ssh key of
  51. 1:52my local machine
  52. 1:53in your case if your account is new you
  53. 1:55have to generate your ssh keys if you
  54. 1:58haven't already and add it by choosing
  55. 2:00the add ssh key button
  56. 2:02and at the end i will change the server
  57. 2:04name it's not really important what you
  58. 2:06set here but i prefer something that i
  59. 2:08can remember
  60. 2:10and now my server should be ready in
  61. 2:12just a few seconds
  62. 2:14for logging into my server i will be
  63. 2:16using the terminal app so i'm gonna copy
  64. 2:18the ip address from here
  65. 2:21and in my terminal i will type ssh root
  66. 2:24add sign and then paste my ip address it
  67. 2:26is asking me whether or not i trust this
  68. 2:28server and i do so i will type yes
  69. 2:32and we are in
  70. 2:34[Music]
  71. 2:37i will head over to jesse's
  72. 2:38documentation environment setup ubuntu
  73. 2:42and copy the command for running the
  74. 2:44installation script for ubuntu 2004
  75. 2:48i will place it here and press enter the
  76. 2:50installation process is going to take
  77. 2:52approximately seven minutes so i will
  78. 2:55skip this video and come back when it's
  79. 2:56done all right at the end it will ask
  80. 2:59you whether or not you want to change
  81. 3:00your default shell to z shell and i will
  82. 3:03type y to say yes
  83. 3:06at this point you should have everything
  84. 3:07installed just to check we will type
  85. 3:09python3
  86. 3:11python
  87. 3:12uppercase v and yes the python version
  88. 3:14is correct then i'll do the same for pip
  89. 3:17and just to show you a list of the
  90. 3:19packages that this script installed for
  91. 3:21us i will type pip list
  92. 3:24a couple of useful packages are y
  93. 3:27finance talib stats models
  94. 3:31quant stats
  95. 3:33numpy
  96. 3:34pandas and more
  97. 3:36let's create a new jesse project by
  98. 3:38copying the command from the
  99. 3:39documentation website and paste it into
  100. 3:42the terminal
  101. 3:44then i will cd into my project
  102. 3:46and create a new environment file by
  103. 3:48typing cp.mv.example.mv
  104. 3:53by typing ls i will see all the existing
  105. 3:56files inside my project
  106. 4:00now remember this is a remote server so
  107. 4:03to edit the files that are in it
  108. 4:05typically i have to use an editor that
  109. 4:07is already installed on that server by
  110. 4:10default the nano editor is what is
  111. 4:12installed on these types of server but
  112. 4:14the problem with it is that it kind of
  113. 4:16sucks and is very hard to use what i'd
  114. 4:18like to do instead is to open these
  115. 4:21files inside an editor that i am already
  116. 4:23used to such as pycharm or vs code
  117. 4:26fortunately there is an extension for vs
  118. 4:28code called remote ssh that allows us to
  119. 4:31do exactly that so go ahead download and
  120. 4:34install vs code for your platform if you
  121. 4:36haven't already and then head over and
  122. 4:38open the extensions section
  123. 4:41and inside the search box type remote
  124. 4:44via ssh
  125. 4:46choose the first result and click on the
  126. 4:48install button
  127. 4:53all right now that we have the extension
  128. 4:55installed it's time to connect to our
  129. 4:57server to connect to your server open
  130. 4:59the command palette by pressing command
  131. 5:02shift and p on mac or if you are on
  132. 5:04windows press shift control np
  133. 5:08and enter ssh
  134. 5:12and choose add new ssh host
  135. 5:15here i will type ssh root add sign and
  136. 5:18then paste in the ip address of my
  137. 5:20server and choose the first address for
  138. 5:21saving the configurations everything
  139. 5:24looks good i'm gonna open the command
  140. 5:25palette one more time and this time
  141. 5:27choose connect to host and choose the ip
  142. 5:29address of my server
  143. 5:33everything looks good if i run the ls
  144. 5:35command you will see my project files
  145. 5:37i'm going to sit into my project
  146. 5:39all right so now what i want to see is
  147. 5:41the files of the project inside vs codes
  148. 5:44built in explorer to open the project
  149. 5:47directory inside vs code i will click on
  150. 5:49the open folder button and choose my bot
  151. 5:52directory and click on the ok button
  152. 5:56and i will say yes i do trust the others
  153. 5:58which is me
  154. 6:00and now i can actually edit the project
  155. 6:02files that are hosted on the remote
  156. 6:04server as if they were hosted on my
  157. 6:06local machine it feels the same i can
  158. 6:08just edit something press save and
  159. 6:11that's it
  160. 6:13[Music]
  161. 6:17this looks really good but one thing
  162. 6:19that we're still missing is auto
  163. 6:21completion for instance let's say that i
  164. 6:24want to use the
  165. 6:25size to quantity utility function of
  166. 6:27jesse for that i can say quantity equals
  167. 6:31utils dot and now if you had auto
  168. 6:34completion i would have seen the methods
  169. 6:36that exist inside the utils module so to
  170. 6:39enable auto completion i need to install
  171. 6:42an extension so i will open the
  172. 6:44extension panel and look up python and
  173. 6:47intellisense is the extension that i
  174. 6:49want
  175. 6:51so i'll go ahead and click on the
  176. 6:53install in ssh green button it should
  177. 6:56take a few seconds
  178. 6:59so now if i head back to my strategy
  179. 7:02file remove the dot and press it again i
  180. 7:05will get auto completion so i'm gonna
  181. 7:08choose size to quantity
  182. 7:10and give it 500 bucks and the entry
  183. 7:12price would be my current price which is
  184. 7:14self.price
  185. 7:17and change the quantity from one to the
  186. 7:20quantity variable
  187. 7:22so now the editor can understand my
  188. 7:24python code and is able to help me write
  189. 7:27my strategies faster than before
  190. 7:32to start jesse i will open the built-in
  191. 7:35terminal inside vs code and execute
  192. 7:37jesse run
  193. 7:40the reason i'm getting this error is
  194. 7:42because by default the environment file
  195. 7:44that we created by copying from the
  196. 7:46example file is set to work with docker
  197. 7:49so for a native environment setup like
  198. 7:51ours we need to set postgres and redis
  199. 7:54hosts into localhost those values
  200. 7:56already exist so all i have to do now is
  201. 7:59to comment this line and uncomment this
  202. 8:01one and i'll do the same for redis
  203. 8:04all right let's give this another try
  204. 8:07and this time we get the database is not
  205. 8:09ready and after 10 seconds it fails with
  206. 8:12an authentication error that's because
  207. 8:15even though the installer script that we
  208. 8:17used earlier installed postgres for us
  209. 8:20it didn't create a database user and
  210. 8:22password so let's head over to the
  211. 8:24documentation again and navigate into
  212. 8:27the environment setup and under ubuntu
  213. 8:31you will find the postgresql section and
  214. 8:34i can just copy and paste these commands
  215. 8:36inside my terminal to create a username
  216. 8:39database and password
  217. 8:48so if i execute the command one more
  218. 8:51time it should work
  219. 8:55here's something really interesting
  220. 8:57usually when you're using jesse on a
  221. 8:58remote server you must use your server's
  222. 9:01external ip address in order to access
  223. 9:03it but vs code can do something magical
  224. 9:05for you if you run the same command
  225. 9:07inside vs code's built-in terminal it
  226. 9:09will automatically bind your local ip
  227. 9:11address into the remote server's
  228. 9:13external ip
  229. 9:15so if inside my local browser i enter
  230. 9:18localhost with 9000 port it will open
  231. 9:21the dashboard of my remote server and
  232. 9:23it's really cool because it feels like
  233. 9:25you're running things on your local
  234. 9:27machine and to prove it to you that this
  235. 9:29dashboard is indeed running on the
  236. 9:31remote server i will open the about
  237. 9:33section and as you can see the operating
  238. 9:35system is linux while my local machine
  239. 9:38is a mac so that's how i know this for
  240. 9:40sure
  241. 9:41[Music]
  242. 9:44to install jupyter lab inside the
  243. 9:46server's terminal i will execute pip
  244. 9:48install jewfighter lab it's going to
  245. 9:51take several seconds and now we can
  246. 9:53start using it to insert jupyter lab i
  247. 9:56will execute jupyter
  248. 9:58hyphen
  249. 9:59lab
  250. 10:00it throws an error saying that running
  251. 10:02as root is not recommended but i don't
  252. 10:05really mind it so i'm going to skip it
  253. 10:06by using the allow root flag at the end
  254. 10:09of it and just like before vs code is
  255. 10:12going to do its magic thing and bind my
  256. 10:15local address into the external ip
  257. 10:17address of the server so if i copy this
  258. 10:19url and paste it into my browser i
  259. 10:22should be able to see my jupyter lab
  260. 10:24workflow
  261. 10:26let's create a notebook to execute some
  262. 10:28python code in case you're not already
  263. 10:30familiar with due python notebooks they
  264. 10:32are great for researching using python
  265. 10:34they allow you to write your code inside
  266. 10:37separate blocks and see the result right
  267. 10:39there to show you a good example of this
  268. 10:42inside this notebook i'm gonna import
  269. 10:44some candles using jesse's research
  270. 10:46module calculate the 50 period sma of
  271. 10:50those candles and display both of them
  272. 10:52on a chart first i'm going to import a
  273. 10:55few libraries that i need
  274. 10:57from date time import date time
  275. 11:01import
  276. 11:02matplotlib
  277. 11:04dot
  278. 11:05pi plot
  279. 11:07as plt
  280. 11:09this next line is not actually required
  281. 11:11but i'm gonna do it just to silent an
  282. 11:13annoying warning of pandas
  283. 11:17next i will import the research module
  284. 11:19from jessie and also jesus technical
  285. 11:21indicator module
  286. 11:23ptc candles echo
  287. 11:27research dot
  288. 11:29get candles
  289. 11:31the first parameter is exchange name
  290. 11:34which i will pass binance
  291. 11:36the second one is the symbol which i
  292. 11:39will pass btc
  293. 11:41usdt
  294. 11:43i will pass 30 minutes as a time frame
  295. 11:47and then i will pass a starting date
  296. 11:49i want 10 days of candles
  297. 11:52from 10th of november 2021 until 10 days
  298. 11:55later
  299. 11:57if i execute this
  300. 11:59i will get an error saying that candle
  301. 12:02not found in database the reason i'm
  302. 12:04getting this error is because i didn't
  303. 12:06import any candles with jesse
  304. 12:09so i'm going to create a new terminal
  305. 12:11window on my vs code
  306. 12:13and execute the jsu-run command to
  307. 12:16run the dashboard
  308. 12:19after entering my password and logging
  309. 12:22in
  310. 12:23i'm gonna navigate into the import
  311. 12:25candles page
  312. 12:27and choose binance as my exchange
  313. 12:30btc usct as my symbol
  314. 12:34and change the starting date to 9th of
  315. 12:36november which is one day before the
  316. 12:37actual date that i need just in case the
  317. 12:40importing process is going to take
  318. 12:42approximately five minutes so i'm going
  319. 12:44to skip the video and come back when
  320. 12:46it's done
  321. 12:47all right now that we have our candles
  322. 12:49let's head back to the jupiter lab and
  323. 12:51try executing that block of code one
  324. 12:54more time
  325. 12:56this time i didn't get any errors which
  326. 12:58means it worked
  327. 12:59next i want the moving average of these
  328. 13:01candles with the period of 50. i can get
  329. 13:04that by saying ta.sma
  330. 13:08and pass in my candles
  331. 13:10and the next parameter is the period and
  332. 13:13because i need all the moving average
  333. 13:14values and not just the last one i'm
  334. 13:17going to pass sequential equals true
  335. 13:20just to be sure i'm gonna print the
  336. 13:22values
  337. 13:24i can minimize the output if i don't
  338. 13:26need it anymore by clicking on the blue
  339. 13:29line
  340. 13:31inside the chart i'm going to need only
  341. 13:33the closing prices and not the whole
  342. 13:34candles so i need a numpy array of the
  343. 13:37closing prices only and since jesse's
  344. 13:39candles have the type of numpy array
  345. 13:42that's easy to do
  346. 13:47let's print it just to be sure the
  347. 13:49format is correct
  348. 13:51and minimize it
  349. 13:54all right now i have everything that i
  350. 13:56need for my charts except for timestamps
  351. 13:58we already have timestamps in our
  352. 14:00candles but they are in the integer
  353. 14:02format which isn't what the matplotlib
  354. 14:04library expects
  355. 14:06so i need to convert them into datetime
  356. 14:08objects
  357. 14:10to do that i'm going to create a python
  358. 14:12list named times and then loop through
  359. 14:15every single candle
  360. 14:17create new time date out of those
  361. 14:19milliseconds timestamps and store it
  362. 14:21inside the times list
  363. 14:28let's print it just to make sure the
  364. 14:29format is correct
  365. 14:34and finally we can display our chart i
  366. 14:36will start by setting the size of my
  367. 14:38chart a little bigger than the default
  368. 14:44and then i will start by plotting btc
  369. 14:46close prices
  370. 14:49i can do that by saying plt dot plot
  371. 14:53which is a function
  372. 14:55and then i pass my timestamps and then
  373. 14:58btc close prices
  374. 15:01and i set the color to orange
  375. 15:05and i set the label to
  376. 15:07btc
  377. 15:10next i will plot
  378. 15:12the 50 moving average
  379. 15:14by typing plt dot plot
  380. 15:19and then again i pass timestamps
  381. 15:22moving average values
  382. 15:24and i set the color to
  383. 15:26black and the label to
  384. 15:29sma 50
  385. 15:32and finally to display the chart i will
  386. 15:34say plt dot legend
  387. 15:38oops look like i forgot
  388. 15:40an equal sign
  389. 15:42i'm sure you guys saw it
  390. 15:44let's give it another try and this time
  391. 15:46it works as you can see we have a chart
  392. 15:48with btc prizes and the 50 moving
  393. 15:51average this was a simple example but it
  394. 15:54shows you how powerful this thing could
  395. 15:55be
  396. 15:58[Music]
  397. 16:00this tutorial is almost done but before
  398. 16:02i leave you guys i want to show you a
  399. 16:03common problem with this setup and the
  400. 16:05solution for it when running python
  401. 16:07processes like we just did whether using
  402. 16:09the terminal app or vs code's built-in
  403. 16:11terminal one common problem is that
  404. 16:14sometimes you close the terminal session
  405. 16:16whether intentionally or accidentally
  406. 16:18but the process keeps running in the
  407. 16:20background so the next time that you try
  408. 16:22to run the same command it will fail
  409. 16:24saying that the port is already in use
  410. 16:26by another process there are a couple of
  411. 16:28ways to solve this problem my solution
  412. 16:30is to use a tool called a screen which
  413. 16:32gives you better control over your
  414. 16:34terminal sessions here let me show you
  415. 16:37you can install a screen on your server
  416. 16:39by running
  417. 16:40apt install python y screen
  418. 16:45in my case it's already installed
  419. 16:48and now instead of executing jsu-run
  420. 16:50directly
  421. 16:51first i will create an end screen
  422. 16:53i can do that by saying screen
  423. 16:55python uppercase s and then i pass in a
  424. 16:59name
  425. 16:59which makes reattaching easier
  426. 17:02for this process i will name it jesse
  427. 17:04and now i'm actually inside a new screen
  428. 17:07window
  429. 17:08so if i execute jsurun in here
  430. 17:12and close my terminal windows entirely
  431. 17:15i can later on open another terminal and
  432. 17:17reattach to the same window and to do
  433. 17:20that i will execute a screen python r
  434. 17:23and passing the name of that window
  435. 17:25which was jesse and i can just continue
  436. 17:28as if i never close the terminal at all
  437. 17:31now let's create another terminal window
  438. 17:33for jupiter screen
  439. 17:36hyphen uppercase s
  440. 17:40and i will name it dewpiter
  441. 17:42and to run jupiter i will
  442. 17:44execute jupiter
  443. 17:47lab
  444. 17:50then again i have to pass the allow root
  445. 17:53flag
  446. 17:56and then i can copy and paste this url
  447. 17:58inside my browser to use jupyter but
  448. 18:01sometimes when you are running the
  449. 18:02process inside a screen window the port
  450. 18:05binding of vs code doesn't work anymore
  451. 18:07so what i can do here is to replace
  452. 18:10localhost with the external ip address
  453. 18:12of my server the reason this isn't
  454. 18:14working now is because when i started
  455. 18:16jupyter i didn't specify a host address
  456. 18:19specifically so by default it uses
  457. 18:21localhost but to access the application
  458. 18:23using an external address i need to
  459. 18:26either specify the ip address or to
  460. 18:28allow it to serve the application to all
  461. 18:30addresses i can pass in four zeros so
  462. 18:34i'm gonna stop the session inter y
  463. 18:36so this time after writing the same
  464. 18:38command
  465. 18:39i will pass in the ip option
  466. 18:41with the value of
  467. 18:43zero zero zero zero
  468. 18:47now it doesn't matter which url i copy
  469. 18:49because i will be changing the hostname
  470. 18:51either way
  471. 18:52now i'm gonna paste in the ip address of
  472. 18:55my server
  473. 18:57and this time it should work
  474. 19:01let's do the same for jesse's dashboard
  475. 19:04and it works perfectly that's it for
  476. 19:07this tutorial this was just about the
  477. 19:08installation of the remote dev
  478. 19:10environment if you want to see examples
  479. 19:12of me using jc's research module make
  480. 19:15sure to subscribe because i will be
  481. 19:17making videos about that thanks for
  482. 19:19watching

About this transcript

This page contains the full transcript of How to set up a remote dev environment for algo-trading with Python in VSCode by Algo-trading with Saleh, generated from the public captions YouTube serves with the video. The transcript has 2,975 words across 482 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.

What you can do with it

Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to translate the transcript into 100+ languages.

Free YouTube transcript tool

YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, translation to 100+ languages, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.