├── .gitignore ├── price_alert.sln └── price_alert_v2 ├── .gitignore ├── Functions ├── receive_command.cs └── watcher.cs ├── Models ├── Message.cs └── WatcherRequest.cs ├── Tools ├── Bittrex.cs ├── Constants.cs └── TwilioSender.cs ├── host.json └── price_alert_v2.csproj /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.suo 8 | *.user 9 | *.userosscache 10 | *.sln.docstates 11 | 12 | # User-specific files (MonoDevelop/Xamarin Studio) 13 | *.userprefs 14 | 15 | # Build results 16 | [Dd]ebug/ 17 | [Dd]ebugPublic/ 18 | [Rr]elease/ 19 | [Rr]eleases/ 20 | x64/ 21 | x86/ 22 | bld/ 23 | [Bb]in/ 24 | [Oo]bj/ 25 | [Ll]og/ 26 | 27 | # Visual Studio 2015/2017 cache/options directory 28 | .vs/ 29 | # Uncomment if you have tasks that create the project's static files in wwwroot 30 | #wwwroot/ 31 | 32 | # Visual Studio 2017 auto generated files 33 | Generated\ Files/ 34 | 35 | # MSTest test Results 36 | [Tt]est[Rr]esult*/ 37 | [Bb]uild[Ll]og.* 38 | 39 | # NUNIT 40 | *.VisualState.xml 41 | TestResult.xml 42 | 43 | # Build Results of an ATL Project 44 | [Dd]ebugPS/ 45 | [Rr]eleasePS/ 46 | dlldata.c 47 | 48 | # Benchmark Results 49 | BenchmarkDotNet.Artifacts/ 50 | 51 | # .NET Core 52 | project.lock.json 53 | project.fragment.lock.json 54 | artifacts/ 55 | **/Properties/launchSettings.json 56 | 57 | # StyleCop 58 | StyleCopReport.xml 59 | 60 | # Files built by Visual Studio 61 | *_i.c 62 | *_p.c 63 | *_i.h 64 | *.ilk 65 | *.meta 66 | *.obj 67 | *.pch 68 | *.pdb 69 | *.pgc 70 | *.pgd 71 | *.rsp 72 | *.sbr 73 | *.tlb 74 | *.tli 75 | *.tlh 76 | *.tmp 77 | *.tmp_proj 78 | *.log 79 | *.vspscc 80 | *.vssscc 81 | .builds 82 | *.pidb 83 | *.svclog 84 | *.scc 85 | 86 | # Chutzpah Test files 87 | _Chutzpah* 88 | 89 | # Visual C++ cache files 90 | ipch/ 91 | *.aps 92 | *.ncb 93 | *.opendb 94 | *.opensdf 95 | *.sdf 96 | *.cachefile 97 | *.VC.db 98 | *.VC.VC.opendb 99 | 100 | # Visual Studio profiler 101 | *.psess 102 | *.vsp 103 | *.vspx 104 | *.sap 105 | 106 | # Visual Studio Trace Files 107 | *.e2e 108 | 109 | # TFS 2012 Local Workspace 110 | $tf/ 111 | 112 | # Guidance Automation Toolkit 113 | *.gpState 114 | 115 | # ReSharper is a .NET coding add-in 116 | _ReSharper*/ 117 | *.[Rr]e[Ss]harper 118 | *.DotSettings.user 119 | 120 | # JustCode is a .NET coding add-in 121 | .JustCode 122 | 123 | # TeamCity is a build add-in 124 | _TeamCity* 125 | 126 | # DotCover is a Code Coverage Tool 127 | *.dotCover 128 | 129 | # AxoCover is a Code Coverage Tool 130 | .axoCover/* 131 | !.axoCover/settings.json 132 | 133 | # Visual Studio code coverage results 134 | *.coverage 135 | *.coveragexml 136 | 137 | # NCrunch 138 | _NCrunch_* 139 | .*crunch*.local.xml 140 | nCrunchTemp_* 141 | 142 | # MightyMoose 143 | *.mm.* 144 | AutoTest.Net/ 145 | 146 | # Web workbench (sass) 147 | .sass-cache/ 148 | 149 | # Installshield output folder 150 | [Ee]xpress/ 151 | 152 | # DocProject is a documentation generator add-in 153 | DocProject/buildhelp/ 154 | DocProject/Help/*.HxT 155 | DocProject/Help/*.HxC 156 | DocProject/Help/*.hhc 157 | DocProject/Help/*.hhk 158 | DocProject/Help/*.hhp 159 | DocProject/Help/Html2 160 | DocProject/Help/html 161 | 162 | # Click-Once directory 163 | publish/ 164 | 165 | # Publish Web Output 166 | *.[Pp]ublish.xml 167 | *.azurePubxml 168 | # Note: Comment the next line if you want to checkin your web deploy settings, 169 | # but database connection strings (with potential passwords) will be unencrypted 170 | *.pubxml 171 | *.publishproj 172 | 173 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 174 | # checkin your Azure Web App publish settings, but sensitive information contained 175 | # in these scripts will be unencrypted 176 | PublishScripts/ 177 | 178 | # NuGet Packages 179 | *.nupkg 180 | # The packages folder can be ignored because of Package Restore 181 | **/[Pp]ackages/* 182 | # except build/, which is used as an MSBuild target. 183 | !**/[Pp]ackages/build/ 184 | # Uncomment if necessary however generally it will be regenerated when needed 185 | #!**/[Pp]ackages/repositories.config 186 | # NuGet v3's project.json files produces more ignorable files 187 | *.nuget.props 188 | *.nuget.targets 189 | 190 | # Microsoft Azure Build Output 191 | csx/ 192 | *.build.csdef 193 | 194 | # Microsoft Azure Emulator 195 | ecf/ 196 | rcf/ 197 | 198 | # Windows Store app package directories and files 199 | AppPackages/ 200 | BundleArtifacts/ 201 | Package.StoreAssociation.xml 202 | _pkginfo.txt 203 | *.appx 204 | 205 | # Visual Studio cache files 206 | # files ending in .cache can be ignored 207 | *.[Cc]ache 208 | # but keep track of directories ending in .cache 209 | !*.[Cc]ache/ 210 | 211 | # Others 212 | ClientBin/ 213 | ~$* 214 | *~ 215 | *.dbmdl 216 | *.dbproj.schemaview 217 | *.jfm 218 | *.pfx 219 | *.publishsettings 220 | orleans.codegen.cs 221 | 222 | # Since there are multiple workflows, uncomment next line to ignore bower_components 223 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 224 | #bower_components/ 225 | 226 | # RIA/Silverlight projects 227 | Generated_Code/ 228 | 229 | # Backup & report files from converting an old project file 230 | # to a newer Visual Studio version. Backup files are not needed, 231 | # because we have git ;-) 232 | _UpgradeReport_Files/ 233 | Backup*/ 234 | UpgradeLog*.XML 235 | UpgradeLog*.htm 236 | 237 | # SQL Server files 238 | *.mdf 239 | *.ldf 240 | *.ndf 241 | 242 | # Business Intelligence projects 243 | *.rdl.data 244 | *.bim.layout 245 | *.bim_*.settings 246 | 247 | # Microsoft Fakes 248 | FakesAssemblies/ 249 | 250 | # GhostDoc plugin setting file 251 | *.GhostDoc.xml 252 | 253 | # Node.js Tools for Visual Studio 254 | .ntvs_analysis.dat 255 | node_modules/ 256 | 257 | # TypeScript v1 declaration files 258 | typings/ 259 | 260 | # Visual Studio 6 build log 261 | *.plg 262 | 263 | # Visual Studio 6 workspace options file 264 | *.opt 265 | 266 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 267 | *.vbw 268 | 269 | # Visual Studio LightSwitch build output 270 | **/*.HTMLClient/GeneratedArtifacts 271 | **/*.DesktopClient/GeneratedArtifacts 272 | **/*.DesktopClient/ModelManifest.xml 273 | **/*.Server/GeneratedArtifacts 274 | **/*.Server/ModelManifest.xml 275 | _Pvt_Extensions 276 | 277 | # Paket dependency manager 278 | .paket/paket.exe 279 | paket-files/ 280 | 281 | # FAKE - F# Make 282 | .fake/ 283 | 284 | # JetBrains Rider 285 | .idea/ 286 | *.sln.iml 287 | 288 | # CodeRush 289 | .cr/ 290 | 291 | # Python Tools for Visual Studio (PTVS) 292 | __pycache__/ 293 | *.pyc 294 | 295 | # Cake - Uncomment if you are using it 296 | # tools/** 297 | # !tools/packages.config 298 | 299 | # Tabs Studio 300 | *.tss 301 | 302 | # Telerik's JustMock configuration file 303 | *.jmconfig 304 | 305 | # BizTalk build output 306 | *.btp.cs 307 | *.btm.cs 308 | *.odx.cs 309 | *.xsd.cs 310 | 311 | # OpenCover UI analysis results 312 | OpenCover/ 313 | 314 | # Azure Stream Analytics local run output 315 | ASALocalRun/ 316 | 317 | # MSBuild Binary and Structured Log 318 | *.binlog 319 | -------------------------------------------------------------------------------- /price_alert.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.27205.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "price_alert_v2", "price_alert_v2\price_alert_v2.csproj", "{F980FCAD-BD2F-451B-B31F-0398C5D4CFAE}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {F980FCAD-BD2F-451B-B31F-0398C5D4CFAE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {F980FCAD-BD2F-451B-B31F-0398C5D4CFAE}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {F980FCAD-BD2F-451B-B31F-0398C5D4CFAE}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {F980FCAD-BD2F-451B-B31F-0398C5D4CFAE}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {226B227F-8980-4494-B6FA-33D406F9AC88} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /price_alert_v2/.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # Azure Functions localsettings file 5 | local.settings.json 6 | 7 | # User-specific files 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Build results 17 | [Dd]ebug/ 18 | [Dd]ebugPublic/ 19 | [Rr]elease/ 20 | [Rr]eleases/ 21 | x64/ 22 | x86/ 23 | bld/ 24 | [Bb]in/ 25 | [Oo]bj/ 26 | [Ll]og/ 27 | 28 | # Visual Studio 2015 cache/options directory 29 | .vs/ 30 | # Uncomment if you have tasks that create the project's static files in wwwroot 31 | #wwwroot/ 32 | 33 | # MSTest test Results 34 | [Tt]est[Rr]esult*/ 35 | [Bb]uild[Ll]og.* 36 | 37 | # NUNIT 38 | *.VisualState.xml 39 | TestResult.xml 40 | 41 | # Build Results of an ATL Project 42 | [Dd]ebugPS/ 43 | [Rr]eleasePS/ 44 | dlldata.c 45 | 46 | # DNX 47 | project.lock.json 48 | project.fragment.lock.json 49 | artifacts/ 50 | 51 | *_i.c 52 | *_p.c 53 | *_i.h 54 | *.ilk 55 | *.meta 56 | *.obj 57 | *.pch 58 | *.pdb 59 | *.pgc 60 | *.pgd 61 | *.rsp 62 | *.sbr 63 | *.tlb 64 | *.tli 65 | *.tlh 66 | *.tmp 67 | *.tmp_proj 68 | *.log 69 | *.vspscc 70 | *.vssscc 71 | .builds 72 | *.pidb 73 | *.svclog 74 | *.scc 75 | 76 | # Chutzpah Test files 77 | _Chutzpah* 78 | 79 | # Visual C++ cache files 80 | ipch/ 81 | *.aps 82 | *.ncb 83 | *.opendb 84 | *.opensdf 85 | *.sdf 86 | *.cachefile 87 | *.VC.db 88 | *.VC.VC.opendb 89 | 90 | # Visual Studio profiler 91 | *.psess 92 | *.vsp 93 | *.vspx 94 | *.sap 95 | 96 | # TFS 2012 Local Workspace 97 | $tf/ 98 | 99 | # Guidance Automation Toolkit 100 | *.gpState 101 | 102 | # ReSharper is a .NET coding add-in 103 | _ReSharper*/ 104 | *.[Rr]e[Ss]harper 105 | *.DotSettings.user 106 | 107 | # JustCode is a .NET coding add-in 108 | .JustCode 109 | 110 | # TeamCity is a build add-in 111 | _TeamCity* 112 | 113 | # DotCover is a Code Coverage Tool 114 | *.dotCover 115 | 116 | # NCrunch 117 | _NCrunch_* 118 | .*crunch*.local.xml 119 | nCrunchTemp_* 120 | 121 | # MightyMoose 122 | *.mm.* 123 | AutoTest.Net/ 124 | 125 | # Web workbench (sass) 126 | .sass-cache/ 127 | 128 | # Installshield output folder 129 | [Ee]xpress/ 130 | 131 | # DocProject is a documentation generator add-in 132 | DocProject/buildhelp/ 133 | DocProject/Help/*.HxT 134 | DocProject/Help/*.HxC 135 | DocProject/Help/*.hhc 136 | DocProject/Help/*.hhk 137 | DocProject/Help/*.hhp 138 | DocProject/Help/Html2 139 | DocProject/Help/html 140 | 141 | # Click-Once directory 142 | publish/ 143 | 144 | # Publish Web Output 145 | *.[Pp]ublish.xml 146 | *.azurePubxml 147 | # TODO: Comment the next line if you want to checkin your web deploy settings 148 | # but database connection strings (with potential passwords) will be unencrypted 149 | #*.pubxml 150 | *.publishproj 151 | 152 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 153 | # checkin your Azure Web App publish settings, but sensitive information contained 154 | # in these scripts will be unencrypted 155 | PublishScripts/ 156 | 157 | # NuGet Packages 158 | *.nupkg 159 | # The packages folder can be ignored because of Package Restore 160 | **/packages/* 161 | # except build/, which is used as an MSBuild target. 162 | !**/packages/build/ 163 | # Uncomment if necessary however generally it will be regenerated when needed 164 | #!**/packages/repositories.config 165 | # NuGet v3's project.json files produces more ignoreable files 166 | *.nuget.props 167 | *.nuget.targets 168 | 169 | # Microsoft Azure Build Output 170 | csx/ 171 | *.build.csdef 172 | 173 | # Microsoft Azure Emulator 174 | ecf/ 175 | rcf/ 176 | 177 | # Windows Store app package directories and files 178 | AppPackages/ 179 | BundleArtifacts/ 180 | Package.StoreAssociation.xml 181 | _pkginfo.txt 182 | 183 | # Visual Studio cache files 184 | # files ending in .cache can be ignored 185 | *.[Cc]ache 186 | # but keep track of directories ending in .cache 187 | !*.[Cc]ache/ 188 | 189 | # Others 190 | ClientBin/ 191 | ~$* 192 | *~ 193 | *.dbmdl 194 | *.dbproj.schemaview 195 | *.jfm 196 | *.pfx 197 | *.publishsettings 198 | node_modules/ 199 | orleans.codegen.cs 200 | 201 | # Since there are multiple workflows, uncomment next line to ignore bower_components 202 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 203 | #bower_components/ 204 | 205 | # RIA/Silverlight projects 206 | Generated_Code/ 207 | 208 | # Backup & report files from converting an old project file 209 | # to a newer Visual Studio version. Backup files are not needed, 210 | # because we have git ;-) 211 | _UpgradeReport_Files/ 212 | Backup*/ 213 | UpgradeLog*.XML 214 | UpgradeLog*.htm 215 | 216 | # SQL Server files 217 | *.mdf 218 | *.ldf 219 | 220 | # Business Intelligence projects 221 | *.rdl.data 222 | *.bim.layout 223 | *.bim_*.settings 224 | 225 | # Microsoft Fakes 226 | FakesAssemblies/ 227 | 228 | # GhostDoc plugin setting file 229 | *.GhostDoc.xml 230 | 231 | # Node.js Tools for Visual Studio 232 | .ntvs_analysis.dat 233 | 234 | # Visual Studio 6 build log 235 | *.plg 236 | 237 | # Visual Studio 6 workspace options file 238 | *.opt 239 | 240 | # Visual Studio LightSwitch build output 241 | **/*.HTMLClient/GeneratedArtifacts 242 | **/*.DesktopClient/GeneratedArtifacts 243 | **/*.DesktopClient/ModelManifest.xml 244 | **/*.Server/GeneratedArtifacts 245 | **/*.Server/ModelManifest.xml 246 | _Pvt_Extensions 247 | 248 | # Paket dependency manager 249 | .paket/paket.exe 250 | paket-files/ 251 | 252 | # FAKE - F# Make 253 | .fake/ 254 | 255 | # JetBrains Rider 256 | .idea/ 257 | *.sln.iml 258 | 259 | # CodeRush 260 | .cr/ 261 | 262 | # Python Tools for Visual Studio (PTVS) 263 | __pycache__/ 264 | *.pyc -------------------------------------------------------------------------------- /price_alert_v2/Functions/receive_command.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | using Microsoft.Azure.WebJobs; 3 | using Microsoft.Azure.WebJobs.Extensions.Http; 4 | using Microsoft.AspNetCore.Http; 5 | using Microsoft.Azure.WebJobs.Host; 6 | using Microsoft.WindowsAzure.Storage; // Namespace for CloudStorageAccount 7 | using Microsoft.WindowsAzure.Storage.Table; // Namespace for Table storage types 8 | using System.Threading.Tasks; 9 | using System; 10 | 11 | namespace price_alert_v2 12 | { 13 | public static class receive_command 14 | { 15 | private static Random rnd1 = new Random(); 16 | private static CloudStorageAccount storageAccount = CloudStorageAccount.Parse(Constants.StorageConnectionString); 17 | private static CloudTableClient tableClient = storageAccount.CreateCloudTableClient(); 18 | private static CloudTable table = tableClient.GetTableReference("alias"); 19 | 20 | [FunctionName("receive_command")] 21 | public static async Task Run([HttpTrigger(AuthorizationLevel.Function, "post")]HttpRequest req, 22 | TraceWriter log, 23 | [OrchestrationClient]DurableOrchestrationClient starter) 24 | { 25 | log.Info("Command triggered via HTTP."); 26 | 27 | var args = req.Form["body"].ToString().Split(' '); 28 | string fromPhone = req.Form["from"]; 29 | switch (args[0].ToLower()) 30 | { 31 | case "watch": 32 | await StartWatcher(starter, args, fromPhone); 33 | break; 34 | case "stop": 35 | await TerminateWatcherAsync(starter, args, fromPhone); 36 | break; 37 | default: 38 | return new BadRequestResult(); 39 | } 40 | return new OkResult(); 41 | } 42 | 43 | private static async Task TerminateWatcherAsync(DurableOrchestrationClient starter, string[] args, string fromPhone) 44 | { 45 | var result = await table.ExecuteAsync(TableOperation.Retrieve(fromPhone, args[1])); 46 | if(result.Result != null) 47 | { 48 | await starter.TerminateAsync(((Alias)result.Result).Id, "User requested terminate"); 49 | await TwilioSender.SendMessageAsync(fromPhone, $"Terminated instance {args[1]}"); 50 | } 51 | else 52 | { 53 | await TwilioSender.SendMessageAsync(fromPhone, $"No instance exists with id: {args[1]}"); 54 | } 55 | } 56 | 57 | private static async Task StartWatcher(DurableOrchestrationClient starter, string[] args, string fromPhone) 58 | { 59 | string market = await Bittrex.GetMarketName(args[1]); 60 | string instanceId = await starter.StartNewAsync("watcher", new WatcherRequest 61 | { 62 | market = market, 63 | threshold = double.Parse(args[2]), 64 | maxDuration = TimeSpan.FromMinutes(double.Parse(Constants.MaxDuration)), 65 | args = args, 66 | phone = fromPhone 67 | }); 68 | Alias alias = new Alias 69 | { 70 | PartitionKey = fromPhone, 71 | RowKey = rnd1.Next(1000).ToString(), 72 | Id = instanceId 73 | }; 74 | await table.ExecuteAsync(TableOperation.Insert(alias)); 75 | await TwilioSender.SendMessageAsync(fromPhone, $"Now watching {market} to pass {args[2]}. To cancel, text STOP {alias.RowKey}"); 76 | } 77 | 78 | public class Alias : TableEntity 79 | { 80 | public string Id { get; set; } 81 | } 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /price_alert_v2/Functions/watcher.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Net.Http; 4 | using System.Threading; 5 | using System.Threading.Tasks; 6 | using Microsoft.Azure.WebJobs; 7 | using Microsoft.Azure.WebJobs.Extensions.Http; 8 | using Microsoft.Azure.WebJobs.Host; 9 | using Newtonsoft.Json.Linq; 10 | 11 | namespace price_alert_v2 12 | { 13 | public static class watcher 14 | { 15 | [FunctionName("watcher")] 16 | public static async Task RunOrchestrator( 17 | [OrchestrationTrigger] DurableOrchestrationContext context, TraceWriter log) 18 | { 19 | log.Info("Starting watcher - getting initial ticker"); 20 | WatcherRequest input = context.GetInput(); 21 | double current = await context.CallActivityAsync("watcher_getticker", input.market); 22 | DateTime maxTime = context.CurrentUtcDateTime.Add(input.maxDuration); 23 | 24 | while (current < input.threshold && context.CurrentUtcDateTime < maxTime) { 25 | await context.CreateTimer(context.CurrentUtcDateTime.AddMinutes(double.Parse(Constants.DelayInterval)), CancellationToken.None); 26 | log.Info("Getting ticker"); 27 | current = await context.CallActivityAsync("watcher_getticker", input.market); 28 | log.Info("Current price " + current); 29 | } 30 | log.Info("Exited while loop"); 31 | if(current >= input.threshold) 32 | { 33 | await context.CallActivityAsync("send_event", new Message { 34 | phone = input.phone, 35 | text = input.market + " crossed at " + context.CurrentUtcDateTime.ToString() + " with price " + current 36 | }); 37 | } 38 | else 39 | { 40 | await context.CallActivityAsync("send_event", new Message { 41 | phone = input.phone, 42 | text = input.market + " timed out with price " + current 43 | }); 44 | } 45 | 46 | } 47 | 48 | [FunctionName("watcher_getticker")] 49 | public static async Task GetTicker([ActivityTrigger] string name, TraceWriter log) 50 | { 51 | var result = await (await Bittrex.httpClient.GetAsync(Constants.TickerUrl + "?market=" + name)).Content.ReadAsAsync(); 52 | return (double)result["result"]["Bid"]; 53 | } 54 | 55 | [FunctionName("send_event")] 56 | public static async Task SendMessage([ActivityTrigger] Message message, TraceWriter log) 57 | { 58 | await TwilioSender.SendMessageAsync(message.phone, message.text); 59 | } 60 | 61 | 62 | } 63 | } -------------------------------------------------------------------------------- /price_alert_v2/Models/Message.cs: -------------------------------------------------------------------------------- 1 | namespace price_alert_v2 2 | { 3 | public class Message 4 | { 5 | public string phone { get; set; } 6 | public string text { get; set; } 7 | } 8 | } -------------------------------------------------------------------------------- /price_alert_v2/Models/WatcherRequest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace price_alert_v2 4 | { 5 | public class WatcherRequest 6 | { 7 | public string market { get; set; } 8 | public double threshold { get; set; } 9 | public TimeSpan maxDuration { get; set; } 10 | public string[] args { get; set; } 11 | public string phone { get; set; } 12 | } 13 | } -------------------------------------------------------------------------------- /price_alert_v2/Tools/Bittrex.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Net.Http; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Mvc; 6 | using Newtonsoft.Json.Linq; 7 | 8 | namespace price_alert_v2 9 | { 10 | internal class Bittrex 11 | { 12 | internal static HttpClient httpClient = new HttpClient(); 13 | private static JArray markets; 14 | internal static async Task GetMarketName(string requestedCoin) 15 | { 16 | if (markets == null) 17 | { 18 | await CallMarkets(); 19 | } 20 | 21 | // Check to see if there is a ticker for USDT, if not will just do a BTC market 22 | var usdtMarket = markets 23 | .FirstOrDefault(m => string.Equals(((string)m["MarketName"]), "USDT-" + requestedCoin, StringComparison.OrdinalIgnoreCase)); 24 | 25 | string market = "BTC-" + requestedCoin.ToUpper(); 26 | if(usdtMarket != null) { 27 | market = (string)usdtMarket["MarketName"]; 28 | } 29 | 30 | return market; 31 | } 32 | 33 | private static async Task CallMarkets() 34 | { 35 | var result = await httpClient.GetAsync(Constants.GetMarketsUrl); 36 | markets = (JArray)(await result.Content.ReadAsAsync())["result"]; 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /price_alert_v2/Tools/Constants.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Twilio.Types; 3 | 4 | namespace price_alert_v2 5 | { 6 | internal class Constants 7 | { 8 | internal static string StorageConnectionString = Environment.GetEnvironmentVariable("AzureWebJobsStorage"); 9 | 10 | // Bittrex 11 | internal static string GetMarketsUrl = "https://bittrex.com/api/v1.1/public/getmarkets"; 12 | internal static string TickerUrl = "https://bittrex.com/api/v1.1/public/getticker"; 13 | 14 | // Twilio SMS 15 | internal static string Twilio_accountSid = Environment.GetEnvironmentVariable("Twilio_accountSid"); 16 | internal static string Twilio_authToken = Environment.GetEnvironmentVariable("Twilio_authToken"); 17 | internal static string Twilio_number = Environment.GetEnvironmentVariable("Twilio_number"); 18 | 19 | // Config 20 | public static string MaxDuration = Environment.GetEnvironmentVariable("Config_maxMinutes") ?? "240"; 21 | public static string DelayInterval = Environment.GetEnvironmentVariable("Config_delayMinutes") ?? "15"; 22 | } 23 | } -------------------------------------------------------------------------------- /price_alert_v2/Tools/TwilioSender.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading.Tasks; 3 | using Twilio; 4 | using Twilio.Rest.Api.V2010.Account; 5 | using Twilio.Types; 6 | 7 | namespace price_alert_v2 8 | { 9 | internal class TwilioSender 10 | { 11 | internal static async Task SendMessageAsync(string toPhone, string message) 12 | { 13 | TwilioClient.Init(Constants.Twilio_accountSid, Constants.Twilio_authToken); 14 | await MessageResource.CreateAsync( 15 | toPhone, 16 | from: new PhoneNumber(Constants.Twilio_number), 17 | body: message); 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /price_alert_v2/host.json: -------------------------------------------------------------------------------- 1 | { 2 | "logger": { 3 | "categoryFilter": { 4 | "categoryLevels": { 5 | "Host.Triggers.DurableTask": "Error" 6 | } 7 | } 8 | } 9 | } -------------------------------------------------------------------------------- /price_alert_v2/price_alert_v2.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | netstandard2.0 4 | v2 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | PreserveNewest 14 | 15 | 16 | PreserveNewest 17 | Never 18 | 19 | 20 | --------------------------------------------------------------------------------