larry1chan@qq.com 10 ماه پیش
کامیت
27559f703e
9فایلهای تغییر یافته به همراه538 افزوده شده و 0 حذف شده
  1. 0 0
      README.md
  2. 8 0
      apitest/apitest.code-workspace
  3. 21 0
      apitest/crypto_prices.csv
  4. 54 0
      apitest/disparity.py
  5. 79 0
      apitest/disparity_talk.py
  6. 54 0
      apitest/histpx_top20.py
  7. 36 0
      apitest/top5.py
  8. 125 0
      apitest/trend_detect.md
  9. 161 0
      apitest/trend_detect.py

+ 0 - 0
README.md


+ 8 - 0
apitest/apitest.code-workspace

@@ -0,0 +1,8 @@
+{
+	"folders": [
+		{
+			"path": "."
+		}
+	],
+	"settings": {}
+}

+ 21 - 0
apitest/crypto_prices.csv

@@ -0,0 +1,21 @@
+Symbol,Day 1,Day 2,Day 3,Day 4,Day 5,Day 6,Day 7,Day 8,Day 9,Day 10,Day 11,Day 12,Day 13,Day 14,Day 15,Day 16,Day 17,Day 18,Day 19,Day 20,Day 21,Day 22,Day 23,Day 24,Day 25,Day 26,Day 27,Day 28,Day 29,Day 30,Day 31,Day 32,Day 33,Day 34,Day 35,Day 36,Day 37,Day 38,Day 39,Day 40,Day 41,Day 42,Day 43,Day 44,Day 45,Day 46,Day 47,Day 48,Day 49,Day 50,Day 51,Day 52,Day 53,Day 54,Day 55,Day 56,Day 57,Day 58,Day 59,Day 60
+BTCUSDT,94599.99,94545.06,94536.1,96560.86,100497.35,99987.3,104077.48,104556.23,101331.57,102260.01,106143.82,103706.66,103910.34,104870.5,104746.85,102620.0,102082.83,101335.52,103733.24,104722.94,102429.56,100635.65,97700.59,101328.52,97763.13,96612.43,96554.35,96506.8,96444.74,96462.75,97430.82,95778.2,97869.99,96608.14,97500.48,97569.66,96118.12,95780.0,95671.74,96644.37,98305.0,96181.98,96551.01,96258.0,91552.88,88680.4,84250.09,84708.58,84349.94,86064.53,94270.0,86220.61,87281.98,90606.01,89931.89,86801.75,86222.45,80734.37,78595.86,82932.99,82700.0
+BTCFDUSD,94655.99,94586.08,94544.44,96553.5,100483.93,100014.67,104156.07,104597.64,101482.56,102363.22,106133.79,103762.79,103962.35,104912.09,104780.91,102609.14,102068.0,101376.0,103805.81,104782.07,102482.34,100709.01,97804.91,101427.56,97852.13,96700.06,96635.33,96617.98,96545.84,96562.91,97523.68,95888.36,97920.0,96710.87,97583.53,97666.88,96237.79,95921.24,95764.18,96756.49,98427.96,96384.34,96677.11,96406.74,91682.89,88693.52,84247.89,84897.09,84468.25,86169.82,94338.75,86372.88,87381.63,90745.41,90047.78,86896.6,86333.02,80879.74,78755.69,83086.16,82841.66
+USDTTRY,35.48,35.47,35.52,35.49,35.37,35.45,35.46,35.64,35.83,35.74,35.62,35.69,35.68,35.78,35.78,35.74,35.74,35.8,35.82,35.78,35.88,35.99,36.36,36.11,36.02,36.01,35.97,36.17,36.19,36.14,36.04,36.13,36.07,36.14,36.28,36.38,36.42,36.34,36.33,36.34,36.3,36.57,36.49,36.49,36.5,36.5,36.46,36.46,36.45,36.55,36.23,36.51,36.49,36.46,36.46,36.55,36.57,36.7,36.64,36.64,36.63
+ETHFDUSD,3285.29,3269.0,3137.93,3225.2,3450.4,3309.04,3476.75,3309.78,3219.59,3287.47,3326.76,3244.46,3340.08,3312.14,3319.62,3232.66,3182.44,3078.97,3115.82,3248.88,3302.07,3119.67,2873.41,2882.44,2733.75,2790.63,2689.07,2625.27,2635.12,2630.29,2663.9,2604.93,2740.06,2678.87,2728.5,2695.64,2665.05,2748.09,2674.62,2718.81,2741.19,2668.25,2766.79,2823.85,2516.84,2495.6,2336.57,2312.56,2240.8,2220.32,2520.21,2152.73,2174.22,2244.78,2205.09,2144.0,2206.47,2024.05,1869.14,1926.91,1913.52
+ETHUSDC,3281.93,3265.4,3136.79,3224.2,3451.8,3308.08,3474.97,3304.17,3209.99,3280.01,3327.8,3241.41,3338.4,3309.91,3318.79,3231.68,3181.91,3076.03,3114.0,3247.62,3300.04,3116.56,2869.29,2883.19,2731.99,2788.39,2686.78,2622.87,2633.01,2627.81,2661.91,2602.58,2738.05,2676.08,2726.18,2693.74,2661.8,2743.71,2670.11,2715.9,2739.04,2661.69,2763.8,2820.09,2513.09,2492.04,2332.41,2305.61,2236.79,2216.8,2518.74,2147.78,2171.12,2241.48,2202.36,2141.07,2203.2,2020.12,1864.62,1922.99,1909.53
+USDTARS,1219.9,1218.9,1222.4,1219.2,1214.3,1218.7,1218.6,1216.5,1234.9,1223.0,1220.5,1217.7,1215.3,1202.6,1202.3,1205.0,1208.7,1204.4,1200.9,1192.8,1214.1,1212.2,1216.7,1220.3,1222.7,1217.8,1216.0,1218.6,1215.0,1214.4,1208.0,1211.0,1209.7,1212.4,1213.8,1221.7,1225.0,1238.4,1233.8,1229.1,1228.7,1233.9,1230.2,1229.4,1229.0,1230.9,1231.2,1231.6,1235.8,1237.8,1241.5,1238.1,1232.3,1239.6,1241.3,1237.0,1236.9,1239.0,1239.2,1239.1,1237.4
+ETHUSDT,3282.83,3267.3,3137.51,3225.63,3451.52,3308.05,3473.63,3307.71,3215.12,3284.0,3327.54,3242.6,3338.21,3310.09,3318.77,3232.61,3182.44,3077.72,3113.9,3247.39,3300.99,3117.54,2869.68,2879.9,2731.19,2788.25,2686.64,2622.1,2632.46,2627.18,2661.19,2602.59,2738.27,2675.87,2725.95,2693.04,2661.41,2744.05,2671.99,2715.5,2738.04,2663.0,2763.22,2819.69,2513.52,2495.7,2336.37,2307.72,2237.59,2217.39,2518.11,2149.01,2171.51,2241.59,2202.2,2141.6,2203.58,2020.41,1865.1,1923.43,1909.93
+USDTCOP,4264.0,4256.0,4271.0,4234.0,4233.0,4272.0,4280.0,4286.0,4323.0,4254.0,4250.0,4181.0,4168.0,4131.0,4094.0,4273.0,4200.0,4159.0,4105.0,4082.0,4145.0,4156.0,4201.0,4155.0,4116.0,4145.0,4131.0,4105.0,4060.0,4115.0,4084.0,4083.0,4099.0,4093.0,4077.0,4067.0,4087.0,4070.0,4072.0,4051.0,4023.0,4036.0,4042.0,4036.0,4080.0,4117.0,4070.0,4086.0,4114.0,4124.0,4122.0,4117.0,4129.0,4072.0,4056.0,4097.0,4083.0,4121.0,4154.0,4117.0,4101.0
+RARETRY,3.75,3.675,3.577,3.706,3.862,3.775,3.996,3.743,3.418,3.393,3.497,3.442,3.386,3.288,3.315,3.256,3.259,3.151,3.089,3.109,3.151,2.919,2.603,2.644,2.482,2.43,2.339,2.373,2.514,2.47,2.515,2.534,2.717,2.634,2.704,2.636,2.652,2.572,2.46,2.479,2.575,2.447,2.726,2.572,2.2,2.238,2.234,2.264,2.187,2.115,2.254,1.909,1.82,1.85,1.797,1.79,1.732,2.567,3.585,3.764,3.431
+BTCJPY,14946896.0,14940272.0,14897765.0,15283861.0,15706017.0,15553103.0,16270924.0,16347341.0,15903260.0,15903000.0,16550205.0,16256926.0,16258303.0,16378654.0,16365900.0,16049999.0,15853892.0,15811561.0,16143771.0,16165190.0,15935428.0,15647275.0,15156896.0,15800204.0,15130012.0,14777645.0,14650981.0,14670484.0,14643114.0,14684047.0,14827058.0,14665710.0,15101258.0,14820000.0,14879113.0,14904483.0,14665740.0,14543596.0,14550332.0,14637537.0,14700727.0,14418365.0,14446655.0,14394147.0,13734748.0,13231607.0,12519533.0,12722554.0,12710795.0,12978689.0,14230693.0,12912843.0,13096131.0,13532849.0,13359173.0,12858277.0,12780960.0,11948953.0,11579951.0,12312993.0,12333022.0
+USDCUSDT,1.0004,1.0004,1.0003,1.0003,0.9998,1.0001,0.9996,1.0011,1.0014,1.0012,0.9999,1.0005,0.9998,1.0,1.0002,1.0004,1.0001,1.0006,1.0,1.0,1.0003,1.0002,1.0002,0.999,0.9997,1.0,1.0,0.9998,0.9999,0.9999,0.9999,1.0001,0.9998,0.9999,0.9999,0.9998,0.9999,0.9999,1.0004,1.0,0.9997,1.0004,0.9999,1.0,1.0001,1.0013,1.0014,1.0007,1.0003,1.0004,0.9999,1.0006,1.0002,1.0001,0.9999,1.0002,1.0001,1.0002,1.0004,1.0002,1.0001
+BANANATRY,1405.0,1365.0,1348.0,1336.0,1407.0,1355.0,1454.0,1383.0,1232.0,1293.0,1422.0,1477.0,1488.0,1485.0,1483.0,1413.0,1346.0,1267.0,1329.0,1358.0,1386.0,1262.0,1076.0,1024.0,886.0,833.0,777.0,733.0,766.0,737.0,844.0,894.0,992.0,948.0,960.0,971.0,939.0,911.0,865.0,874.0,863.0,821.0,873.0,854.0,699.0,707.0,659.0,659.0,649.0,648.0,687.0,575.0,521.0,531.0,517.0,504.0,492.0,438.0,411.0,599.0,599.0
+PEPETRY,0.0006389,0.00062973,0.000599,0.00062006,0.00067443,0.00064289,0.00071937,0.00065755,0.00057536,0.00056438,0.00056633,0.00054012,0.00054666,0.0005348,0.00053836,0.00050102,0.00046877,0.00041,0.00044394,0.00046318,0.00049762,0.00044077,0.00039153,0.00039754,0.00036567,0.00036036,0.00033163,0.0003231,0.00034619,0.00034471,0.0003457,0.00034662,0.00036374,0.00035011,0.00037358,0.00036152,0.00035343,0.00036744,0.00033639,0.00033993,0.00034943,0.00033376,0.00035116,0.00034091,0.00028815,0.00030098,0.00030333,0.00029945,0.00028882,0.00027718,0.00032005,0.0002639,0.0002549,0.00025803,0.00024921,0.00025548,0.00024399,0.00021534,0.00020887,0.00023155,0.00023533
+ETHJPY,518526.0,516200.0,494424.0,510351.0,539189.0,514197.0,543569.0,517391.0,504357.0,511005.0,518905.0,507951.0,522407.0,517092.0,518086.0,504901.0,493657.0,480626.0,484475.0,501193.0,513574.0,484594.0,444846.0,449150.0,422730.0,426978.0,407861.0,398506.0,399323.0,400052.0,404914.0,398745.0,422322.0,410419.0,415800.0,410997.0,406200.0,416380.0,406160.0,411240.0,409626.0,398993.0,413462.0,421675.0,377268.0,372356.0,347227.0,346495.0,337008.0,334400.0,380228.0,321532.0,325936.0,334752.0,327014.0,317381.0,326711.0,298496.0,274653.0,285028.0,284927.0
+BTCUSDC,94576.14,94503.99,94498.0,96531.99,100515.6,99984.0,104117.41,104441.4,101189.9,102148.0,106159.15,103656.01,103935.58,104848.01,104731.56,102573.26,102064.94,101273.89,103739.99,104735.0,102409.98,100624.49,97664.01,101448.63,97793.98,96626.35,96561.45,96533.13,96464.49,96479.5,97450.22,95776.24,97878.01,96626.02,97520.0,97603.98,96122.02,95778.02,95612.01,96640.01,98347.98,96137.95,96569.68,96267.63,91541.03,88578.02,84124.92,84647.87,84321.98,86029.83,94275.9,86158.8,87262.0,90607.24,89932.0,86774.01,86209.99,80716.74,78561.69,82924.7,82675.98
+XRPTRY,91.42,88.82,89.61,94.69,111.19,114.95,116.69,116.55,106.0,111.03,113.03,113.42,111.27,110.98,111.19,108.06,109.21,109.44,109.89,111.96,108.88,103.59,93.7,97.49,91.08,85.74,83.69,86.65,87.53,86.47,87.32,87.18,89.2,92.48,99.35,100.5,99.41,96.65,93.11,99.44,97.57,94.03,93.91,93.95,83.14,84.78,80.17,80.16,78.19,80.05,106.54,87.2,89.54,91.18,94.81,87.2,85.0,78.43,74.01,79.51,80.35
+BTCTRY,3356550.0,3353252.0,3357163.0,3426781.0,3554511.0,3545559.0,3690281.0,3727027.0,3632064.0,3656333.0,3780250.0,3701830.0,3706268.0,3752256.0,3748400.0,3668444.0,3648945.0,3628340.0,3714854.0,3747462.0,3675489.0,3623078.0,3552001.0,3660046.0,3522094.0,3478510.0,3474569.0,3490649.0,3489807.0,3485589.0,3511008.0,3461159.0,3529070.0,3491457.0,3538115.0,3550646.0,3502078.0,3479677.0,3476405.0,3511563.0,3568274.0,3517350.0,3522683.0,3511878.0,3342165.0,3236618.0,3071804.0,3088148.0,3074770.0,3146024.0,3415863.0,3149658.0,3184922.0,3303228.0,3278881.0,3173356.0,3152752.0,2961007.0,2881776.0,3037602.0,3029514.0
+XRPUSDT,2.5764,2.5046,2.5232,2.6673,3.1429,3.2451,3.2922,3.2697,2.9587,3.1053,3.1738,3.1803,3.1194,3.1009,3.108,3.0223,3.0552,3.0572,3.0683,3.1276,3.0361,2.8778,2.58,2.7001,2.5274,2.381,2.325,2.3968,2.419,2.3928,2.4237,2.4131,2.4734,2.5599,2.7384,2.7619,2.7283,2.6599,2.5628,2.7378,2.6877,2.5721,2.574,2.5763,2.2783,2.3222,2.1982,2.1985,2.1453,2.1916,2.9396,2.3873,2.4543,2.4998,2.6001,2.3855,2.3261,2.1387,2.0216,2.1711,2.1926
+BNXTRY,13.18,12.91,12.17,12.76,13.31,13.48,13.75,12.13,11.07,10.06,10.31,9.95,10.1,9.65,9.82,9.68,9.41,8.43,8.87,9.24,9.25,8.33,6.6,6.85,6.48,6.35,5.88,6.07,13.73,19.77,24.62,26.54,36.54,32.27,37.2,36.31,34.2,31.87,33.92,31.82,41.84,45.28,42.36,39.84,35.14,40.19,45.58,42.33,43.89,40.43,34.73,30.39,31.97,29.83,26.53,35.21,35.28,37.16,35.78,45.07,40.65
+XRPJPY,406.77,396.24,397.95,422.54,490.02,503.74,514.43,510.73,465.17,482.35,493.91,498.27,488.09,484.96,486.1,473.55,474.29,477.5,477.64,483.45,472.21,447.36,400.56,420.36,391.19,364.77,351.7,364.12,367.99,364.65,368.85,369.35,381.29,392.6,417.57,422.11,415.43,403.79,389.85,415.81,402.25,385.77,385.19,385.17,341.57,346.49,326.55,330.09,323.37,330.39,443.76,357.31,368.41,373.54,386.12,353.51,344.61,315.68,297.0,321.96,326.99

+ 54 - 0
apitest/disparity.py

@@ -0,0 +1,54 @@
+import time
+import requests
+from binance.client import Client
+
+# Binance API credentials
+api_key = 'YOUR_BINANCE_API_KEY'
+api_secret = 'YOUR_BINANCE_API_SECRET'
+
+# Initialize Binance client
+client = Client(api_key, api_secret)
+
+# Define the threshold for disparity (e.g., 0.05 for 5%)
+DISPARITY_THRESHOLD = 0.05
+
+# Function to fetch current prices of BTC and ETH
+def get_prices():
+    btc_price = float(client.get_symbol_ticker(symbol='BTCUSDT')['price'])
+    eth_price = float(client.get_symbol_ticker(symbol='ETHUSDT')['price'])
+    return btc_price, eth_price
+
+# Function to calculate disparity
+def calculate_disparity(btc_price, eth_price):
+    parity = eth_price / btc_price
+    return parity
+
+# Function to send alert (e.g., via webhook, email, etc.)
+def send_alert(message):
+    webhook_url = 'YOUR_WEBHOOK_URL'  # Replace with your webhook URL
+    payload = {'text': message}
+    requests.post(webhook_url, json=payload)
+    print(f"Alert sent: {message}")
+
+# Main monitoring loop
+def monitor_disparity():
+    while True:
+        try:
+            btc_price, eth_price = get_prices()
+            parity = calculate_disparity(btc_price, eth_price)
+            
+            print(f"BTC Price: {btc_price}, ETH Price: {eth_price}, Parity: {parity}")
+            
+            if parity > (1 + DISPARITY_THRESHOLD):
+                send_alert(f"ETH is overvalued compared to BTC! Parity: {parity}")
+            elif parity < (1 - DISPARITY_THRESHOLD):
+                send_alert(f"ETH is undervalued compared to BTC! Parity: {parity}")
+            
+            time.sleep(60)  # Check every 60 seconds
+        
+        except Exception as e:
+            print(f"Error: {e}")
+            time.sleep(60)
+
+if __name__ == "__main__":
+    monitor_disparity()

+ 79 - 0
apitest/disparity_talk.py

@@ -0,0 +1,79 @@
+import time
+import requests
+from binance.client import Client
+
+# Binance API credentials
+api_key = 'WFIEaBuUafZ9ldAiMHLZ4Z1qHdVnpoDUVZM8MughMf6zmbSqGx5pEmQFBJysjwFp'  # Optional for public data
+api_secret = 'C9HtmLk7fBCidyJI2lPtUbYhj4T0FdmJ0NE0LLipFiwUSR7euf1TEzJblEx1O6oA'  # Optional for public data
+
+# Initialize Binance client
+client = Client(api_key, api_secret)
+
+# Define the threshold for disparity (e.g., 0.05 for 5%)
+DISPARITY_THRESHOLD = 0.05
+
+# Nextcloud Talk configuration
+NEXTCLOUD_URL = 'https://1984.algometic.com'  # Replace with your Nextcloud URL
+NEXTCLOUD_USERNAME = 'larry'  # Replace with your Nextcloud username
+NEXTCLOUD_PASSWORD = 'jEr6f-8Q5y5-nsSdA-koWsk-58jRT'  # Replace with your app password
+TALK_CONVERSATION_TOKEN = 'jg65znzn'  # Replace with your Talk conversation token
+
+# Function to fetch current prices of BTC and ETH
+def get_prices():
+    btc_price = float(client.get_symbol_ticker(symbol='BTCUSDT')['price'])
+    eth_price = float(client.get_symbol_ticker(symbol='ETHUSDT')['price'])
+    return btc_price, eth_price
+
+# Function to calculate disparity
+def calculate_disparity(btc_price, eth_price):
+    parity = eth_price / btc_price
+    return parity
+
+# Function to send alert to Nextcloud Talk
+def send_alert_to_talk(message):
+    talk_api_url = f"{NEXTCLOUD_URL}/ocs/v2.php/apps/spreed/api/v1/chat/{TALK_CONVERSATION_TOKEN}"
+    
+    headers = {
+        'OCS-APIRequest': 'true',
+        'Content-Type': 'application/json',
+        'Accept': 'application/json',
+    }
+    
+    payload = {
+        'message': message,
+    }
+    
+    try:
+        response = requests.post(
+            talk_api_url,
+            headers=headers,
+            json=payload,
+            auth=(NEXTCLOUD_USERNAME, NEXTCLOUD_PASSWORD)
+        )
+        response.raise_for_status()  # Raise an error for bad responses
+        print(f"Alert sent to Nextcloud Talk: {message}")
+    except requests.exceptions.RequestException as e:
+        print(f"Failed to send alert to Nextcloud Talk: {e}")
+
+# Main monitoring loop
+def monitor_disparity():
+    while True:
+        try:
+            btc_price, eth_price = get_prices()
+            parity = calculate_disparity(btc_price, eth_price)
+            
+            print(f"BTC Price: {btc_price}, ETH Price: {eth_price}, Parity: {parity}")
+            
+            if parity > (1 + DISPARITY_THRESHOLD):
+                send_alert_to_talk(f"ETH is overvalued compared to BTC! Parity: {parity}")
+            elif parity < (1 - DISPARITY_THRESHOLD):
+                send_alert_to_talk(f"ETH is undervalued compared to BTC! Parity: {parity}")
+            
+            time.sleep(60)  # Check every 60 seconds
+        
+        except Exception as e:
+            print(f"Error: {e}")
+            time.sleep(60)
+
+if __name__ == "__main__":
+    monitor_disparity()

+ 54 - 0
apitest/histpx_top20.py

@@ -0,0 +1,54 @@
+import csv
+from binance.client import Client
+from datetime import datetime, timedelta
+
+# Replace with your Binance API key and secret
+api_key = 'WFIEaBuUafZ9ldAiMHLZ4Z1qHdVnpoDUVZM8MughMf6zmbSqGx5pEmQFBJysjwFp'  # Optional for public data
+api_secret = 'C9HtmLk7fBCidyJI2lPtUbYhj4T0FdmJ0NE0LLipFiwUSR7euf1TEzJblEx1O6oA'  # Optional for public data
+
+# Initialize the Binance client
+client = Client(api_key, api_secret)
+
+def get_top_traded_coins(limit=20):
+    """Get the top traded coins by volume."""
+    tickers = client.get_ticker()
+    # Sort by quote volume (most traded)
+    sorted_tickers = sorted(tickers, key=lambda x: float(x['quoteVolume']), reverse=True)
+    # Extract the top 'limit' coins
+    top_coins = [ticker['symbol'] for ticker in sorted_tickers[:limit]]
+    return top_coins
+
+def get_historical_prices(symbol, days=30):
+    """Get historical prices for a symbol over the last 'days' days."""
+    end_time = datetime.now()
+    start_time = end_time - timedelta(days=days)
+    klines = client.get_historical_klines(symbol, Client.KLINE_INTERVAL_1DAY, start_time.strftime("%d %b, %Y"), end_time.strftime("%d %b, %Y"))
+    # Extract closing prices
+    prices = [float(kline[4]) for kline in klines]
+    return prices
+
+def save_to_csv(data, days, filename='crypto_prices.csv'):
+    """Save the data to a CSV file."""
+    with open(filename, mode='w', newline='') as file:
+        writer = csv.writer(file)
+        writer.writerow(['Symbol'] + [f'Day {i+1}' for i in range(days)])
+        for symbol, prices in data.items():
+            writer.writerow([symbol] + prices)
+
+def main():
+    # Get the top 20 traded coins
+    top_coins = get_top_traded_coins(20)
+    
+    # Fetch historical prices for each coin
+    crypto_prices = {}
+    for coin in top_coins:
+        print(f"Fetching prices for {coin}...")
+        prices = get_historical_prices(coin, 60)
+        crypto_prices[coin] = prices
+    
+    # Save the data to a CSV file
+    save_to_csv(crypto_prices, 60)
+    print("Data saved to crypto_prices.csv")
+
+if __name__ == "__main__":
+    main()

+ 36 - 0
apitest/top5.py

@@ -0,0 +1,36 @@
+from binance.client import Client
+
+# Binance API credentials (public data does not require authentication)
+api_key = 'WFIEaBuUafZ9ldAiMHLZ4Z1qHdVnpoDUVZM8MughMf6zmbSqGx5pEmQFBJysjwFp'  # Optional for public data
+api_secret = 'C9HtmLk7fBCidyJI2lPtUbYhj4T0FdmJ0NE0LLipFiwUSR7euf1TEzJblEx1O6oA'  # Optional for public data
+
+# Initialize Binance client
+client = Client(api_key, api_secret)
+
+# List of top 5 popular cryptocurrencies (symbols)
+top_cryptos = ['BTCUSDT', 'ETHUSDT', 'BNBUSDT', 'SOLUSDT', 'XRPUSDT']
+
+# Function to fetch and display crypto info
+def get_crypto_info(symbol):
+    try:
+        ticker = client.get_symbol_ticker(symbol=symbol)
+        stats = client.get_ticker(symbol=symbol)
+        
+        price = ticker['price']
+        price_change_percent = stats['priceChangePercent']
+        
+        print(f"Symbol: {symbol}")
+        print(f"Price: {price} USDT")
+        print(f"24h Change: {price_change_percent}%")
+        print("-" * 30)
+    
+    except Exception as e:
+        print(f"Error fetching data for {symbol}: {e}")
+
+# Main function to fetch info for top 5 cryptos
+def fetch_top_crypto_prices():
+    for crypto in top_cryptos:
+        get_crypto_info(crypto)
+
+if __name__ == "__main__":
+    fetch_top_crypto_prices()

+ 125 - 0
apitest/trend_detect.md

@@ -0,0 +1,125 @@
+A simple and effective trend detection algorithm can be designed using **moving averages** and **slope analysis**. This approach is widely used in financial analysis and is easy to implement. Below is a discussion of the algorithm and its key components:
+
+---
+
+### **Algorithm Overview**
+The algorithm detects trends by analyzing the slope of a moving average of historical prices. It works as follows:
+
+1. **Calculate Moving Average (MA)**:
+   - Compute the moving average of prices over a specified window size (e.g., 10 days).
+   - The moving average smooths out short-term fluctuations, making it easier to identify trends.
+
+2. **Calculate Slope**:
+   - Compute the slope of the moving average over the same window.
+   - The slope indicates the direction and strength of the trend:
+     - **Positive slope**: Upward trend.
+     - **Negative slope**: Downward trend.
+     - **Zero slope**: Flat or no trend.
+
+3. **Trend Classification**:
+   - Classify the trend based on the slope:
+     - If the slope is above a threshold (e.g., 0.1), it's an **upward trend**.
+     - If the slope is below a threshold (e.g., -0.1), it's a **downward trend**.
+     - Otherwise, it's a **flat trend**.
+
+4. **Validation**:
+   - Validate the trend by checking if it persists in the subsequent days.
+
+---
+
+### **Advantages of the Algorithm**
+1. **Simplicity**:
+   - The algorithm is easy to implement and understand.
+   - It uses basic mathematical operations (averages and slopes).
+
+2. **Effectiveness**:
+   - Moving averages smooth out noise, making trends easier to detect.
+   - The slope provides a quantitative measure of the trend's strength.
+
+3. **Customizability**:
+   - The window size and slope thresholds can be adjusted based on the dataset and desired sensitivity.
+
+4. **Interpretability**:
+   - The results are easy to interpret (upward, downward, or flat trends).
+
+---
+
+### **Algorithm Steps in Detail**
+
+#### 1. **Calculate Moving Average**
+For a window size \( W \), the moving average at day \( t \) is:
+\[
+MA_t = \frac{1}{W} \sum_{i=t-W+1}^{t} P_i
+\]
+where \( P_i \) is the price at day \( i \).
+
+#### 2. **Calculate Slope**
+The slope of the moving average over the window is calculated using linear regression:
+\[
+\text{Slope} = \frac{W \sum_{i=1}^{W} (i \cdot MA_i) - \sum_{i=1}^{W} i \cdot \sum_{i=1}^{W} MA_i}{W \sum_{i=1}^{W} i^2 - (\sum_{i=1}^{W} i)^2}
+\]
+
+#### 3. **Trend Classification**
+- If \( \text{Slope} > \text{Threshold} \): **Upward trend**.
+- If \( \text{Slope} < -\text{Threshold} \): **Downward trend**.
+- Otherwise: **Flat trend**.
+
+#### 4. **Validation**
+- After detecting a trend, validate it by checking if the trend continues in the next \( N \) days.
+
+---
+
+### **Example Implementation**
+
+```python
+import numpy as np
+
+def moving_average(prices, window):
+    return np.convolve(prices, np.ones(window), 'valid') / window
+
+def calculate_slope(moving_avg):
+    x = np.arange(len(moving_avg))
+    y = np.array(moving_avg)
+    slope = (len(x) * np.sum(x * y) - np.sum(x) * np.sum(y)) / (len(x) * np.sum(x**2) - np.sum(x)**2)
+    return slope
+
+def detect_trend(prices, window=10, slope_threshold=0.1):
+    ma = moving_average(prices, window)
+    slope = calculate_slope(ma)
+    
+    if slope > slope_threshold:
+        return "Upward Trend"
+    elif slope < -slope_threshold:
+        return "Downward Trend"
+    else:
+        return "Flat Trend"
+```
+
+---
+
+### **Why This Algorithm Works**
+1. **Smoothing Effect**:
+   - Moving averages reduce noise, making it easier to identify long-term trends.
+
+2. **Quantitative Measure**:
+   - The slope provides a clear, numerical measure of the trend's direction and strength.
+
+3. **Flexibility**:
+   - The window size and slope threshold can be adjusted to suit different datasets and timeframes.
+
+---
+
+### **Limitations**
+1. **Lag**:
+   - Moving averages are lagging indicators, meaning they react slowly to sudden price changes.
+
+2. **Parameter Sensitivity**:
+   - The results depend on the choice of window size and slope threshold.
+
+3. **False Signals**:
+   - In highly volatile markets, the algorithm may produce false trend signals.
+
+---
+
+### **Conclusion**
+This moving average-based trend detection algorithm is simple, effective, and widely applicable. It provides a clear and interpretable way to identify trends in time-series data, making it a valuable tool for financial analysis, including cryptocurrency price trends.

+ 161 - 0
apitest/trend_detect.py

@@ -0,0 +1,161 @@
+import numpy as np
+
+import csv
+
+def read_crypto_csv(filename):
+    """
+    Converts a CSV file of cryptocurrency prices into a dictionary format.
+    
+    Args:
+        filename (str): Path to the CSV file
+        
+    Returns:
+        dict: {coin_symbol: list_of_prices}
+    """
+    crypto_data = {}
+    
+    with open(filename, 'r') as f:
+        reader = csv.reader(f)
+        headers = next(reader)  # Read header row
+        
+        # Verify CSV format (first column should be 'Symbol')
+        if headers[0] != 'Symbol':
+            raise ValueError("CSV format incorrect. First column should be 'Symbol'")
+            
+        # Process each row
+        for row in reader:
+            symbol = row[0]
+            prices = [float(price) for price in row[1:]]  # Convert prices to floats
+            
+            crypto_data[symbol] = prices
+            
+    return crypto_data
+
+
+
+def detect_trend(data, window_size=10, slope_threshold=0.1):
+    """
+    Detects upward/downward trends for multiple coins using moving average slopes.
+    
+    Args:
+        data (dict): Dictionary of {coin: list_of_prices}
+        window_size (int): Days to analyze for initial trend
+        slope_threshold (float): Slope magnitude threshold for trend classification
+    
+    Returns:
+        dict: {coin: {'trend': 'upward'/'downward'/'flat', 'slope': float}}
+    """
+    results = {}
+    
+    for coin, prices in data.items():
+        if len(prices) < window_size:
+            raise ValueError(f"Not enough data for {coin}. Needs at least {window_size} days")
+            
+        # Calculate moving average
+        window_prices = prices[:window_size]
+        x = np.arange(window_size)
+        y = np.array(window_prices)
+        
+        # Calculate slope using linear regression
+        numerator = window_size * np.sum(x*y) - np.sum(x) * np.sum(y)
+        denominator = window_size * np.sum(x**2) - (np.sum(x))**2
+        slope = numerator / denominator if denominator != 0 else 0
+        
+        # Classify trend
+        if slope > slope_threshold:
+            trend = 'upward'
+        elif slope < -slope_threshold:
+            trend = 'downward'
+        else:
+            trend = 'flat'
+            
+        results[coin] = {'trend': trend, 'slope': slope}
+        
+    return results
+
+def validate_trend(data, initial_trends, window_size=10, validation_period=5, slope_threshold=0.1):
+    """
+    Validates trends by analyzing subsequent price movements.
+    
+    Args:
+        data (dict): Dictionary of {coin: list_of_prices}
+        initial_trends (dict): Results from detect_trend()
+        window_size (int): Initial detection window size
+        validation_period (int): Days after window_size to analyze
+        slope_threshold (float): Slope threshold for validation
+    
+    Returns:
+        dict: {coin: {'initial_trend': str, 'validation_trend': str, 'result': str}}
+    """
+    validation_results = {}
+    
+    for coin, prices in data.items():
+        if len(prices) < window_size + validation_period:
+            raise ValueError(f"Not enough data for validation for {coin}")
+            
+        # Get validation window prices (days 11-16 for window_size=10, validation_period=5)
+        validation_prices = prices[window_size:window_size+validation_period]
+        
+        # Calculate validation trend
+        x_val = np.arange(validation_period)
+        y_val = np.array(validation_prices)
+        
+        numerator_val = validation_period * np.sum(x_val*y_val) - np.sum(x_val) * np.sum(y_val)
+        denominator_val = validation_period * np.sum(x_val**2) - (np.sum(x_val))**2
+        slope_val = numerator_val / denominator_val if denominator_val != 0 else 0
+        
+        # Classify validation trend
+        if slope_val > slope_threshold:
+            val_trend = 'upward'
+        elif slope_val < -slope_threshold:
+            val_trend = 'downward'
+        else:
+            val_trend = 'flat'
+            
+        # Determine validation result
+        initial = initial_trends[coin]['trend']
+        
+        if initial == 'flat':
+            if val_trend != 'flat':
+                result = f'New {val_trend} trend emerged'
+            else:
+                result = 'Continued flat'
+        else:
+            if val_trend == initial:
+                result = 'Trend continued'
+            elif val_trend == 'flat':
+                result = 'Trend weakened to flat'
+            else:
+                result = 'Trend reversed'
+                
+        validation_results[coin] = {
+            'initial_trend': initial,
+            'validation_trend': val_trend,
+            'result': result,
+            'validation_slope': slope_val
+        }
+        
+    return validation_results
+
+# Usage example
+if __name__ == '__main__':
+    # Convert CSV to crypto_data structure
+    crypto_data = read_crypto_csv('crypto_prices.csv')
+
+    # Detect initial trends
+    initial_results = detect_trend(crypto_data, window_size=10)
+
+    # Validate trends using next 5 days
+    validation_results = validate_trend(crypto_data, initial_results, window_size=10, validation_period=5)
+
+    # Print formatted results
+    print("Coin\t\tInitial\t\tValidation\tResult")
+    print("-----------------------------------------------------------")
+    for coin, result in validation_results.items():
+        print(f"{coin}\t{result['initial_trend']:8}\t{result['validation_trend']:8}\t{result['result']}")
+
+    # # Example: Print first 3 coins and their first 5 prices
+    # for i, (coin, prices) in enumerate(crypto_data.items()):
+    #     if i >= 3:
+    #         break
+    #     print(f"{coin}: {prices[:5]}...")