{"cells":[{"cell_type":"markdown","metadata":{"id":"IBA0Y-jXHI9w"},"source":["# OBJEKTINIS PROGRAMAVIMAS"]},{"cell_type":"markdown","metadata":{"id":"kRgdtcSRHI9y"},"source":["### Duomenų atsisiuntimas (Coingecko API):"]},{"cell_type":"markdown","metadata":{"id":"HtRe1RqqHI9z"},"source":["ohlc (Open/High/Low/Close):"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"hiVG9XkQHI9z","outputId":"ee2ca931-c487-4761-8e0b-5cb29fee44a7"},"outputs":[{"name":"stdout","output_type":"stream","text":["OHLC Data for the Last 2 Days:\n","1717444800000\n","Time: 2024-06-03 20:00:00, Open: 69763.0, High: 69763.0, Low: 68875.0, Close: 69069.0\n","1717459200000\n","Time: 2024-06-04 00:00:00, Open: 69098.0, High: 69470.0, Low: 68732.0, Close: 68808.0\n","1717473600000\n","Time: 2024-06-04 04:00:00, Open: 68810.0, High: 69343.0, Low: 68744.0, Close: 69150.0\n","1717488000000\n","Time: 2024-06-04 08:00:00, Open: 69149.0, High: 69237.0, Low: 68732.0, Close: 69058.0\n","1717502400000\n","Time: 2024-06-04 12:00:00, Open: 68972.0, High: 69074.0, Low: 68544.0, Close: 68920.0\n","1717516800000\n","Time: 2024-06-04 16:00:00, Open: 68961.0, High: 70569.0, Low: 68844.0, Close: 70569.0\n","1717531200000\n","Time: 2024-06-04 20:00:00, Open: 70413.0, High: 71018.0, Low: 70062.0, Close: 70263.0\n","1717545600000\n","Time: 2024-06-05 00:00:00, Open: 70425.0, High: 70711.0, Low: 70201.0, Close: 70600.0\n","1717560000000\n","Time: 2024-06-05 04:00:00, Open: 70542.0, High: 71235.0, Low: 70444.0, Close: 70868.0\n","1717574400000\n","Time: 2024-06-05 08:00:00, Open: 70995.0, High: 71313.0, Low: 70869.0, Close: 71215.0\n","1717588800000\n","Time: 2024-06-05 12:00:00, Open: 71185.0, High: 71185.0, Low: 70710.0, Close: 70928.0\n","1717603200000\n","Time: 2024-06-05 16:00:00, Open: 70967.0, High: 71625.0, Low: 70409.0, Close: 71484.0\n","1717617600000\n","Time: 2024-06-05 20:00:00, Open: 71587.0, High: 71741.0, Low: 70888.0, Close: 71390.0\n","1717632000000\n","Time: 2024-06-06 00:00:00, Open: 71307.0, High: 71329.0, Low: 70895.0, Close: 71185.0\n","1717646400000\n","Time: 2024-06-06 04:00:00, Open: 71054.0, High: 71241.0, Low: 70939.0, Close: 71043.0\n","1717660800000\n","Time: 2024-06-06 08:00:00, Open: 71054.0, High: 71101.0, Low: 70787.0, Close: 71043.0\n","1717675200000\n","Time: 2024-06-06 12:00:00, Open: 71009.0, High: 71124.0, Low: 70891.0, Close: 71052.0\n","1717689600000\n","Time: 2024-06-06 16:00:00, Open: 71086.0, High: 71595.0, Low: 71005.0, Close: 71277.0\n","1717704000000\n","Time: 2024-06-06 20:00:00, Open: 71238.0, High: 71313.0, Low: 70475.0, Close: 70475.0\n","1717718400000\n","Time: 2024-06-07 00:00:00, Open: 70430.0, High: 70898.0, Low: 70066.0, Close: 70760.0\n","1717732800000\n","Time: 2024-06-07 04:00:00, Open: 70774.0, High: 70991.0, Low: 70661.0, Close: 70960.0\n","1717747200000\n","Time: 2024-06-07 08:00:00, Open: 70985.0, High: 71396.0, Low: 70985.0, Close: 71046.0\n","1717761600000\n","Time: 2024-06-07 12:00:00, Open: 71096.0, High: 71612.0, Low: 71025.0, Close: 71612.0\n","1717776000000\n","Time: 2024-06-07 16:00:00, Open: 71644.0, High: 71931.0, Low: 70743.0, Close: 71056.0\n","1717790400000\n","Time: 2024-06-07 20:00:00, Open: 71068.0, High: 71147.0, Low: 68856.0, Close: 69272.0\n","1717804800000\n","Time: 2024-06-08 00:00:00, Open: 69188.0, High: 69461.0, Low: 68972.0, Close: 69325.0\n","1717819200000\n","Time: 2024-06-08 04:00:00, Open: 69339.0, High: 69490.0, Low: 69260.0, Close: 69437.0\n","1717833600000\n","Time: 2024-06-08 08:00:00, Open: 69393.0, High: 69544.0, Low: 69223.0, Close: 69511.0\n","1717848000000\n","Time: 2024-06-08 12:00:00, Open: 69503.0, High: 69503.0, Low: 69309.0, Close: 69309.0\n","1717862400000\n","Time: 2024-06-08 16:00:00, Open: 69387.0, High: 69487.0, Low: 69206.0, Close: 69436.0\n","1717876800000\n","Time: 2024-06-08 20:00:00, Open: 69406.0, High: 69490.0, Low: 69305.0, Close: 69466.0\n","1717891200000\n","Time: 2024-06-09 00:00:00, Open: 69459.0, High: 69459.0, Low: 69284.0, Close: 69315.0\n","1717905600000\n","Time: 2024-06-09 04:00:00, Open: 69305.0, High: 69338.0, Low: 69158.0, Close: 69264.0\n","1717920000000\n","Time: 2024-06-09 08:00:00, Open: 69255.0, High: 69402.0, Low: 69224.0, Close: 69287.0\n","1717934400000\n","Time: 2024-06-09 12:00:00, Open: 69288.0, High: 69386.0, Low: 69271.0, Close: 69370.0\n","1717948800000\n","Time: 2024-06-09 16:00:00, Open: 69360.0, High: 69743.0, Low: 69214.0, Close: 69533.0\n","1717963200000\n","Time: 2024-06-09 20:00:00, Open: 69539.0, High: 69829.0, Low: 69513.0, Close: 69715.0\n","1717977600000\n","Time: 2024-06-10 00:00:00, Open: 69714.0, High: 69795.0, Low: 69561.0, Close: 69654.0\n","1717992000000\n","Time: 2024-06-10 04:00:00, Open: 69649.0, High: 69771.0, Low: 69446.0, Close: 69599.0\n","1718006400000\n","Time: 2024-06-10 08:00:00, Open: 69594.0, High: 69668.0, Low: 69303.0, Close: 69331.0\n","1718020800000\n","Time: 2024-06-10 12:00:00, Open: 69265.0, High: 69540.0, Low: 69265.0, Close: 69438.0\n","1718035200000\n","Time: 2024-06-10 16:00:00, Open: 69461.0, High: 70120.0, Low: 69240.0, Close: 70120.0\n"]}],"source":["import requests\n","from datetime import datetime\n","from dateutil import parser\n","\n","base_url = \"https://api.coingecko.com/api/v3/coins/bitcoin/ohlc\"\n","\n","params = {\n"," 'vs_currency': 'usd',\n"," 'days': '7',\n","}\n","\n","headers = {\n"," \"accept\": \"application/json\",\n"," \"x-cg-demo-api-key\": \"\"\n","}\n","\n","response = requests.get(base_url, params=params, headers=headers)\n","data = response.json()\n","\n","def format_timestamp(timestamp):\n"," return datetime.utcfromtimestamp(timestamp/1000).strftime('%Y-%m-%d %H:%M:%S')\n","\n","print(\"OHLC Data for the Last 2 Days:\")\n","#print(data)\n","for entry in data:\n"," print(entry[0])\n"," time = format_timestamp(entry[0])\n"," open_price = entry[1]\n"," high_price = entry[2]\n"," low_price = entry[3]\n"," close_price = entry[4]\n"," print(f\"Time: {time}, Open: {open_price}, High: {high_price}, Low: {low_price}, Close: {close_price}\")"]},{"cell_type":"markdown","metadata":{"id":"rmcsemXBHI91"},"source":["### Norint gauti VOLUME turime naudoti kitą nuorodą:"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"ci5jNO9hHI91","outputId":"84b1f5c5-6a33-4bf5-9bee-a54e5e4bb54c"},"outputs":[{"name":"stdout","output_type":"stream","text":["OHLC and Volume Data for the Last 7 Days:\n","Time: 2024-06-03 19:01:23, Price: 69222.414378, Volume: 30018278644.1606\n","Time: 2024-06-03 20:08:11, Price: 69290.18723123687, Volume: 29701192747.200317\n","Time: 2024-06-03 21:08:14, Price: 69123.47887328567, Volume: 29906664983.140537\n","Time: 2024-06-03 22:02:18, Price: 69013.04238036116, Volume: 30254954583.87357\n","Time: 2024-06-03 23:09:30, Price: 69005.28049701726, Volume: 30358753702.080475\n","Time: 2024-06-04 00:05:16, Price: 68809.78520249174, Volume: 25735381259.850346\n","Time: 2024-06-04 01:03:23, Price: 68993.03011420573, Volume: 30721958753.510273\n","Time: 2024-06-04 02:05:52, Price: 69187.85395378836, Volume: 29280880072.333164\n","Time: 2024-06-04 03:03:48, Price: 69097.86394215949, Volume: 28752894554.199627\n","Time: 2024-06-04 04:08:23, Price: 69068.12651217902, Volume: 29116866216.644135\n","Time: 2024-06-04 05:01:56, Price: 69041.25822711401, Volume: 28803440800.623695\n","Time: 2024-06-04 06:07:09, Price: 68864.94517712682, Volume: 28508162909.899426\n","Time: 2024-06-04 07:03:01, Price: 68913.88379627353, Volume: 26569740587.43989\n","Time: 2024-06-04 08:03:50, Price: 68972.13885024353, Volume: 27211254939.588264\n","Time: 2024-06-04 09:01:39, Price: 68804.00490025479, Volume: 26858437576.66786\n","Time: 2024-06-04 10:00:57, Price: 68544.20771408538, Volume: 27156789279.20647\n","Time: 2024-06-04 11:12:09, Price: 68943.40312278771, Volume: 26892740537.474834\n","Time: 2024-06-04 13:27:17, Price: 69272.28353960442, Volume: 25466083582.290916\n","Time: 2024-06-04 14:10:53, Price: 69839.98961512558, Volume: 23126914513.654984\n","Time: 2024-06-04 15:03:37, Price: 69644.11487424099, Volume: 25837218823.809067\n","Time: 2024-06-04 16:04:17, Price: 70413.21458461684, Volume: 26939408318.65423\n","Time: 2024-06-04 17:02:56, Price: 70770.46287594845, Volume: 27930208932.84292\n","Time: 2024-06-04 18:02:34, Price: 70582.78701003439, Volume: 29147665744.745632\n","Time: 2024-06-04 19:06:00, Price: 70725.13618285558, Volume: 30453315419.68153\n","Time: 2024-06-04 20:04:31, Price: 70425.01676590033, Volume: 31550806009.34074\n","Time: 2024-06-04 21:04:42, Price: 70432.54255820208, Volume: 31394646932.1266\n","Time: 2024-06-04 22:05:13, Price: 70618.36843943138, Volume: 31281193470.70335\n","Time: 2024-06-04 23:07:31, Price: 70526.14065753206, Volume: 31535031052.06846\n","Time: 2024-06-05 00:05:31, Price: 70542.10192339358, Volume: 31807659919.933342\n","Time: 2024-06-05 01:01:41, Price: 70800.51482374071, Volume: 31942981121.956753\n","Time: 2024-06-05 02:09:22, Price: 70876.573651482, Volume: 33549428909.636566\n","Time: 2024-06-05 03:02:31, Price: 70843.34092018707, Volume: 33802925021.480732\n","Time: 2024-06-05 04:00:50, Price: 70868.22714405037, Volume: 33893401267.12407\n","Time: 2024-06-05 05:01:27, Price: 71183.78135845078, Volume: 35071271770.20103\n","Time: 2024-06-05 06:01:50, Price: 71003.3250016292, Volume: 35888450946.553925\n","Time: 2024-06-05 07:00:26, Price: 71149.68396766191, Volume: 36601094148.26381\n","Time: 2024-06-05 08:04:20, Price: 71185.3088652343, Volume: 37020453255.09313\n","Time: 2024-06-05 09:07:36, Price: 70936.64700630313, Volume: 37305992748.97972\n","Time: 2024-06-05 10:02:53, Price: 70857.96640641778, Volume: 32308443302.82607\n","Time: 2024-06-05 11:00:25, Price: 70883.96030648473, Volume: 37289387522.71707\n","Time: 2024-06-05 12:07:45, Price: 70841.58894438873, Volume: 37428505065.4178\n","Time: 2024-06-05 13:04:29, Price: 70979.39844584733, Volume: 37916518163.04748\n","Time: 2024-06-05 14:08:16, Price: 70643.51067253706, Volume: 36505222742.33775\n","Time: 2024-06-05 15:04:34, Price: 70883.84892621133, Volume: 36144156310.39381\n","Time: 2024-06-05 16:03:20, Price: 71587.3390476925, Volume: 23408854375.070045\n","Time: 2024-06-05 17:01:35, Price: 71331.28620844566, Volume: 27438093045.026577\n","Time: 2024-06-05 18:05:31, Price: 71713.94076998901, Volume: 33501843930.990833\n","Time: 2024-06-05 19:05:36, Price: 71118.28092102184, Volume: 32315936125.059055\n","Time: 2024-06-05 20:08:08, Price: 71197.62590248944, Volume: 28080260257.52787\n","Time: 2024-06-05 21:01:14, Price: 71218.07366859974, Volume: 32268164469.349068\n","Time: 2024-06-05 22:04:41, Price: 71144.3179387504, Volume: 31983425815.78001\n","Time: 2024-06-05 23:04:02, Price: 71162.3800160821, Volume: 27403566370.597824\n","Time: 2024-06-06 00:03:53, Price: 71054.14439841534, Volume: 32449132584.340324\n","Time: 2024-06-06 01:04:53, Price: 70990.2501658845, Volume: 31666023356.144684\n","Time: 2024-06-06 02:07:48, Price: 71111.7771693848, Volume: 30396514135.31691\n","Time: 2024-06-06 03:03:50, Price: 71163.70801347587, Volume: 29754435794.37934\n","Time: 2024-06-06 04:04:16, Price: 71053.80230635182, Volume: 25087474397.087322\n","Time: 2024-06-06 05:07:17, Price: 71066.23543064836, Volume: 24328723156.625145\n","Time: 2024-06-06 06:01:25, Price: 70921.91695573041, Volume: 28166890221.34705\n","Time: 2024-06-06 07:07:46, Price: 70891.01993148876, Volume: 23228512662.126297\n","Time: 2024-06-06 08:08:01, Price: 70989.56581977903, Volume: 26536346312.95889\n","Time: 2024-06-06 09:04:37, Price: 70907.02219682894, Volume: 26073781369.281876\n","Time: 2024-06-06 10:06:18, Price: 70952.67189764655, Volume: 24255688211.885937\n","Time: 2024-06-06 11:00:05, Price: 70958.65300241375, Volume: 25207083528.522167\n","Time: 2024-06-06 12:02:46, Price: 71085.53126834088, Volume: 18284513402.94118\n","Time: 2024-06-06 13:01:11, Price: 71173.32805060249, Volume: 22353983551.987164\n","Time: 2024-06-06 14:02:22, Price: 71207.59435524222, Volume: 20117128630.54215\n","Time: 2024-06-06 15:04:16, Price: 71469.15438887932, Volume: 25169763523.085464\n","Time: 2024-06-06 16:02:27, Price: 71238.06260323075, Volume: 20680045468.15438\n","Time: 2024-06-06 17:07:41, Price: 70768.22344988026, Volume: 24435495547.735798\n","Time: 2024-06-06 18:07:32, Price: 71138.39580214774, Volume: 24514488917.096157\n","Time: 2024-06-06 19:00:55, Price: 71069.18929010618, Volume: 23088599940.250572\n","Time: 2024-06-06 20:02:23, Price: 70429.80683094825, Volume: 23298526166.933655\n","Time: 2024-06-06 21:08:48, Price: 70730.16396597322, Volume: 20573485330.701767\n","Time: 2024-06-06 22:04:48, Price: 70704.28903677444, Volume: 23983004831.8955\n","Time: 2024-06-06 23:01:55, Price: 70897.66575927468, Volume: 24254804207.39153\n","Time: 2024-06-07 00:05:07, Price: 70773.74598776827, Volume: 23542405680.725166\n","Time: 2024-06-07 01:03:09, Price: 70858.3516640106, Volume: 22915051048.664154\n","Time: 2024-06-07 02:00:15, Price: 70863.98433867987, Volume: 22865926781.2095\n","Time: 2024-06-07 03:06:26, Price: 70823.64754475745, Volume: 23285903776.776234\n","Time: 2024-06-07 04:08:06, Price: 71094.45975791331, Volume: 23840341525.191322\n","Time: 2024-06-07 05:05:56, Price: 71218.7556793813, Volume: 18572180777.719524\n","Time: 2024-06-07 06:01:00, Price: 71336.03392792157, Volume: 24502336247.901608\n","Time: 2024-06-07 07:00:25, Price: 71280.68092471165, Volume: 24535340895.689938\n","Time: 2024-06-07 08:02:45, Price: 71095.85098124442, Volume: 24753247002.675888\n","Time: 2024-06-07 09:00:57, Price: 71080.68182932476, Volume: 19962060424.69161\n","Time: 2024-06-07 10:06:27, Price: 71273.51614831026, Volume: 25032490299.454735\n","Time: 2024-06-07 11:03:24, Price: 71327.90048172572, Volume: 25082309492.06385\n","Time: 2024-06-07 12:05:06, Price: 71643.88933000261, Volume: 24910257624.061897\n","Time: 2024-06-07 13:06:42, Price: 71186.33669913492, Volume: 27726107166.293755\n","Time: 2024-06-07 14:08:29, Price: 71355.1403021001, Volume: 29110210418.141735\n","Time: 2024-06-07 15:07:34, Price: 71341.85799237363, Volume: 28533090814.15139\n","Time: 2024-06-07 16:07:14, Price: 70950.07816989005, Volume: 29034459548.19106\n","Time: 2024-06-07 17:03:09, Price: 70768.04687954747, Volume: 24151162065.934326\n","Time: 2024-06-07 18:03:14, Price: 69678.62142097896, Volume: 25281609856.78319\n","Time: 2024-06-07 19:04:24, Price: 69123.85740127321, Volume: 33886460645.07946\n","Time: 2024-06-07 20:07:53, Price: 69096.92925087264, Volume: 30518286007.66723\n","Time: 2024-06-07 21:07:51, Price: 69228.75408533507, Volume: 33795460102.69083\n","Time: 2024-06-07 22:03:53, Price: 69218.12095730139, Volume: 34803202951.225845\n","Time: 2024-06-07 23:01:43, Price: 69461.03394002216, Volume: 29971593945.38651\n","Time: 2024-06-08 00:05:40, Price: 69260.21173528439, Volume: 34530240693.47627\n","Time: 2024-06-08 01:01:55, Price: 69382.28142333424, Volume: 29896818076.678574\n","Time: 2024-06-08 02:04:38, Price: 69425.41471694803, Volume: 33931602012.927334\n","Time: 2024-06-08 03:07:33, Price: 69409.18581526849, Volume: 34156263058.001987\n","Time: 2024-06-08 04:01:40, Price: 69392.79120773365, Volume: 34777753548.18209\n","Time: 2024-06-08 05:02:43, Price: 69308.10284340921, Volume: 29490345701.12805\n","Time: 2024-06-08 06:04:43, Price: 69288.12202319676, Volume: 32336587511.897495\n","Time: 2024-06-08 07:03:23, Price: 69308.1573604734, Volume: 32696236402.042667\n","Time: 2024-06-08 08:05:08, Price: 69503.48114691078, Volume: 22182930704.80761\n","Time: 2024-06-08 09:08:16, Price: 69391.17587185616, Volume: 26985809860.280293\n","Time: 2024-06-08 10:02:58, Price: 69422.0549280154, Volume: 31130109779.05146\n","Time: 2024-06-08 11:05:32, Price: 69432.25588125558, Volume: 31637000794.878254\n","Time: 2024-06-08 12:07:38, Price: 69258.72930891113, Volume: 30444607252.586044\n","Time: 2024-06-08 13:00:08, Price: 69337.60341855812, Volume: 21278674018.799137\n","Time: 2024-06-08 14:05:16, Price: 69410.6900283224, Volume: 22416729426.38913\n","Time: 2024-06-08 15:03:55, Price: 69443.1469916804, Volume: 24793573162.39803\n","Time: 2024-06-08 16:04:09, Price: 69405.63763463982, Volume: 18643901114.6999\n","Time: 2024-06-08 17:07:54, Price: 69361.46134430173, Volume: 23240462940.428947\n","Time: 2024-06-08 18:02:31, Price: 69439.96089497658, Volume: 21706735146.153076\n","Time: 2024-06-08 19:09:28, Price: 69487.75689863384, Volume: 15944945605.432377\n","Time: 2024-06-08 20:07:12, Price: 69449.81437968381, Volume: 14323080270.105919\n","Time: 2024-06-08 21:00:38, Price: 69359.75273517056, Volume: 10920602546.69344\n","Time: 2024-06-08 22:07:06, Price: 69396.27529521167, Volume: 12555336072.788439\n","Time: 2024-06-08 23:06:45, Price: 69311.00170202478, Volume: 12957020044.270039\n","Time: 2024-06-09 00:03:33, Price: 69305.38413230315, Volume: 12847962289.456978\n","Time: 2024-06-09 01:00:27, Price: 69271.82967363774, Volume: 10066718992.903212\n","Time: 2024-06-09 02:06:56, Price: 69294.7352566043, Volume: 12256443708.45615\n","Time: 2024-06-09 03:07:23, Price: 69189.27484588115, Volume: 9810267642.45181\n","Time: 2024-06-09 04:05:57, Price: 69255.12336023682, Volume: 12471446688.148481\n","Time: 2024-06-09 05:08:07, Price: 69268.84907656063, Volume: 11802177182.232487\n","Time: 2024-06-09 06:02:30, Price: 69301.42826402026, Volume: 11543478483.317194\n","Time: 2024-06-09 07:08:09, Price: 69402.31338469898, Volume: 11924620294.002207\n","Time: 2024-06-09 08:04:36, Price: 69288.40380070929, Volume: 11704771165.89392\n","Time: 2024-06-09 09:03:56, Price: 69341.41547524066, Volume: 10767884026.333746\n","Time: 2024-06-09 10:02:08, Price: 69358.75947957805, Volume: 8083520040.423612\n","Time: 2024-06-09 11:07:55, Price: 69355.05403630743, Volume: 11071015486.305046\n","Time: 2024-06-09 12:05:02, Price: 69359.77053101533, Volume: 10035350491.603842\n","Time: 2024-06-09 13:00:40, Price: 69739.25483618052, Volume: 10516657684.233894\n","Time: 2024-06-09 14:04:39, Price: 69464.54727961162, Volume: 11297784378.652313\n","Time: 2024-06-09 15:01:52, Price: 69489.02263323929, Volume: 11553052270.80147\n","Time: 2024-06-09 16:08:47, Price: 69512.58598901884, Volume: 11572887601.519272\n","Time: 2024-06-09 17:05:10, Price: 69636.44792486633, Volume: 11652997673.72068\n","Time: 2024-06-09 18:02:01, Price: 69658.46681164297, Volume: 8892545791.355675\n","Time: 2024-06-09 19:05:09, Price: 69737.12919334027, Volume: 11181055187.672602\n","Time: 2024-06-09 20:06:42, Price: 69649.06870027601, Volume: 12243631285.687578\n","Time: 2024-06-09 21:00:39, Price: 69681.23501022052, Volume: 9639902370.746393\n","Time: 2024-06-09 22:08:33, Price: 69705.3147840307, Volume: 12450794791.207031\n","Time: 2024-06-09 23:01:31, Price: 69616.31203554032, Volume: 12405209299.492361\n","Time: 2024-06-10 00:07:00, Price: 69600.84597186842, Volume: 12177078985.637917\n","Time: 2024-06-10 01:03:19, Price: 69556.82634403778, Volume: 12674997971.943167\n","Time: 2024-06-10 02:04:03, Price: 69601.3025268636, Volume: 12821436653.12271\n","Time: 2024-06-10 03:04:19, Price: 69699.90448151037, Volume: 12391073288.204947\n","Time: 2024-06-10 04:03:02, Price: 69593.50742064392, Volume: 9463972664.40574\n","Time: 2024-06-10 05:01:18, Price: 69668.47016488576, Volume: 12786445630.355762\n","Time: 2024-06-10 06:05:09, Price: 69532.87864605538, Volume: 11321024709.35716\n","Time: 2024-06-10 07:05:51, Price: 69400.28705440945, Volume: 11765945602.861357\n","Time: 2024-06-10 08:07:55, Price: 69371.00641265, Volume: 14182912692.154623\n","Time: 2024-06-10 09:06:06, Price: 69384.4040382232, Volume: 14480867950.88864\n","Time: 2024-06-10 10:02:39, Price: 69425.34660664776, Volume: 12575088777.254637\n","Time: 2024-06-10 11:00:51, Price: 69432.85832587274, Volume: 15209188235.74221\n","Time: 2024-06-10 12:07:43, Price: 69407.0113316572, Volume: 15431534376.450335\n","Time: 2024-06-10 13:05:03, Price: 69284.76519309687, Volume: 13561423862.636637\n","Time: 2024-06-10 14:01:04, Price: 69330.06966003006, Volume: 14748983511.134398\n","Time: 2024-06-10 15:09:19, Price: 69642.34736119978, Volume: 15131749929.976673\n","Time: 2024-06-10 16:07:55, Price: 70026.23809524855, Volume: 16722170218.940643\n","Time: 2024-06-10 17:04:01, Price: 69968.38351995572, Volume: 15317364706.86971\n","Time: 2024-06-10 18:09:58, Price: 69934.87931158906, Volume: 17755231708.302704\n","Time: 2024-06-10 18:26:01, Price: 69849.0972479416, Volume: 18112300454.465282\n"]}],"source":["import requests\n","from datetime import datetime\n","\n","base_url = \"https://api.coingecko.com/api/v3/coins/bitcoin/market_chart\"\n","\n","params = {\n"," 'vs_currency': 'usd',\n"," 'days': '7' # Get data for the last 7 days\n","}\n","\n","headers = {\n"," \"accept\": \"application/json\",\n"," \"x-cg-demo-api-key\": \"CG-HWFe76jzP5YcNf1qKdiSY4VL\"\n","}\n","\n","response = requests.get(base_url, params=params, headers=headers)\n","data = response.json()\n","\n","def format_timestamp(timestamp):\n"," return datetime.utcfromtimestamp(timestamp / 1000).strftime('%Y-%m-%d %H:%M:%S')\n","\n","prices = data['prices']\n","volumes = data['total_volumes']\n","\n","\n","print(\"OHLC and Volume Data for the Last 7 Days:\")\n","for i in range(len(prices)):\n"," time = format_timestamp(prices[i][0])\n"," price = prices[i][1]\n"," volume = volumes[i][1]\n"," print(f\"Time: {time}, Price: {price}, Volume: {volume}\")"]},{"cell_type":"markdown","metadata":{"id":"uyo9L22WHI92"},"source":["### Sujungiame abi užklausas bei išfiltruojame po vieną įrašą iš 2 paskutinių dienų:"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"bQQvAxL7HI92","outputId":"192d8493-3622-45ed-9bf1-fcbabe0ad039"},"outputs":[{"name":"stdout","output_type":"stream","text":["{'date': '2024-06-09 00:00:00', 'open': 69459.0, 'high': 69459.0, 'low': 69284.0, 'close': 69315.0, 'volume': 12847962289.456978}\n","{'date': '2024-06-10 00:00:00', 'open': 69714.0, 'high': 69795.0, 'low': 69561.0, 'close': 69654.0, 'volume': 12177078985.637917}\n"]}],"source":["import requests\n","from datetime import datetime, timedelta\n","\n","ohlc_url = \"https://api.coingecko.com/api/v3/coins/bitcoin/ohlc\"\n","market_chart_url = \"https://api.coingecko.com/api/v3/coins/bitcoin/market_chart\"\n","params = {\n"," 'vs_currency': 'usd',\n"," 'days': '7'\n","}\n","headers = {\n"," \"accept\": \"application/json\",\n"," \"x-cg-demo-api-key\": \"CG-HWFe76jzP5YcNf1qKdiSY4VL\"\n","}\n","\n","def is_midnight(timestamp):\n"," dt = datetime.utcfromtimestamp(timestamp / 1000)\n"," return dt.hour == 0 and dt.minute == 0 and dt.second == 0\n","\n","def format_timestamp(timestamp):\n"," return datetime.utcfromtimestamp(timestamp / 1000).strftime('%Y-%m-%d %H:%M:%S')\n","\n","def find_closest_volume(timestamp, volume_data):\n"," closest_volume, closest_diff = None, 10e10\n"," for vol_entry in volume_data:\n"," vol_timestamp = vol_entry[0]\n"," diff = abs(timestamp - vol_timestamp)\n"," if diff < closest_diff:\n"," closest_diff = diff\n"," closest_volume = vol_entry[1]\n"," closest_timestamp = vol_timestamp\n"," return closest_volume\n","\n","response_ohlc = requests.get(ohlc_url, params=params, headers=headers)\n","response_market_chart = requests.get(market_chart_url, params=params, headers=headers)\n","\n","if response_ohlc.ok and response_market_chart.ok:\n"," ohlc_data = response_ohlc.json()\n"," market_data = response_market_chart.json()\n"," results = []\n"," today = datetime.utcnow()\n"," start_date = today - timedelta(days=2)\n"," for entry in ohlc_data:\n"," timestamp = entry[0]\n"," if is_midnight(timestamp) and datetime.utcfromtimestamp(timestamp / 1000) >= start_date:\n"," open_price, high_price, low_price, close_price = entry[1:]\n"," time_formatted = format_timestamp(timestamp)\n"," volume = find_closest_volume(timestamp, market_data['total_volumes'])\n"," results.append({\n"," 'date': time_formatted,\n"," 'open': open_price,\n"," 'high': high_price,\n"," 'low': low_price,\n"," 'close': close_price,\n"," 'volume': volume\n"," })\n"," for result in results:\n"," print(result)\n","else:\n"," if response_ohlc.status_code != 200: print(f'bitcoin/ohlc ERROR: {response_ohlc.text}')\n"," if response_market_chart.status_code != 200: print(f'bitcoin/market_chart ERROR: {response_market_chart.text}')\n"]},{"cell_type":"markdown","metadata":{"id":"vvN_NML_HI93"},"source":["# Aplikacija su integruotu Coingecko API:"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"WkK3eUhJHI93"},"outputs":[],"source":["import pandas as pd\n","from sklearn.preprocessing import StandardScaler\n","from sklearn.linear_model import Lasso\n","from sklearn.ensemble import RandomForestRegressor\n","import sqlite3\n","import warnings\n","import requests\n","from datetime import datetime, timedelta\n","\n","class BTCModel:\n"," def __init__(self, data_path, reviews_path, random_forest=False, use_extended_features=False):\n"," self.btc_all = pd.read_csv(data_path)\n"," self.reviews = pd.read_csv(reviews_path, sep='|')\n"," self.scaler = StandardScaler()\n"," self.random_forest = random_forest\n"," self.use_extended_features = use_extended_features\n","\n"," if random_forest:\n"," self.model = RandomForestRegressor(\n"," max_depth=None, min_samples_leaf=2, min_samples_split=2, n_estimators=300, random_state=73\n"," )\n"," else:\n"," self.model = Lasso(alpha=75, max_iter=25000, tol=0.001, random_state=0)\n","\n"," self._preprocess()\n"," self._train()\n","\n"," def _preprocess(self):\n"," self.reviews['Date'] = pd.to_datetime(self.reviews['Date'], errors='coerce')\n"," self.reviews = self.reviews.dropna(subset=['Date'])\n"," self.reviews['YearMonth'] = self.reviews['Date'].dt.to_period('M')\n"," monthly_mean_rating = self.reviews.groupby('YearMonth')['Rating'].mean().reset_index()\n"," monthly_mean_rating['Date'] = monthly_mean_rating['YearMonth'].dt.to_timestamp()\n"," self.btc_all['Date'] = pd.to_datetime(self.btc_all['Date'])\n"," self.btc_all['YearMonth'] = self.btc_all['Date'].dt.to_period('M')\n"," btc_merged = pd.merge(self.btc_all, monthly_mean_rating, on='YearMonth', how='left')\n"," btc_merged['Date'] = btc_merged['Date_x']\n"," btc_merged = btc_merged.drop(columns=['Date_x', 'Date_y'])\n"," btc_merged['Rating'].fillna(method='ffill', inplace=True)\n"," btc_merged['Lag_Close_1'] = btc_merged['Close'].shift(1)\n"," btc_merged['Lag_Close_2'] = btc_merged['Close'].shift(2)\n"," btc_merged['Lag_Volume_1'] = btc_merged['Volume'].shift(1)\n"," btc_merged['Lag_Volume_2'] = btc_merged['Volume'].shift(2)\n"," btc_merged['Lag_Open_1'] = btc_merged['Open'].shift(1)\n"," btc_merged['Lag_Open_2'] = btc_merged['Open'].shift(2)\n"," btc_merged['Lag_High_1'] = btc_merged['High'].shift(1)\n"," btc_merged['Lag_High_2'] = btc_merged['High'].shift(2)\n"," btc_merged['Lag_Low_1'] = btc_merged['Low'].shift(1)\n"," btc_merged['Lag_Low_2'] = btc_merged['Low'].shift(2)\n"," btc_merged.dropna(inplace=True)\n"," btc_merged['Day'] = btc_merged['Date'].dt.day\n"," btc_merged['Month'] = btc_merged['Date'].dt.month\n"," btc_merged['Year'] = btc_merged['Date'].dt.year\n"," self.btc_all = btc_merged\n","\n"," def _train(self):\n"," if self.use_extended_features:\n"," features = [\n"," 'Lag_Close_1', 'Lag_Close_2', 'Lag_Volume_1', 'Lag_Volume_2',\n"," 'Lag_Open_1', 'Lag_Open_2', 'Lag_High_1', 'Lag_High_2', 'Lag_Low_1', 'Lag_Low_2',\n"," 'Day', 'Month', 'Year', 'Rating'\n"," ]\n"," else:\n"," features = [\n"," 'Lag_Close_1', 'Lag_Close_2', 'Lag_Volume_1', 'Lag_Volume_2',\n"," 'Day', 'Month', 'Year', 'Rating'\n"," ]\n","\n"," X = self.btc_all[features]\n"," y = self.btc_all['Close']\n","\n"," assert len(X) == len(y), \"Feature X and target y arrays length mismatch!\"\n","\n"," X_train = X.copy()\n"," y_train = y.copy()\n","\n"," assert len(X_train) == len(y_train), \"Training feature X_train and target arrays y_train length mismatch!\"\n","\n"," X_train = self.scaler.fit_transform(X_train)\n"," self.model.fit(X_train, y_train)\n","\n"," def _fetch_coingecko_data(self):\n"," ohlc_url = \"https://api.coingecko.com/api/v3/coins/bitcoin/ohlc\"\n"," market_chart_url = \"https://api.coingecko.com/api/v3/coins/bitcoin/market_chart\"\n"," params = {\n"," 'vs_currency': 'usd',\n"," 'days': '7'\n"," }\n"," headers = {\n"," \"accept\": \"application/json\",\n"," \"x-cg-demo-api-key\": \"CG-HWFe76jzP5YcNf1qKdiSY4VL\"\n"," }\n","\n"," response_ohlc = requests.get(ohlc_url, params=params, headers=headers)\n"," response_market_chart = requests.get(market_chart_url, params=params, headers=headers)\n","\n"," if response_ohlc.ok and response_market_chart.ok:\n"," ohlc_data = response_ohlc.json()\n"," market_data = response_market_chart.json()\n"," results = []\n"," today = datetime.utcnow()\n"," start_date = today - timedelta(days=2)\n"," for entry in ohlc_data:\n"," timestamp = entry[0]\n"," if self._is_midnight(timestamp) and datetime.utcfromtimestamp(timestamp / 1000) >= start_date:\n"," open_price, high_price, low_price, close_price = entry[1:]\n"," time_formatted = self._format_timestamp(timestamp)\n"," volume = self._find_closest_volume(timestamp, market_data['total_volumes'])\n"," results.append({\n"," 'date': time_formatted,\n"," 'open': open_price,\n"," 'high': high_price,\n"," 'low': low_price,\n"," 'close': close_price,\n"," 'volume': volume\n"," })\n"," for result in results:\n"," print(result)\n"," return results\n"," else:\n"," if response_ohlc.status_code != 200:\n"," print(f'bitcoin/ohlc ERROR: {response_ohlc.text}')\n"," if response_market_chart.status_code != 200:\n"," print(f'bitcoin/market_chart ERROR: {response_market_chart.text}')\n"," raise ValueError(\"API ERROR.\")\n","\n"," def _get_lag_data_from_api(self):\n"," btc_data = self._fetch_coingecko_data()\n"," date_plus_one = datetime.now() + timedelta(days=1)\n"," data = {\n"," 'Lag_Close_1': btc_data[1]['close'],\n"," 'Lag_Close_2': btc_data[0]['close'],\n"," 'Lag_Volume_1': btc_data[1]['volume'],\n"," 'Lag_Volume_2': btc_data[0]['volume'],\n"," 'Lag_Open_1': btc_data[1]['open'],\n"," 'Lag_Open_2': btc_data[0]['open'],\n"," 'Lag_High_1': btc_data[1]['high'],\n"," 'Lag_High_2': btc_data[0]['high'],\n"," 'Lag_Low_1': btc_data[1]['low'],\n"," 'Lag_Low_2': btc_data[0]['low'],\n"," 'Day': date_plus_one.day,\n"," 'Month': date_plus_one.month,\n"," 'Year': date_plus_one.year,\n"," 'Rating': 1.4\n"," }\n"," return data\n","\n"," def predict(self, user_input=None, date=None, use_api=False):\n"," warnings.filterwarnings(\"ignore\", message=\"X does not have valid feature names, but StandardScaler was fitted with feature names\")\n"," if use_api:\n"," user_input_processed = self._get_lag_data_from_api()\n"," user_input_scaled = self.scaler.transform([list(user_input_processed.values())])\n"," elif user_input is not None and date is None:\n"," user_input_processed = self._preprocess_user_input(user_input)\n"," user_input_scaled = self.scaler.transform([user_input_processed])\n"," elif date is not None:\n"," user_input = self._get_lag_data(date)\n"," user_input_scaled = self.scaler.transform([list(user_input.values())])\n"," else:\n"," raise ValueError(\"ERROR.\")\n","\n"," prediction = self.model.predict(user_input_scaled)\n"," return prediction[0]\n","\n"," def _preprocess_user_input(self, user_input):\n"," if self.use_extended_features:\n"," return [\n"," user_input['Lag_Close_1'],\n"," user_input['Lag_Close_2'],\n"," user_input['Lag_Volume_1'],\n"," user_input['Lag_Volume_2'],\n"," user_input['Lag_Open_1'],\n"," user_input['Lag_Open_2'],\n"," user_input['Lag_High_1'],\n"," user_input['Lag_High_2'],\n"," user_input['Lag_Low_1'],\n"," user_input['Lag_Low_2'],\n"," user_input['Day'],\n"," user_input['Month'],\n"," user_input['Year'],\n"," user_input['Rating']\n"," ]\n"," else:\n"," return [\n"," user_input['Lag_Close_1'],\n"," user_input['Lag_Close_2'],\n"," user_input['Lag_Volume_1'],\n"," user_input['Lag_Volume_2'],\n"," user_input['Day'],\n"," user_input['Month'],\n"," user_input['Year'],\n"," user_input['Rating']\n"," ]\n","\n"," def _get_lag_data(self, date):\n"," date = pd.to_datetime(date)\n"," if date > self.btc_all['Date'].max():\n"," most_recent = self.btc_all.iloc[-1]\n"," if self.use_extended_features:\n"," return {\n"," 'Lag_Close_1': most_recent['Close'],\n"," 'Lag_Close_2': most_recent['Lag_Close_1'],\n"," 'Lag_Volume_1': most_recent['Volume'],\n"," 'Lag_Volume_2': most_recent['Lag_Volume_1'],\n"," 'Lag_Open_1': most_recent['Open'],\n"," 'Lag_Open_2': most_recent['Lag_Open_1'],\n"," 'Lag_High_1': most_recent['High'],\n"," 'Lag_High_2': most_recent['Lag_High_1'],\n"," 'Lag_Low_1': most_recent['Low'],\n"," 'Lag_Low_2': most_recent['Lag_Low_1'],\n"," 'Day': date.day,\n"," 'Month': date.month,\n"," 'Year': date.year,\n"," 'Rating': most_recent['Rating']\n"," }\n"," else:\n"," return {\n"," 'Lag_Close_1': most_recent['Close'],\n"," 'Lag_Close_2': most_recent['Lag_Close_1'],\n"," 'Lag_Volume_1': most_recent['Volume'],\n"," 'Lag_Volume_2': most_recent['Lag_Volume_1'],\n"," 'Day': date.day,\n"," 'Month': date.month,\n"," 'Year': date.year,\n"," 'Rating': most_recent['Rating']\n"," }\n"," row = self.btc_all[self.btc_all['Date'] == date]\n"," if row.empty:\n"," row = self.btc_all[self.btc_all['Date'] < date].iloc[-1]\n"," if self.use_extended_features:\n"," return {\n"," 'Lag_Close_1': row['Lag_Close_1'].values[0],\n"," 'Lag_Close_2': row['Lag_Close_2'].values[0],\n"," 'Lag_Volume_1': row['Lag_Volume_1'].values[0],\n"," 'Lag_Volume_2': row['Lag_Volume_2'].values[0],\n"," 'Lag_Open_1': row['Lag_Open_1'].values[0],\n"," 'Lag_Open_2': row['Lag_Open_2'].values[0],\n"," 'Lag_High_1': row['Lag_High_1'].values[0],\n"," 'Lag_High_2': row['Lag_High_2'].values[0],\n"," 'Lag_Low_1': row['Lag_Low_1'].values[0],\n"," 'Lag_Low_2': row['Lag_Low_2'].values[0],\n"," 'Day': date.day,\n"," 'Month': date.month,\n"," 'Year': date.year,\n"," 'Rating': row['Rating'].values[0]\n"," }\n"," else:\n"," return {\n"," 'Lag_Close_1': row['Lag_Close_1'].values[0],\n"," 'Lag_Close_2': row['Lag_Close_2'].values[0],\n"," 'Lag_Volume_1': row['Lag_Volume_1'].values[0],\n"," 'Lag_Volume_2': row['Lag_Volume_2'].values[0],\n"," 'Day': date.day,\n"," 'Month': date.month,\n"," 'Year': date.year,\n"," 'Rating': row['Rating'].values[0]\n"," }\n","\n"," def _is_midnight(self, timestamp):\n"," dt = datetime.utcfromtimestamp(timestamp / 1000)\n"," return dt.hour == 0 and dt.minute == 0 and dt.second == 0\n","\n"," def _format_timestamp(self, timestamp):\n"," return datetime.utcfromtimestamp(timestamp / 1000).strftime('%Y-%m-%d %H:%M:%S')\n","\n"," def _find_closest_volume(self, timestamp, volume_data):\n"," closest_volume, closest_diff = None, 10e10\n"," for vol_entry in volume_data:\n"," vol_timestamp = vol_entry[0]\n"," diff = abs(timestamp - vol_timestamp)\n"," if diff < closest_diff:\n"," closest_diff = diff\n"," closest_volume = vol_entry[1]\n"," return closest_volume\n","\n","class user_inputDatabase:\n"," def __init__(self, db_path):\n"," self.db_path = db_path\n"," self._initialize_db()\n","\n"," def _initialize_db(self):\n"," conn = sqlite3.connect(self.db_path)\n"," c = conn.cursor()\n"," c.execute('''CREATE TABLE IF NOT EXISTS user_inputs\n"," (Lag_Close_1 REAL, Lag_Close_2 REAL, Lag_Volume_1 REAL, Lag_Volume_2 REAL,\n"," Lag_Open_1 REAL, Lag_Open_2 REAL, Lag_High_1 REAL, Lag_High_2 REAL, Lag_Low_1 REAL, Lag_Low_2 REAL,\n"," Day INTEGER, Month INTEGER, Year INTEGER, Rating REAL)''')\n"," conn.commit()\n"," conn.close()\n","\n"," def save_user_input(self, user_input):\n"," conn = sqlite3.connect(self.db_path)\n"," c = conn.cursor()\n"," columns = ', '.join(user_input.keys())\n"," placeholders = ', '.join('?' * len(user_input))\n"," values = tuple(user_input.values())\n","\n"," query = f\"INSERT INTO user_inputs ({columns}) VALUES ({placeholders})\"\n"," c.execute(query, values)\n","\n"," conn.commit()\n"," conn.close()\n"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"G47qeNmgHI94","outputId":"ddaf22c6-e075-4f4f-dbac-2df9c60fb459"},"outputs":[{"name":"stdout","output_type":"stream","text":["BTC Prediction Model\n","Norėdami įšeiti įveskite 'q'\n","Nuspėjama modelio BTC kaina šiam laikotarpiui (2024-9-1) --> 69,031.21 USD <--\n"]}],"source":["import json\n","from datetime import datetime\n","\n","try_again = 'Neteisinga įvestis, bandykite dar kartą.'\n","\n","def get_float_input(prompt, quit_char='q'):\n"," while True:\n"," inp = input(prompt).strip().lower()\n"," if inp == quit_char:\n"," return quit_char\n"," try:\n"," return float(inp)\n"," except ValueError:\n"," print(try_again)\n","\n","def get_int_input(prompt, quit_char='q'):\n"," while True:\n"," inp = input(prompt).strip().lower()\n"," if inp == quit_char:\n"," return quit_char\n"," try:\n"," return int(inp)\n"," except ValueError:\n"," print(try_again)\n","\n","def get_date_input(prompt, format=\"%Y-%m-%d\", quit_char='q'):\n"," while True:\n"," inp = input(prompt).strip().lower()\n"," if inp == quit_char:\n"," return quit_char\n"," try:\n"," return datetime.strptime(inp, format)\n"," except ValueError:\n"," print(try_again)\n","\n","def main():\n"," db_path = 'inputs_btc2_advanced.db'\n"," user_db = user_inputDatabase(db_path)\n"," print(\"BTC Prediction Model\")\n"," date = None\n"," model = None\n"," data_path = 'combined_btc2_data.csv'\n"," reviews_path = 'trustpilot_coinbase_reviews-strip.csv'\n"," user_input = {}\n","\n"," print(\"Norėdami įšeiti įveskite 'q'\")\n","\n"," use_api = input(\"Ar norite naudoti API? (y/n)\").strip().lower()\n"," if use_api == 'q':\n"," return\n","\n"," if use_api == 'y':\n"," print(\"Parsisiunčiami duomenys...\")\n"," model = BTCModel(data_path, reviews_path, random_forest=False, use_extended_features=True)\n"," #user_input = model._get_lag_data_from_api()\n"," else:\n"," extended_features = input(\"Ar norite naudoti visus įvesties duomenis? (y/n)\\nNenaudojant visos įvesties spėjimams bus naudojama tik data.\").strip().lower()\n"," if extended_features == 'q':\n"," return\n"," if extended_features == 'y':\n"," print(\"Įveskite paskutinių 2 dienų duomenis:\")\n"," user_input['Lag_Close_1'] = get_float_input(\"Lag_Close_1: \")\n"," user_input['Lag_Close_2'] = get_float_input(\"Lag_Close_2: \")\n"," user_input['Lag_Volume_1'] = get_float_input(\"Lag_Volume_1: \")\n"," user_input['Lag_Volume_2'] = get_float_input(\"Lag_Volume_2: \")\n"," user_input['Lag_Open_1'] = get_float_input(\"Lag_Open_1: \")\n"," user_input['Lag_Open_2'] = get_float_input(\"Lag_Open_2: \")\n"," user_input['Lag_High_1'] = get_float_input(\"Lag_High_1: \")\n"," user_input['Lag_High_2'] = get_float_input(\"Lag_High_2: \")\n"," user_input['Lag_Low_1'] = get_float_input(\"Lag_Low_1: \")\n"," user_input['Lag_Low_2'] = get_float_input(\"Lag_Low_2: \")\n"," user_input['Day'] = get_int_input(\"Nuspėjama diena: \")\n"," user_input['Month'] = get_int_input(\"Mėnuo: \")\n"," user_input['Year'] = get_int_input(\"Metai: \")\n"," user_input['Rating'] = get_float_input(\"Vidutinis einamojo mėn. Coinbase reitingas: \")\n"," else:\n"," date = get_date_input(\"Įveskite datą BTC kainos nuspėjimui (YYYY-MM-DD): \")\n"," if date == 'q':\n"," return\n"," user_input['Day'] = date.day\n"," user_input['Month'] = date.month\n"," user_input['Year'] = date.year\n","\n"," if 'Rating' not in user_input or user_input['Rating'] is None:\n"," user_input['Rating'] = 1.4\n","\n"," default_keys = ['Lag_Close_1', 'Lag_Close_2', 'Lag_Volume_1', 'Lag_Volume_2',\n"," 'Lag_Open_1', 'Lag_Open_2', 'Lag_High_1', 'Lag_High_2',\n"," 'Lag_Low_1', 'Lag_Low_2', 'Day', 'Month', 'Year', 'Rating']\n","\n"," for key in default_keys:\n"," user_input.setdefault(key, 0.0 if 'L' in key else 0)\n","\n"," if not model:\n"," model = BTCModel(data_path, reviews_path, random_forest=False, use_extended_features=extended_features)\n","\n"," if date:\n"," prediction = model.predict(date=date, use_api=use_api == 'y')\n"," else:\n"," prediction = model.predict(user_input=user_input, use_api=use_api == 'y')\n","\n"," if use_api == 'y':\n"," print(f\"Nuspėjama modelio su API BTC kaina rytdienai --> {prediction:,.2f} USD <--\")\n"," else:\n"," print(f\"Nuspėjama modelio BTC kaina šiam laikotarpiui ({user_input['Year']}-{user_input['Month']}-{user_input['Day']}) --> {prediction:,.2f} USD <--\")\n","\n"," user_db.save_user_input(user_input)\n","\n","if __name__ == \"__main__\":\n"," main()\n"]}],"metadata":{"kernelspec":{"display_name":"mokymai","language":"python","name":"python3"},"language_info":{"codemirror_mode":{"name":"ipython","version":3},"file_extension":".py","mimetype":"text/x-python","name":"python","nbconvert_exporter":"python","pygments_lexer":"ipython3","version":"3.8.10"},"colab":{"provenance":[]}},"nbformat":4,"nbformat_minor":0}