-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathProgram.cs
More file actions
121 lines (111 loc) · 3.71 KB
/
Copy pathProgram.cs
File metadata and controls
121 lines (111 loc) · 3.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using CCXTSharp;
namespace Example
{
class Program
{
static async void Example1()
{
CcxtAPI ccxtAPI = new CcxtAPI(@"..\..\ccxt\ccxtAPI.exe"); // initialize and start process
List<string> exchangeIds = await ccxtAPI.GetExchangeIds(); // get list of avaliable exchanges
exchangeIds.ForEach(id => Console.WriteLine(id)); // print all exchange ids
await ccxtAPI.Close(); // it's preferred to exit other process if your program will close
}
static async void Example2()
{
// initialize and run script in python interpreter
CcxtAPI ccxtAPI = new CcxtAPI(@"..\..\ccxt\scripts\ccxtAPI.py", @"D:\Program Files (x86)\Python36-32\python.exe");
// gets list of markets on Binance exchange and prints their symbols
List<Market> markets = await ccxtAPI.FetchMarkets("binance");
markets.ForEach(m => Console.WriteLine(m.symbol));
await ccxtAPI.Close();
}
static async void Example3()
{
CcxtAPI ccxtAPI = new CcxtAPI(@"..\..\ccxt\ccxtAPI.exe");
// if cryptopia has support for fetch tickers then fetch them
if((await ccxtAPI.GetExchangeHas("binance")).fetchTickers == Has.Capability.True)
{
Dictionary<string, Ticker> tickers = await ccxtAPI.FetchTickers("binance");
// foreach ticker print their symbol and change
foreach (var ticker in tickers.Values)
{
Console.WriteLine(ticker.symbol + ": " + ticker.percentage);
}
}
await ccxtAPI.Close();
}
static async void Example4()
{
CcxtAPI ccxtAPI = new CcxtAPI(@"..\..\ccxt\ccxtAPI.exe");
// Authenticate
await ccxtAPI.ExchangeApiKey("binance", "my_api_key");
await ccxtAPI.ExchangeSecret("binance", "my_api_secret");
// Place order
Order order = await ccxtAPI.CreateOrder("binance", "ETH/USDT", OrderType.limit, OrderSide.buy, 1, 210);
// Cancel placed order
await ccxtAPI.CancelOrder("binance", order.id, "ETH/USDT");
await ccxtAPI.Close();
}
static async void Example5()
{
CcxtAPI ccxtAPI = new CcxtAPI(@"..\..\ccxt\ccxtAPI.exe");
try
{
Dictionary<string, Market> markets = await ccxtAPI.LoadMarkets("_1broker");
}
catch (CCXTException ex)
{
// exception is handled by ccxt python library
if (ex.HandledByCCXT)
Console.WriteLine(ex.exceptionType.Value.ToString() + ex.Message);
else
{
// there is a bug either in python ccxt or in CCXTSharp
Console.WriteLine(ex.Message);
// restart process
ccxtAPI.Kill(); // message will popup "Failed to execute script ccxtAPI.py"
// reinitialize and continue execution
ccxtAPI = new CcxtAPI(@"..\..\ccxt\ccxtAPI.exe");
}
}
// ...
await ccxtAPI.Close();
}
static async void Example6()
{
CcxtAPI ccxtAPI = new CcxtAPI(@"..\..\ccxt\ccxtAPI.exe");
List<Candlestick> candles = await ccxtAPI.FetchOHLCV("binance", "BTC/USDT", Timeframe.min1);
candles.ForEach(c => Console.WriteLine(c.close));
await ccxtAPI.Close();
}
static async void Test()
{
CcxtAPI ccxtAPI = new CcxtAPI(@"..\..\ccxt\ccxtAPI.exe");
ccxtAPI.ShowPipeData = true;
Console.WriteLine((await ccxtAPI.GetExchangeHas("yobit")).fetchTickers);
var tickers = await ccxtAPI.FetchTickers("yobit");
var list = from ticker in tickers.Values
orderby ticker.change
orderby ticker.quoteVolume
select ticker;
foreach (var e in list)
{
Console.WriteLine(e.symbol + ": " + e.change + " " + e.quoteVolume);
}
}
static void Main(string[] args)
{
Example6();
while (true)
{
Thread.Sleep(100);
}
}
}
}